Skip to content

Commit d68cc3b

Browse files
committed
fix: add missing metrics for few gh api callS
Signed-off-by: Mario Constanti <mario.constanti@mercedes-benz.com>
1 parent 6cb6350 commit d68cc3b

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

metrics/metrics.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const metricsGithubSubsystem = "github"
1616

1717
// RegisterMetrics registers all the metrics
1818
func RegisterMetrics() error {
19-
2019
var collectors []prometheus.Collector
2120
collectors = append(collectors,
2221

runner/pool/enterprise.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,19 @@ func (r *enterprise) FetchDbInstances() ([]params.Instance, error) {
306306
}
307307

308308
func (r *enterprise) RemoveGithubRunner(runnerID int64) (*github.Response, error) {
309-
return r.ghcEnterpriseCli.RemoveRunner(r.ctx, r.cfg.Name, runnerID)
309+
metrics.GithubOperationCount.WithLabelValues(
310+
"RemoveRunner", // label: operation
311+
metricsLabelEnterpriseScope, // label: scope
312+
).Inc()
313+
ghResp, err := r.ghcEnterpriseCli.RemoveRunner(r.ctx, r.cfg.Name, runnerID)
314+
if err != nil {
315+
metrics.GithubOperationFailedCount.WithLabelValues(
316+
"RemoveRunner", // label: operation
317+
metricsLabelEnterpriseScope, // label: scope
318+
).Inc()
319+
return nil, err
320+
}
321+
return ghResp, nil
310322
}
311323

312324
func (r *enterprise) ListPools() ([]params.Pool, error) {

runner/pool/organization.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,17 @@ func (r *organization) JwtToken() string {
352352
}
353353

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

357361
if err != nil {
362+
metrics.GithubOperationFailedCount.WithLabelValues(
363+
"CreateOrganizationRegistrationToken", // label: operation
364+
metricsLabelOrganizationScope, // label: scope
365+
).Inc()
358366
if ghResp != nil && ghResp.StatusCode == http.StatusUnauthorized {
359367
return "", errors.Wrap(runnerErrors.ErrUnauthorized, "fetching token")
360368
}

runner/pool/repository.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,16 @@ func (r *repository) GetJITConfig(ctx context.Context, instance string, pool par
100100
// TODO(gabriel-samfira): Should we make this configurable?
101101
WorkFolder: github.String("_work"),
102102
}
103+
metrics.GithubOperationCount.WithLabelValues(
104+
"GenerateRepoJITConfig", // label: operation
105+
metricsLabelRepositoryScope, // label: scope
106+
).Inc()
103107
jitConfig, resp, err := r.ghcli.GenerateRepoJITConfig(ctx, r.cfg.Owner, r.cfg.Name, &req)
104108
if err != nil {
109+
metrics.GithubOperationFailedCount.WithLabelValues(
110+
"GenerateRepoJITConfig", // label: operation
111+
metricsLabelRepositoryScope, // label: scope
112+
).Inc()
105113
if resp != nil && resp.StatusCode == http.StatusUnauthorized {
106114
return nil, nil, fmt.Errorf("failed to get JIT config: %w", err)
107115
}
@@ -395,8 +403,17 @@ func (r *repository) InstallHook(ctx context.Context, req *github.Hook) (params.
395403
return params.HookInfo{}, errors.Wrap(err, "validating hook request")
396404
}
397405

406+
metrics.GithubOperationCount.WithLabelValues(
407+
"CreateRepoHook", // label: operation
408+
metricsLabelRepositoryScope, // label: scope
409+
).Inc()
410+
398411
hook, _, err := r.ghcli.CreateRepoHook(ctx, r.cfg.Owner, r.cfg.Name, req)
399412
if err != nil {
413+
metrics.GithubOperationFailedCount.WithLabelValues(
414+
"CreateRepoHook", // label: operation
415+
metricsLabelRepositoryScope, // label: scope
416+
).Inc()
400417
return params.HookInfo{}, errors.Wrap(err, "creating repository hook")
401418
}
402419

0 commit comments

Comments
 (0)