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 webservice label to metrics #49

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading