Skip to content

Commit ce81cac

Browse files
Version 2 (#123)
* [v2] Simplify init and config * [v2] Use github client library instead of direct API requests * [v2] Upgrade golang to 1.25.2 * [v2] Remove unused code * [v2] Update go dependencies * [v2] Add option to disable github rate limit metric collection * [v2] Fix app auth * [v2] Add extra rate limit types * [v2] Fix app rate limit handling * [v2] Improve README * [v2] Pagination support * [v2] Support multiple architectures in Dockerfile * [v2] Update version tag * [v2] Add arm64 to docker platform list
1 parent f8151de commit ce81cac

File tree

18 files changed

+628
-761
lines changed

18 files changed

+628
-761
lines changed

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
ARG GOLANG_VERSION=1.22.7
2-
FROM golang:${GOLANG_VERSION} AS build
1+
ARG GOLANG_VERSION=1.25.3
2+
FROM --platform=$BUILDPLATFORM golang:${GOLANG_VERSION} AS build
33
LABEL maintainer="githubexporter"
44

5-
ENV GO111MODULE=on
5+
ARG TARGETOS
6+
ARG TARGETARCH
67

78
COPY ./ /go/src/github.com/githubexporter/github-exporter
89
WORKDIR /go/src/github.com/githubexporter/github-exporter
910

1011
RUN go mod download \
1112
&& go test ./... \
12-
&& CGO_ENABLED=0 GOOS=linux go build -o /bin/main
13+
&& CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /bin/main
1314

1415
FROM gcr.io/distroless/static AS runtime
1516

1617
ADD VERSION .
1718
COPY --from=build /bin/main /bin/main
1819
ENV LISTEN_PORT=9171
19-
EXPOSE 9171
20+
EXPOSE $LISTEN_PORT
2021
ENTRYPOINT [ "/bin/main" ]

METRICS.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,51 @@ Below are an example of the metrics as exposed by this exporter.
55
```
66
# HELP github_rate_limit Number of API queries allowed in a 60 minute window
77
# TYPE github_rate_limit gauge
8-
github_rate_limit 5000
8+
github_rate_limit{resource="code_search"} 60
9+
github_rate_limit{resource="core"} 60
10+
github_rate_limit{resource="graphql"} 0
11+
github_rate_limit{resource="integration_manifest"} 5000
12+
github_rate_limit{resource="search"} 10
913
# HELP github_rate_remaining Number of API queries remaining in the current window
1014
# TYPE github_rate_remaining gauge
11-
github_rate_remaining 2801
15+
github_rate_remaining{resource="code_search"} 56
16+
github_rate_remaining{resource="core"} 56
17+
github_rate_remaining{resource="graphql"} 0
18+
github_rate_remaining{resource="integration_manifest"} 5000
19+
github_rate_remaining{resource="search"} 10
1220
# HELP github_rate_reset The time at which the current rate limit window resets in UTC epoch seconds
1321
# TYPE github_rate_reset gauge
14-
github_rate_reset 1.527709029e+09
22+
github_rate_reset{resource="code_search"} 1.760954346e+09
23+
github_rate_reset{resource="core"} 1.760954346e+09
24+
github_rate_reset{resource="graphql"} 1.760954347e+09
25+
github_rate_reset{resource="integration_manifest"} 1.760954347e+09
26+
github_rate_reset{resource="search"} 1.760950807e+09
1527
# HELP github_repo_forks Total number of forks for given repository
1628
# TYPE github_repo_forks gauge
17-
github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 19
29+
github_repo_forks{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 129
1830
# HELP github_repo_open_issues Total number of open issues for given repository
1931
# TYPE github_repo_open_issues gauge
20-
github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 7
32+
github_repo_open_issues{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 28
33+
# HELP github_repo_pull_request_count Total number of pull requests for given repository
34+
# TYPE github_repo_pull_request_count gauge
35+
github_repo_pull_request_count{repo="github-exporter",user="githubexporter"} 7
2136
# HELP github_repo_size_kb Size in KB for given repository
2237
# TYPE github_repo_size_kb gauge
23-
github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 41
38+
github_repo_size_kb{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 2185
2439
# HELP github_repo_stars Total number of Stars for given repository
2540
# TYPE github_repo_stars gauge
26-
github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 64
41+
github_repo_stars{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 441
2742
# HELP github_repo_watchers Total number of watchers/subscribers for given repository
2843
# TYPE github_repo_watchers gauge
29-
github_repo_watchers{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="infinityworks"} 10
30-
# TYPE github_repo_release_downloads gauge
31-
github_repo_release_downloads{name="release1.0.0",repo="github-exporter",user="infinityworks"} 3500
44+
github_repo_watchers{archived="false",fork="false",language="Go",license="mit",private="false",repo="github-exporter",user="githubexporter"} 10```
3245
```
3346

3447
<!--
35-
3648
The above output was generated by running:
3749
3850
```
3951
REPOS=infinityworks/github-exporter go run main.go
4052
```
4153
4254
And copying the output of http://localhost:9171/metrics
43-
44-
-->
55+
-->

README.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,35 @@ Exposes basic metrics for your repositories from the GitHub API, to a Prometheus
44

55
## Configuration
66

7-
This exporter is setup to take input from environment variables. All variables are optional:
8-
9-
* `ORGS` If supplied, the exporter will enumerate all repositories for that organization. Expected in the format "org1, org2".
10-
* `REPOS` If supplied, The repos you wish to monitor, expected in the format "user/repo1, user/repo2". Can be across different Github users/orgs.
11-
* `USERS` If supplied, the exporter will enumerate all repositories for that users. Expected in
12-
the format "user1, user2".
13-
* `GITHUB_TOKEN` If supplied, enables the user to supply a github authentication token that allows the API to be queried more often. Optional, but recommended.
14-
* `GITHUB_TOKEN_FILE` If supplied _instead of_ `GITHUB_TOKEN`, enables the user to supply a path to a file containing a github authentication token that allows the API to be queried more often. Optional, but recommended.
15-
* `GITHUB_APP` If true , authenticates ass GitHub app to the API.
16-
* `GITHUB_APP_ID` The APP ID of the GitHub App.
17-
* `GITHUB_APP_INSTALLATION_ID` The INSTALLATION ID of the GitHub App.
18-
* `GITHUB_APP_KEY_PATH` The path to the github private key.
19-
* `GITHUB_RATE_LIMIT` The RATE LIMIT that suppose to be for github app (default is 15,000). If the exporter sees the value is below this variable it generating new token for the app.
20-
* `API_URL` Github API URL, shouldn't need to change this. Defaults to `https://api.github.com`
21-
* `LISTEN_PORT` The port you wish to run the container on, the Dockerfile defaults this to `9171`
22-
* `METRICS_PATH` the metrics URL path you wish to use, defaults to `/metrics`
23-
* `LOG_LEVEL` The level of logging the exporter will run with, defaults to `debug`
24-
7+
This exporter is configured via environment variables. All variables are optional unless otherwise stated. Below is a list of supported configuration values:
8+
9+
| Variable | Description | Default |
10+
|------------------------------|------------------------------------------------------------------------------------|--------------------------|
11+
| `ORGS` | Comma-separated list of GitHub organizations to monitor (e.g. `org1,org2`). | |
12+
| `REPOS` | Comma-separated list of repositories to monitor (e.g. `user/repo1,user/repo2`). | |
13+
| `USERS` | Comma-separated list of GitHub users to monitor (e.g. `user1,user2`). | |
14+
| `GITHUB_TOKEN` | GitHub personal access token for API authentication. | |
15+
| `GITHUB_TOKEN_FILE` | Path to a file containing a GitHub personal access token. | |
16+
| `GITHUB_APP` | Set to `true` to authenticate as a GitHub App. | `false` |
17+
| `GITHUB_APP_ID` | The App ID of the GitHub App. Required if `GITHUB_APP` is `true`. | |
18+
| `GITHUB_APP_INSTALLATION_ID` | The Installation ID of the GitHub App. Required if `GITHUB_APP` is `true`. | |
19+
| `GITHUB_APP_KEY_PATH` | Path to the GitHub App private key file. Required if `GITHUB_APP` is `true`. | |
20+
| `GITHUB_RATE_LIMIT_ENABLED` | Whether to fetch GitHub API rate limit metrics (`true` or `false`). | `true` |
21+
| `GITHUB_RESULTS_PER_PAGE` | Number of results to request per page from the GitHub API (max 100). | `100` |
22+
| `API_URL` | GitHub API URL. You should not need to change this unless using GitHub Enterprise. | `https://api.github.com` |
23+
| `LISTEN_PORT` | The port the exporter will listen on. | `9171` |
24+
| `METRICS_PATH` | The HTTP path to expose Prometheus metrics. | `/metrics` |
25+
| `LOG_LEVEL` | Logging level (`debug`, `info`, `warn`, `error`). | `info` |
26+
27+
### Credential Precedence
28+
29+
When authenticating with the GitHub API, the exporter uses credentials in the following order of precedence:
30+
31+
1. **GitHub App credentials** (`GITHUB_APP=true` with `GITHUB_APP_ID`, `GITHUB_APP_INSTALLATION_ID`, and `GITHUB_APP_KEY_PATH`): If enabled, the exporter authenticates as a GitHub App and ignores any personal access token or token file.
32+
2. **Token file** (`GITHUB_TOKEN_FILE`): If a token file is provided (and GitHub App is not enabled), the exporter reads the token from the specified file.
33+
3. **Direct token** (`GITHUB_TOKEN`): If neither GitHub App nor token file is provided, the exporter uses the token supplied directly via the environment variable.
34+
35+
If none of these credentials are provided, the exporter will make unauthenticated requests, which are subject to very strict rate limits.
2536

2637
## Install and deploy
2738

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.1
1+
2.0.0

0 commit comments

Comments
 (0)