Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gauge metric for number of self-hosted org runners #165

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Linter fixes
Signed-off-by: Peter Halasz <[email protected]>
  • Loading branch information
peterhalasz committed Feb 3, 2024
commit 1a6b437e8edf7ad4ecdca56188b2d980d2381b54
2 changes: 1 addition & 1 deletion internal/server/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"golang.org/x/oauth2"
)

var client *github.Client = nil
var client *github.Client

func getGithubClient(githubToken string) *github.Client {
if client != nil {
Expand Down
16 changes: 7 additions & 9 deletions internal/server/runner_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func NewRunnerMetricsExporter(logger log.Logger, opts Opts) *RunnerMetricsExport
}
}

func (e *RunnerMetricsExporter) StartOrgRunnerMetricsCollection(ctx context.Context) error {
func (e *RunnerMetricsExporter) StartOrgRunnerMetricsCollection(ctx context.Context) {
if e.Opts.GitHubOrg == "" {
level.Info(e.Logger).Log("msg", "Github org is not set, no org runner metrics will be collected.")
return nil
_ = level.Info(e.Logger).Log("msg", "Github org is not set, no org runner metrics will be collected.")
return
}
if e.Opts.GitHubAPIToken == "" {
level.Info(e.Logger).Log("msg", "Github token is not set, no org runner metrics will be collected.")
return nil
_ = level.Info(e.Logger).Log("msg", "Github token is not set, no org runner metrics will be collected.")
return
}

ticker := time.NewTicker(time.Duration(e.Opts.RunnersAPIPollSeconds) * time.Second)
Expand All @@ -43,20 +43,18 @@ func (e *RunnerMetricsExporter) StartOrgRunnerMetricsCollection(ctx context.Cont
e.collectOrgRunnerMetrics(ctx)
case <-ctx.Done():
ticker.Stop()
level.Info(e.Logger).Log("msg", "Stopped polling for org runner metrics.")
_ = level.Info(e.Logger).Log("msg", "Stopped polling for org runner metrics.")
return
}
}
}()

return nil
}

func (e *RunnerMetricsExporter) collectOrgRunnerMetrics(ctx context.Context) {
runners, _, err := e.GHClient.Actions.ListOrganizationRunners(ctx, e.Opts.GitHubOrg, nil)

if err != nil {
e.Logger.Log("msg", "Failed to retrieve org runners for org ", e.Opts.GitHubOrg, " ", err)
_ = e.Logger.Log("msg", "Failed to retrieve org runners for org ", e.Opts.GitHubOrg, " ", err)
}

numberOfSelfHostedRunners.WithLabelValues(e.Opts.GitHubOrg).Set(float64(runners.TotalCount))
Expand Down
Loading