Skip to content

Commit

Permalink
remove webservice label from request latency
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeynabRezaei committed Apr 7, 2024
1 parent 0e4c3d0 commit 9bdbc30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions pkg/auth/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
Help: "CheckRequest durations (response times)",
Buckets: DurationBuckets,
},
[]string{CerberusReasonLabel, CheckRequestVersionLabel, HasUpstreamAuth, WebserviceLabel},
[]string{CerberusReasonLabel, CheckRequestVersionLabel, HasUpstreamAuth},
)

cacheUpdateCount = prometheus.NewCounter(
Expand Down Expand Up @@ -150,39 +150,39 @@ func init() {
upstreamAuthFailedRequests,
)
}
///server

func AddReasonLabel(labels prometheus.Labels, reason CerberusReason) prometheus.Labels {
if labels == nil {
labels = prometheus.Labels{}
}
labels[CerberusReasonLabel] = string(reason)
return labels
}
///auth-cache

func AddKindLabel(labels prometheus.Labels, kind string) prometheus.Labels {
if labels == nil {
labels = prometheus.Labels{}
}
labels[ObjectKindLabel] = kind
return labels
}
///auth

func AddStatusLabel(labels prometheus.Labels, status int) prometheus.Labels {
if labels == nil {
labels = prometheus.Labels{}
}
labels[StatusCode] = strconv.Itoa(status)
return labels
}
///server

func AddUpstreamAuthLabel(labels prometheus.Labels, hasUpstreamAuth string) prometheus.Labels {
if labels == nil {
labels = prometheus.Labels{}
}
labels[HasUpstreamAuth] = hasUpstreamAuth
return labels
}
//auth

func AddWithDownstreamDeadlineLabel(labels prometheus.Labels, hasDeadline bool) prometheus.Labels {
if labels == nil {
labels = prometheus.Labels{}
Expand All @@ -194,7 +194,7 @@ func AddWithDownstreamDeadlineLabel(labels prometheus.Labels, hasDeadline bool)
}
return labels
}
///server

func AddWebserviceLabel(labels prometheus.Labels, wsvc string) prometheus.Labels {
if labels == nil {
labels = prometheus.Labels{}
Expand Down
9 changes: 5 additions & 4 deletions pkg/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ func (a *authV2) Check(ctx context.Context, check *CheckRequestV2) (*CheckRespon
reason := CerberusReason(response.Response.Header.Get(CerberusHeaderReasonHeader))
labels := AddReasonLabel(nil, reason)
labels = AddUpstreamAuthLabel(labels, request.Context[HasUpstreamAuth])
labels = AddWebserviceLabel(labels, string(CerberusHeaderWebservice))
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,10 +75,10 @@ func (a *authV3) Check(ctx context.Context, check *CheckRequestV3) (*CheckRespon
reason := CerberusReason(response.Response.Header.Get(CerberusHeaderReasonHeader))
labels := AddReasonLabel(nil, reason)
labels = AddUpstreamAuthLabel(labels, request.Context[HasUpstreamAuth])
labels = AddWebserviceLabel(labels, string(CerberusHeaderWebservice))
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 9bdbc30

Please sign in to comment.