这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@ Exposes basic metrics for your repositories from the GitHub API, to a Prometheus

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

| Variable | Description | Default |
|------------------------------|------------------------------------------------------------------------------------|--------------------------|
| `ORGS` | Comma-separated list of GitHub organizations to monitor (e.g. `org1,org2`). | |
| `REPOS` | Comma-separated list of repositories to monitor (e.g. `user/repo1,user/repo2`). | |
| `USERS` | Comma-separated list of GitHub users to monitor (e.g. `user1,user2`). | |
| `GITHUB_TOKEN` | GitHub personal access token for API authentication. | |
| `GITHUB_TOKEN_FILE` | Path to a file containing a GitHub personal access token. | |
| `GITHUB_APP` | Set to `true` to authenticate as a GitHub App. | `false` |
| `GITHUB_APP_ID` | The App ID of the GitHub App. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_APP_INSTALLATION_ID` | The Installation ID of the GitHub App. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_APP_KEY_PATH` | Path to the GitHub App private key file. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_RATE_LIMIT_ENABLED` | Whether to fetch GitHub API rate limit metrics (`true` or `false`). | `true` |
| `GITHUB_RESULTS_PER_PAGE` | Number of results to request per page from the GitHub API (max 100). | `100` |
| `API_URL` | GitHub API URL. You should not need to change this unless using GitHub Enterprise. | `https://api.github.com` |
| `LISTEN_PORT` | The port the exporter will listen on. | `9171` |
| `METRICS_PATH` | The HTTP path to expose Prometheus metrics. | `/metrics` |
| `LOG_LEVEL` | Logging level (`debug`, `info`, `warn`, `error`). | `info` |
| Variable | Description | Default |
|-------------------------------|------------------------------------------------------------------------------------|--------------------------|
| `ORGS` | Comma-separated list of GitHub organizations to monitor (e.g. `org1,org2`). | |
| `REPOS` | Comma-separated list of repositories to monitor (e.g. `user/repo1,user/repo2`). | |
| `USERS` | Comma-separated list of GitHub users to monitor (e.g. `user1,user2`). | |
| `GITHUB_TOKEN` | GitHub personal access token for API authentication. | |
| `GITHUB_TOKEN_FILE` | Path to a file containing a GitHub personal access token. | |
| `GITHUB_APP` | Set to `true` to authenticate as a GitHub App. | `false` |
| `GITHUB_APP_ID` | The App ID of the GitHub App. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_APP_INSTALLATION_ID` | The Installation ID of the GitHub App. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_APP_KEY_PATH` | Path to the GitHub App private key file. Required if `GITHUB_APP` is `true`. | |
| `GITHUB_RATE_LIMIT_ENABLED` | Whether to fetch GitHub API rate limit metrics (`true` or `false`). | `true` |
| `GITHUB_RESULTS_PER_PAGE` | Number of results to request per page from the GitHub API (max 100). | `100` |
| `FETCH_REPO_RELEASES_ENABLED` | Whether to fetch repository release metrics (`true` or `false`). | `true` |
| `FETCH_ORGS_CONCURRENCY` | Number of concurrent requests to make when fetching organization data. | `1` |
| `FETCH_ORG_REPOS_CONCURRENCY` | Number of concurrent requests to make when fetching organization repository data. | `1` |
| `FETCH_USERS_CONCURRENCY` | Number of concurrent requests to make when fetching user data. | `1` |
| `FETCH_USERS_CONCURRENCY` | Number of concurrent requests to make when fetching repository data. | `1` |
| `API_URL` | GitHub API URL. You should not need to change this unless using GitHub Enterprise. | `https://api.github.com` |
| `LISTEN_PORT` | The port the exporter will listen on. | `9171` |
| `METRICS_PATH` | The HTTP path to expose Prometheus metrics. | `/metrics` |
| `LOG_LEVEL` | Logging level (`debug`, `info`, `warn`, `error`). | `info` |

### Credential Precedence

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.0.2
v2.1.0
31 changes: 18 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@ import (

// Config struct holds runtime configuration required for the application
type Config struct {
MetricsPath string `envconfig:"METRICS_PATH" required:"false" default:"/metrics"`
ListenPort string `envconfig:"LISTEN_PORT" required:"false" default:"9171"`
LogLevel string `envconfig:"LOG_LEVEL" required:"false" default:"INFO"`
ApiUrl *url.URL `envconfig:"API_URL" required:"false" default:"https://api.github.com"`
Repositories []string `envconfig:"REPOS" required:"false"`
Organisations []string `envconfig:"ORGS" required:"false"`
Users []string `envconfig:"USERS" required:"false"`
GitHubResultsPerPage int `envconfig:"GITHUB_RESULTS_PER_PAGE" required:"false" default:"100"`
GithubToken string `envconfig:"GITHUB_TOKEN" required:"false"`
GithubTokenFile string `envconfig:"GITHUB_TOKEN_FILE" required:"false"`
GitHubApp bool `envconfig:"GITHUB_APP" required:"false" default:"false"`
GitHubRateLimitEnabled bool `envconfig:"GITHUB_RATE_LIMIT_ENABLED" required:"false" default:"true"`
*GitHubAppConfig `ignored:"true"`
MetricsPath string `envconfig:"METRICS_PATH" required:"false" default:"/metrics"`
ListenPort string `envconfig:"LISTEN_PORT" required:"false" default:"9171"`
LogLevel string `envconfig:"LOG_LEVEL" required:"false" default:"INFO"`
ApiUrl *url.URL `envconfig:"API_URL" required:"false" default:"https://api.github.com"`
Repositories []string `envconfig:"REPOS" required:"false"`
Organisations []string `envconfig:"ORGS" required:"false"`
Users []string `envconfig:"USERS" required:"false"`
GitHubResultsPerPage int `envconfig:"GITHUB_RESULTS_PER_PAGE" required:"false" default:"100"`
GithubToken string `envconfig:"GITHUB_TOKEN" required:"false"`
GithubTokenFile string `envconfig:"GITHUB_TOKEN_FILE" required:"false"`
GitHubApp bool `envconfig:"GITHUB_APP" required:"false" default:"false"`
GitHubRateLimitEnabled bool `envconfig:"GITHUB_RATE_LIMIT_ENABLED" required:"false" default:"true"`
FetchRepoReleasesEnabled bool `envconfig:"FETCH_REPO_RELEASES_ENABLED" required:"false" default:"true"`
FetchOrgsConcurrency int `envconfig:"FETCH_ORGS_CONCURRENCY" required:"false" default:"1"`
FetchOrgReposConcurrency int `envconfig:"FETCH_ORG_REPOS_CONCURRENCY" required:"false" default:"1"`
FetchReposConcurrency int `envconfig:"FETCH_REPOS_CONCURRENCY" required:"false" default:"1"`
FetchUsersConcurrency int `envconfig:"FETCH_USERS_CONCURRENCY" required:"false" default:"1"`
*GitHubAppConfig `ignored:"true"`
}

type GitHubAppConfig struct {
Expand Down
65 changes: 40 additions & 25 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,41 @@ func TestConfig(t *testing.T) {
Scheme: "https",
Host: "api.github.com",
},
Repositories: []string{},
Organisations: []string{},
Users: []string{},
GitHubResultsPerPage: 100,
GithubToken: "",
GithubTokenFile: "",
GitHubApp: false,
GitHubAppConfig: nil,
GitHubRateLimitEnabled: true,
Repositories: []string{},
Organisations: []string{},
Users: []string{},
GitHubResultsPerPage: 100,
GithubToken: "",
GithubTokenFile: "",
GitHubApp: false,
GitHubAppConfig: nil,
GitHubRateLimitEnabled: true,
FetchRepoReleasesEnabled: true,
FetchOrgsConcurrency: 1,
FetchOrgReposConcurrency: 1,
FetchReposConcurrency: 1,
FetchUsersConcurrency: 1,
},
expectedErr: nil,
},
{
name: "non-default config",
envVars: map[string]string{
"METRICS_PATH": "/otherendpoint",
"LISTEN_PORT": "1111",
"LOG_LEVEL": "DEBUG",
"API_URL": "https://example.com",
"REPOS": "repo1, repo2",
"ORGS": "org1,org2 ",
"USERS": " user1, user2 ",
"GITHUB_RESULTS_PER_PAGE": "50",
"GITHUB_TOKEN": "token",
"GITHUB_RATE_LIMIT_ENABLED": "false",
"METRICS_PATH": "/otherendpoint",
"LISTEN_PORT": "1111",
"LOG_LEVEL": "DEBUG",
"API_URL": "https://example.com",
"REPOS": "repo1, repo2",
"ORGS": "org1,org2 ",
"USERS": " user1, user2 ",
"GITHUB_RESULTS_PER_PAGE": "50",
"GITHUB_TOKEN": "token",
"GITHUB_RATE_LIMIT_ENABLED": "false",
"FETCH_REPO_RELEASES_ENABLED": "false",
"FETCH_ORGS_CONCURRENCY": "2",
"FETCH_ORG_REPOS_CONCURRENCY": "3",
"FETCH_REPOS_CONCURRENCY": "4",
"FETCH_USERS_CONCURRENCY": "5",
},
expectedCfg: &Config{
MetricsPath: "/otherendpoint",
Expand All @@ -71,12 +81,17 @@ func TestConfig(t *testing.T) {
"user1",
"user2",
},
GitHubResultsPerPage: 50,
GithubToken: "token",
GithubTokenFile: "",
GitHubApp: false,
GitHubAppConfig: nil,
GitHubRateLimitEnabled: false,
GitHubResultsPerPage: 50,
GithubToken: "token",
GithubTokenFile: "",
GitHubApp: false,
GitHubAppConfig: nil,
GitHubRateLimitEnabled: false,
FetchRepoReleasesEnabled: false,
FetchOrgsConcurrency: 2,
FetchOrgReposConcurrency: 3,
FetchReposConcurrency: 4,
FetchUsersConcurrency: 5,
},
expectedErr: nil,
},
Expand Down
Loading
Loading