Skip to content

Commit

Permalink
add webservice label to metrics (#49)
Browse files Browse the repository at this point in the history
* add webservice label to metrics

* remove webservice label from request latency
  • Loading branch information
ZeynabRezaei authored Apr 8, 2024
1 parent ddae9a9 commit 2d7be3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 11 additions & 2 deletions pkg/auth/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
HasUpstreamAuth = "upstream_auth_enabled"
ObjectKindLabel = "kind"
WithDownstreamDeadlineLabel = "with_downstream_deadline"
WebserviceLabel = "webservice"

MetricsKindSecret = "secret"
MetricsKindWebservice = "webservice"
Expand All @@ -33,7 +34,7 @@ var (
Name: "check_request_count",
Help: "CheckRequest count",
},
[]string{CerberusReasonLabel, CheckRequestVersionLabel, HasUpstreamAuth},
[]string{CerberusReasonLabel, CheckRequestVersionLabel, HasUpstreamAuth, WebserviceLabel},
)

reqLatency = prometheus.NewHistogramVec(
Expand Down Expand Up @@ -128,7 +129,7 @@ var (
Name: "upstream_auth_failed_requests_total",
Help: "Total number of failed UpstreamAuth requests",
},
[]string{"with_downstream_deadline"},
[]string{WithDownstreamDeadlineLabel},
)
)

Expand Down Expand Up @@ -193,3 +194,11 @@ func AddWithDownstreamDeadlineLabel(labels prometheus.Labels, hasDeadline bool)
}
return labels
}

func AddWebserviceLabel(labels prometheus.Labels, wsvc string) prometheus.Labels {
if labels == nil {
labels = prometheus.Labels{}
}
labels[WebserviceLabel] = wsvc
return labels
}
7 changes: 5 additions & 2 deletions pkg/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ func (a *authV2) Check(ctx context.Context, check *CheckRequestV2) (*CheckRespon
labels := AddReasonLabel(nil, reason)
labels = AddUpstreamAuthLabel(labels, request.Context[HasUpstreamAuth])
labels[CheckRequestVersionLabel] = MetricsCheckRequestVersion2
reqCount.With(labels).Inc()
reqLatency.With(labels).Observe(time.Since(reqStartTime).Seconds())
labels = AddWebserviceLabel(labels, string(CerberusHeaderWebservice))
reqCount.With(labels).Inc()


return final_response, nil
}
Expand All @@ -74,8 +76,9 @@ func (a *authV3) Check(ctx context.Context, check *CheckRequestV3) (*CheckRespon
labels := AddReasonLabel(nil, reason)
labels = AddUpstreamAuthLabel(labels, request.Context[HasUpstreamAuth])
labels[CheckRequestVersionLabel] = MetricsCheckRequestVersion3
reqCount.With(labels).Inc()
reqLatency.With(labels).Observe(time.Since(reqStartTime).Seconds())
labels = AddWebserviceLabel(labels, string(CerberusHeaderWebservice))
reqCount.With(labels).Inc()

return final_response, nil
}
Expand Down

0 comments on commit 2d7be3a

Please sign in to comment.