Skip to content

Commit

Permalink
Merge branch 'main' into usmangt-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanbedi authored Oct 14, 2024
2 parents b78b0cd + 4f41bb9 commit 433d69b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 163 deletions.
137 changes: 0 additions & 137 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,145 +10,8 @@ For the plugin documentation, visit [plugin documentation website](https://grafa

This data source uses the [`githubv4` package](https://github.com/shurcooL/githubv4), which is under active development.

## Features

### Backend

- [x] Releases
- [x] Commits
- [x] Repositories
- [x] Stargazers
- [x] Issues
- [x] Organizations
- [x] Labels
- [x] Milestones
- [x] Response Caching
- [x] Projects
- [x] Workflows
- [ ] Deploys

### Frontend

- [x] Visualize queries
- [x] Template variables
- [x] Annotations

## Caching

Caching on this plugin is always enabled.

## Configuration

Options:

| Setting | Required |
| --------------------- | -------- |
| Access token | true |
| Default Organization | false |
| Default Repository | true |
| GitHub Enterprise URL | false |

To create a new Access Token, navigate to [Personal Access Tokens](https://github.com/settings/tokens) and press **Generate new token.**

### Provisioning

[It’s possible to configure data sources using config files with Grafana’s provisioning system](https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources).

#### With the [prom-operator](https://github.com/prometheus-operator/prometheus-operator)

```yaml
promop:
grafana:
additionalDataSources:
- name: GitHub Repo Insights
type: grafana-github-datasource
jsonData:
owner: ''
repository: ''
secureJsonData:
accessToken: '<github api token>'
```
## Annotations
Annotations overlay events on a graph.
![Annotations on a graph](https://github.com/grafana/github-datasource/raw/main/docs/screenshots/annotations.png)
With annotations, you can display:
- Commits
- Issues
- Pull Requests
- Releases
- Tags
on a graph.
All annotations require that you select a field to display on the annotation, and a field that represents the time that the event occurred.
![Annotations editor](https://github.com/grafana/github-datasource/raw/main/docs/screenshots/annotations-editor.png)
## Variables
[Variables](https://grafana.com/docs/grafana/latest/variables/) allow you to substitute values in a panel with pre-defined values.
![Creating Variables](https://github.com/grafana/github-datasource/raw/main/docs/screenshots/variables-create.png)
You can reference them inside queries, allowing users to configure parameters such as `Query` or `Repository`.

![Using Variables inside queries](https://github.com/grafana/github-datasource/raw/main/docs/screenshots/using-variables.png)

## Macros

You can use the following macros in your queries

| Macro Name | Syntax | Description | Example |
| ---------- | -------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ |
| multiVar | `$__multiVar(prefix,$var)` | Expands a multi value variable into github query string | `$__multiVar(label,$labels)` will expand into `label:first-label label:second-label` |
| | | When using **all** in multi variable, use **\*** as custom all value | |
| day | `$__toDay(diff)` | Returns the day according to UTC time, a difference in days can be added | `created:$__toDay(-7)` on 2022-01-17 will expand into `created:2022-01-10` |

## Access Token Permissions

For all repositories:

- `public_repo`
- `repo:status`
- `repo_deployment`
- `read:packages`
- `read:user`
- `user:email`

For Github projects:

- `read:org`
- `read:project`

An extra setting is required for private repositories

- `repo (Full control of private repositories)`

## Sample Dashboard

For documentation on importing dashboards, check out the documentation on [grafana.com](https://grafana.com/docs/grafana/latest/reference/export_import/#importing-a-dashboard)

The sample dashboard can be obtained from either of two places.

1. From the Grafana dashboards page [located here](https://grafana.com/grafana/dashboards/14000)

2. From this repository

If loading it from this repository, open Grafana and click "Import Dashboard".

Copy the JSON in `./src/dashboards/dashboard.json`, and paste it into the "Import via panel json" box.

## Frequently Asked Questions

- **I am using GitHub OAuth on Grafana. Can my users make requests with their individual GitHub accounts instead of a shared `access_token`?**

No. This requires changes in Grafana first. See [this issue](https://github.com/grafana/grafana/issues/26023) in the Grafana project.

- **Why does it sometimes take up to 5 minutes for my new pull request / new issue / new commit to show up?**

We have aggressive caching enabled due to GitHub's rate limiting policies. When selecting a time range like "Last hour", a combination of the queries for each panel and the time range is cached temporarily.
Expand Down
30 changes: 18 additions & 12 deletions docs/sources/setup/provisioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@ You can define and configure the GitHub data source in YAML files with Grafana p

**Example**

The following YAML snippet can be used to provision the GitHub data source for Grafana if you are using [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator):

```yaml
promop:
grafana:
additionalDataSources:
- name: GitHub Repo Insights
type: grafana-github-datasource
jsonData:
owner: ’<REPOSITORY_OWNER>’
repository: ’<REPOSITORY_NAME>’
secureJsonData:
accessToken: ’<PERSONAL_ACCESS_TOKEN>’
apiVersion: 1

datasources:
- name: GitHub (Personal Access Token)
type: grafana-github-datasource
jsonData:
selectedAuthType: personal-access-token
secureJsonData:
accessToken: <your_access_token>

- name: GitHub (App)
type: grafana-github-datasource
jsonData:
selectedAuthType: github-app
appId: <your_app_id>
installationId: <your_installation_id>
secureJsonData:
privateKey: <your_private_key>
```
18 changes: 4 additions & 14 deletions docs/sources/setup/token.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,10 @@ You will need to define the access permissions for your **personal access token*

The following lists include the required permissions for the access token:

For all repositories:
`public_repo`, `repo:status`, `repo_deployment`, `read:packages`, `read:user`, `user:email`, `read:org`, `read:project`, `repo (For full control of private repositories)`

- `public_repo`
- `repo:status`
- `repo_deployment`
- `read:packages`
- `read:user`
- `user:email`
You will need to define the access permissions for your **GitHub App** in order to allow it to access the data.

For GitHub projects:
**Repositories:**

- `read:org`
- `read:project`

An extra setting is required for private repositories:

- `repo (Full control of private repositories)`
`metadata: read-only`, `contents: read-only`, `issues: read-only`, `pull requests: read-only`, `packages: read-only`, `repository security advisories: read-only`, `projects: read-only`

0 comments on commit 433d69b

Please sign in to comment.