Skip to content

Commit

Permalink
fix: add missing metrics for few gh api callS
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Constanti <mario.constanti@mercedes-benz.com>
  • Loading branch information
bavarianbidi committed Feb 22, 2024
1 parent 6cb6350 commit 377839d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
14 changes: 13 additions & 1 deletion runner/pool/enterprise.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,19 @@ func (r *enterprise) FetchDbInstances() ([]params.Instance, error) {
}

func (r *enterprise) RemoveGithubRunner(runnerID int64) (*github.Response, error) {
return r.ghcEnterpriseCli.RemoveRunner(r.ctx, r.cfg.Name, runnerID)
metrics.GithubOperationCount.WithLabelValues(
"RemoveRunner", // label: operation
metricsLabelEnterpriseScope, // label: scope
).Inc()
ghResp, err := r.ghcEnterpriseCli.RemoveRunner(r.ctx, r.cfg.Name, runnerID)
if err != nil {
metrics.GithubOperationFailedCount.WithLabelValues(
"RemoveRunner", // label: operation
metricsLabelEnterpriseScope, // label: scope
).Inc()
return nil, err
}
return ghResp, nil
}

func (r *enterprise) ListPools() ([]params.Pool, error) {
Expand Down
8 changes: 8 additions & 0 deletions runner/pool/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,17 @@ func (r *organization) JwtToken() string {
}

func (r *organization) GetGithubRegistrationToken() (string, error) {
metrics.GithubOperationCount.WithLabelValues(
"CreateOrganizationRegistrationToken", // label: operation
metricsLabelOrganizationScope, // label: scope
).Inc()
tk, ghResp, err := r.ghcli.CreateOrganizationRegistrationToken(r.ctx, r.cfg.Name)

if err != nil {
metrics.GithubOperationFailedCount.WithLabelValues(
"CreateOrganizationRegistrationToken", // label: operation
metricsLabelOrganizationScope, // label: scope
).Inc()
if ghResp != nil && ghResp.StatusCode == http.StatusUnauthorized {
return "", errors.Wrap(runnerErrors.ErrUnauthorized, "fetching token")
}
Expand Down
17 changes: 17 additions & 0 deletions runner/pool/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ func (r *repository) GetJITConfig(ctx context.Context, instance string, pool par
// TODO(gabriel-samfira): Should we make this configurable?
WorkFolder: github.String("_work"),
}
metrics.GithubOperationCount.WithLabelValues(
"GenerateRepoJITConfig", // label: operation
metricsLabelRepositoryScope, // label: scope
).Inc()
jitConfig, resp, err := r.ghcli.GenerateRepoJITConfig(ctx, r.cfg.Owner, r.cfg.Name, &req)
if err != nil {
metrics.GithubOperationFailedCount.WithLabelValues(
"GenerateRepoJITConfig", // label: operation
metricsLabelRepositoryScope, // label: scope
).Inc()
if resp != nil && resp.StatusCode == http.StatusUnauthorized {
return nil, nil, fmt.Errorf("failed to get JIT config: %w", err)
}
Expand Down Expand Up @@ -395,8 +403,17 @@ func (r *repository) InstallHook(ctx context.Context, req *github.Hook) (params.
return params.HookInfo{}, errors.Wrap(err, "validating hook request")
}

metrics.GithubOperationCount.WithLabelValues(
"CreateRepoHook", // label: operation
metricsLabelRepositoryScope, // label: scope
).Inc()

hook, _, err := r.ghcli.CreateRepoHook(ctx, r.cfg.Owner, r.cfg.Name, req)
if err != nil {
metrics.GithubOperationFailedCount.WithLabelValues(
"CreateRepoHook", // label: operation
metricsLabelRepositoryScope, // label: scope
).Inc()
return params.HookInfo{}, errors.Wrap(err, "creating repository hook")
}

Expand Down

0 comments on commit 377839d

Please sign in to comment.