address feedback: use componentName and resource labels for flagz/statusz metrics

Set component label to componentName (e.g., "kube-proxy", "kubelet")
instead of empty string. Move endpoint identifier from subresource to
resource ("flagz"/"statusz") since these are defined API resources with
their own GVK (config.k8s.io/v1alpha1).
This commit is contained in:
yongruilin
2026-02-26 21:28:03 +00:00
parent e728229cb9
commit c246753025
4 changed files with 12 additions and 12 deletions

View File

@@ -148,10 +148,10 @@ func handleFlagz(componentName string, reg *registry, serializer runtime.Negotia
var deprecated bool
defer func() {
metrics.MonitorRequest(r, "GET", group, version,
"", // resource
DefaultFlagzPath, // subresource
"", // scope
"", // component
"flagz", // resource
"", // subresource
"", // scope
componentName, // component
deprecated,
"", // removedRelease
delegate.Status(), delegate.ContentLength(), time.Since(requestReceivedTimestamp))

View File

@@ -415,8 +415,8 @@ func TestMetrics(t *testing.T) {
expected := strings.NewReader(`
# HELP apiserver_request_total [STABLE] Counter of apiserver requests broken out for each verb, dry run value, group, version, resource, scope, component, and HTTP response code.
# TYPE apiserver_request_total counter
apiserver_request_total{code="200",component="",dry_run="",group="",resource="",scope="",subresource="/flagz",verb="GET",version=""} 1
apiserver_request_total{code="200",component="",dry_run="",group="config.k8s.io",resource="",scope="",subresource="/flagz",verb="GET",version="v1alpha1"} 1
apiserver_request_total{code="200",component="test-server",dry_run="",group="",resource="flagz",scope="",subresource="",verb="GET",version=""} 1
apiserver_request_total{code="200",component="test-server",dry_run="",group="config.k8s.io",resource="flagz",scope="",subresource="",verb="GET",version="v1alpha1"} 1
`)
if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, expected, "apiserver_request_total"); err != nil {
t.Error(err)

View File

@@ -172,10 +172,10 @@ func handleStatusz(componentName string, reg statuszRegistry, serializer runtime
var deprecated bool
defer func() {
metrics.MonitorRequest(r, "GET", group, version,
"", // resource
DefaultStatuszPath, // subresource
"", // scope
"", // component
"statusz", // resource
"", // subresource
"", // scope
componentName, // component
deprecated,
"", // removedRelease
delegate.Status(), delegate.ContentLength(), time.Since(requestReceivedTimestamp))

View File

@@ -501,8 +501,8 @@ func TestMetrics(t *testing.T) {
expected := strings.NewReader(`
# HELP apiserver_request_total [STABLE] Counter of apiserver requests broken out for each verb, dry run value, group, version, resource, scope, component, and HTTP response code.
# TYPE apiserver_request_total counter
apiserver_request_total{code="200",component="",dry_run="",group="",resource="",scope="",subresource="/statusz",verb="GET",version=""} 1
apiserver_request_total{code="200",component="",dry_run="",group="config.k8s.io",resource="",scope="",subresource="/statusz",verb="GET",version="v1alpha1"} 1
apiserver_request_total{code="200",component="test-server",dry_run="",group="",resource="statusz",scope="",subresource="",verb="GET",version=""} 1
apiserver_request_total{code="200",component="test-server",dry_run="",group="config.k8s.io",resource="statusz",scope="",subresource="",verb="GET",version="v1alpha1"} 1
`)
if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, expected, "apiserver_request_total"); err != nil {
t.Error(err)