Skip to content

Commit 2abdb35

Browse files
feat: Various performance improvements (#128)
* feat: Make request concurrency configurable * version 2.1.0
1 parent b03ae31 commit 2abdb35

File tree

8 files changed

+195
-118
lines changed

8 files changed

+195
-118
lines changed

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@ Exposes basic metrics for your repositories from the GitHub API, to a Prometheus
66

77
This exporter is configured via environment variables. All variables are optional unless otherwise stated. Below is a list of supported configuration values:
88

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` |
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+
| `FETCH_REPO_RELEASES_ENABLED` | Whether to fetch repository release metrics (`true` or `false`). | `true` |
23+
| `FETCH_ORGS_CONCURRENCY` | Number of concurrent requests to make when fetching organization data. | `1` |
24+
| `FETCH_ORG_REPOS_CONCURRENCY` | Number of concurrent requests to make when fetching organization repository data. | `1` |
25+
| `FETCH_USERS_CONCURRENCY` | Number of concurrent requests to make when fetching user data. | `1` |
26+
| `FETCH_USERS_CONCURRENCY` | Number of concurrent requests to make when fetching repository data. | `1` |
27+
| `API_URL` | GitHub API URL. You should not need to change this unless using GitHub Enterprise. | `https://api.github.com` |
28+
| `LISTEN_PORT` | The port the exporter will listen on. | `9171` |
29+
| `METRICS_PATH` | The HTTP path to expose Prometheus metrics. | `/metrics` |
30+
| `LOG_LEVEL` | Logging level (`debug`, `info`, `warn`, `error`). | `info` |
2631

2732
### Credential Precedence
2833

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.0.2
1+
v2.1.0

config/config.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,24 @@ import (
1616

1717
// Config struct holds runtime configuration required for the application
1818
type Config struct {
19-
MetricsPath string `envconfig:"METRICS_PATH" required:"false" default:"/metrics"`
20-
ListenPort string `envconfig:"LISTEN_PORT" required:"false" default:"9171"`
21-
LogLevel string `envconfig:"LOG_LEVEL" required:"false" default:"INFO"`
22-
ApiUrl *url.URL `envconfig:"API_URL" required:"false" default:"https://api.github.com"`
23-
Repositories []string `envconfig:"REPOS" required:"false"`
24-
Organisations []string `envconfig:"ORGS" required:"false"`
25-
Users []string `envconfig:"USERS" required:"false"`
26-
GitHubResultsPerPage int `envconfig:"GITHUB_RESULTS_PER_PAGE" required:"false" default:"100"`
27-
GithubToken string `envconfig:"GITHUB_TOKEN" required:"false"`
28-
GithubTokenFile string `envconfig:"GITHUB_TOKEN_FILE" required:"false"`
29-
GitHubApp bool `envconfig:"GITHUB_APP" required:"false" default:"false"`
30-
GitHubRateLimitEnabled bool `envconfig:"GITHUB_RATE_LIMIT_ENABLED" required:"false" default:"true"`
31-
*GitHubAppConfig `ignored:"true"`
19+
MetricsPath string `envconfig:"METRICS_PATH" required:"false" default:"/metrics"`
20+
ListenPort string `envconfig:"LISTEN_PORT" required:"false" default:"9171"`
21+
LogLevel string `envconfig:"LOG_LEVEL" required:"false" default:"INFO"`
22+
ApiUrl *url.URL `envconfig:"API_URL" required:"false" default:"https://api.github.com"`
23+
Repositories []string `envconfig:"REPOS" required:"false"`
24+
Organisations []string `envconfig:"ORGS" required:"false"`
25+
Users []string `envconfig:"USERS" required:"false"`
26+
GitHubResultsPerPage int `envconfig:"GITHUB_RESULTS_PER_PAGE" required:"false" default:"100"`
27+
GithubToken string `envconfig:"GITHUB_TOKEN" required:"false"`
28+
GithubTokenFile string `envconfig:"GITHUB_TOKEN_FILE" required:"false"`
29+
GitHubApp bool `envconfig:"GITHUB_APP" required:"false" default:"false"`
30+
GitHubRateLimitEnabled bool `envconfig:"GITHUB_RATE_LIMIT_ENABLED" required:"false" default:"true"`
31+
FetchRepoReleasesEnabled bool `envconfig:"FETCH_REPO_RELEASES_ENABLED" required:"false" default:"true"`
32+
FetchOrgsConcurrency int `envconfig:"FETCH_ORGS_CONCURRENCY" required:"false" default:"1"`
33+
FetchOrgReposConcurrency int `envconfig:"FETCH_ORG_REPOS_CONCURRENCY" required:"false" default:"1"`
34+
FetchReposConcurrency int `envconfig:"FETCH_REPOS_CONCURRENCY" required:"false" default:"1"`
35+
FetchUsersConcurrency int `envconfig:"FETCH_USERS_CONCURRENCY" required:"false" default:"1"`
36+
*GitHubAppConfig `ignored:"true"`
3237
}
3338

3439
type GitHubAppConfig struct {

config/config_test.go

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,41 @@ func TestConfig(t *testing.T) {
2525
Scheme: "https",
2626
Host: "api.github.com",
2727
},
28-
Repositories: []string{},
29-
Organisations: []string{},
30-
Users: []string{},
31-
GitHubResultsPerPage: 100,
32-
GithubToken: "",
33-
GithubTokenFile: "",
34-
GitHubApp: false,
35-
GitHubAppConfig: nil,
36-
GitHubRateLimitEnabled: true,
28+
Repositories: []string{},
29+
Organisations: []string{},
30+
Users: []string{},
31+
GitHubResultsPerPage: 100,
32+
GithubToken: "",
33+
GithubTokenFile: "",
34+
GitHubApp: false,
35+
GitHubAppConfig: nil,
36+
GitHubRateLimitEnabled: true,
37+
FetchRepoReleasesEnabled: true,
38+
FetchOrgsConcurrency: 1,
39+
FetchOrgReposConcurrency: 1,
40+
FetchReposConcurrency: 1,
41+
FetchUsersConcurrency: 1,
3742
},
3843
expectedErr: nil,
3944
},
4045
{
4146
name: "non-default config",
4247
envVars: map[string]string{
43-
"METRICS_PATH": "/otherendpoint",
44-
"LISTEN_PORT": "1111",
45-
"LOG_LEVEL": "DEBUG",
46-
"API_URL": "https://example.com",
47-
"REPOS": "repo1, repo2",
48-
"ORGS": "org1,org2 ",
49-
"USERS": " user1, user2 ",
50-
"GITHUB_RESULTS_PER_PAGE": "50",
51-
"GITHUB_TOKEN": "token",
52-
"GITHUB_RATE_LIMIT_ENABLED": "false",
48+
"METRICS_PATH": "/otherendpoint",
49+
"LISTEN_PORT": "1111",
50+
"LOG_LEVEL": "DEBUG",
51+
"API_URL": "https://example.com",
52+
"REPOS": "repo1, repo2",
53+
"ORGS": "org1,org2 ",
54+
"USERS": " user1, user2 ",
55+
"GITHUB_RESULTS_PER_PAGE": "50",
56+
"GITHUB_TOKEN": "token",
57+
"GITHUB_RATE_LIMIT_ENABLED": "false",
58+
"FETCH_REPO_RELEASES_ENABLED": "false",
59+
"FETCH_ORGS_CONCURRENCY": "2",
60+
"FETCH_ORG_REPOS_CONCURRENCY": "3",
61+
"FETCH_REPOS_CONCURRENCY": "4",
62+
"FETCH_USERS_CONCURRENCY": "5",
5363
},
5464
expectedCfg: &Config{
5565
MetricsPath: "/otherendpoint",
@@ -71,12 +81,17 @@ func TestConfig(t *testing.T) {
7181
"user1",
7282
"user2",
7383
},
74-
GitHubResultsPerPage: 50,
75-
GithubToken: "token",
76-
GithubTokenFile: "",
77-
GitHubApp: false,
78-
GitHubAppConfig: nil,
79-
GitHubRateLimitEnabled: false,
84+
GitHubResultsPerPage: 50,
85+
GithubToken: "token",
86+
GithubTokenFile: "",
87+
GitHubApp: false,
88+
GitHubAppConfig: nil,
89+
GitHubRateLimitEnabled: false,
90+
FetchRepoReleasesEnabled: false,
91+
FetchOrgsConcurrency: 2,
92+
FetchOrgReposConcurrency: 3,
93+
FetchReposConcurrency: 4,
94+
FetchUsersConcurrency: 5,
8095
},
8196
expectedErr: nil,
8297
},

0 commit comments

Comments
 (0)