Skip to content

Commit cc31909

Browse files
author
Han Kang
committed
remove client label from apiserver request count metric since it is unbounded
Change-Id: I3a9eacebc9d9dc9ed6347260d9378cdcb5743431
1 parent 81acde7 commit cc31909

File tree

3 files changed

+3
-80
lines changed

3 files changed

+3
-80
lines changed

staging/src/k8s.io/apiserver/pkg/endpoints/metrics/BUILD

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ package(default_visibility = ["//visibility:public"])
33
load(
44
"@io_bazel_rules_go//go:def.bzl",
55
"go_library",
6-
"go_test",
7-
)
8-
9-
go_test(
10-
name = "go_default_test",
11-
srcs = ["metrics_test.go"],
12-
embed = [":go_default_library"],
136
)
147

158
go_library(
@@ -20,7 +13,6 @@ go_library(
2013
deps = [
2114
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation:go_default_library",
2215
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
23-
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
2416
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
2517
"//staging/src/k8s.io/apiserver/pkg/endpoints/request:go_default_library",
2618
"//staging/src/k8s.io/apiserver/pkg/features:go_default_library",

staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131

3232
"k8s.io/apimachinery/pkg/apis/meta/v1/validation"
3333
"k8s.io/apimachinery/pkg/types"
34-
utilnet "k8s.io/apimachinery/pkg/util/net"
3534
utilsets "k8s.io/apimachinery/pkg/util/sets"
3635
"k8s.io/apiserver/pkg/endpoints/request"
3736
"k8s.io/apiserver/pkg/features"
@@ -65,14 +64,14 @@ var (
6564
requestCounter = compbasemetrics.NewCounterVec(
6665
&compbasemetrics.CounterOpts{
6766
Name: "apiserver_request_total",
68-
Help: "Counter of apiserver requests broken out for each verb, dry run value, group, version, resource, scope, component, client, and HTTP response contentType and code.",
67+
Help: "Counter of apiserver requests broken out for each verb, dry run value, group, version, resource, scope, component, and HTTP response contentType and code.",
6968
StabilityLevel: compbasemetrics.ALPHA,
7069
},
7170
// The label_name contentType doesn't follow the label_name convention defined here:
7271
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/instrumentation.md
7372
// But changing it would break backwards compatibility. Future label_names
7473
// should be all lowercase and separated by underscores.
75-
[]string{"verb", "dry_run", "group", "version", "resource", "subresource", "scope", "component", "client", "contentType", "code"},
74+
[]string{"verb", "dry_run", "group", "version", "resource", "subresource", "scope", "component", "contentType", "code"},
7675
)
7776
longRunningRequestGauge = compbasemetrics.NewGaugeVec(
7877
&compbasemetrics.GaugeOpts{
@@ -256,9 +255,8 @@ func RecordLongRunning(req *http.Request, requestInfo *request.RequestInfo, comp
256255
func MonitorRequest(req *http.Request, verb, group, version, resource, subresource, scope, component, contentType string, httpCode, respSize int, elapsed time.Duration) {
257256
reportedVerb := cleanVerb(verb, req)
258257
dryRun := cleanDryRun(req.URL)
259-
client := cleanUserAgent(utilnet.GetHTTPClient(req))
260258
elapsedSeconds := elapsed.Seconds()
261-
requestCounter.WithLabelValues(reportedVerb, dryRun, group, version, resource, subresource, scope, component, client, contentType, codeToString(httpCode)).Inc()
259+
requestCounter.WithLabelValues(reportedVerb, dryRun, group, version, resource, subresource, scope, component, contentType, codeToString(httpCode)).Inc()
262260
requestLatencies.WithLabelValues(reportedVerb, dryRun, group, version, resource, subresource, scope, component).Observe(elapsedSeconds)
263261
// We are only interested in response sizes of read requests.
264262
if verb == "GET" || verb == "LIST" {
@@ -376,19 +374,6 @@ func cleanDryRun(u *url.URL) string {
376374
return strings.Join(utilsets.NewString(dryRun...).List(), ",")
377375
}
378376

379-
func cleanUserAgent(ua string) string {
380-
// We collapse all "web browser"-type user agents into one "browser" to reduce metric cardinality.
381-
if strings.HasPrefix(ua, "Mozilla/") {
382-
return "Browser"
383-
}
384-
// If an old "kubectl.exe" has passed us its full path, we discard the path portion.
385-
if kubectlExeRegexp.MatchString(ua) {
386-
// avoid an allocation
387-
ua = kubectlExeRegexp.ReplaceAllString(ua, "$1")
388-
}
389-
return ua
390-
}
391-
392377
// ResponseWriterDelegator interface wraps http.ResponseWriter to additionally record content-length, status-code, etc.
393378
type ResponseWriterDelegator struct {
394379
http.ResponseWriter

staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics_test.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)