Skip to content

Commit

Permalink
Merge pull request kubernetes#110009 from azylinski/fix-create-cr-scope
Browse files Browse the repository at this point in the history
Fix requests scope classification
  • Loading branch information
k8s-ci-robot committed May 12, 2022
2 parents 1be1ec4 + 690c912 commit 0e56766
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func InstrumentHandlerFunc(verb, group, version, resource, subresource, scope, c

// CleanScope returns the scope of the request.
func CleanScope(requestInfo *request.RequestInfo) string {
if requestInfo.Name != "" {
if requestInfo.Name != "" || requestInfo.Verb == "create" {
return "resource"
}
if requestInfo.Namespace != "" {
Expand Down
19 changes: 16 additions & 3 deletions staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ func TestCleanScope(t *testing.T) {
},
expectedScope: "resource",
},
{
name: "POST resource scope",
requestInfo: &request.RequestInfo{
Verb: "create",
Namespace: "my-namespace",
IsResourceRequest: false,
},
expectedScope: "resource",
},
{
name: "namespace scope",
requestInfo: &request.RequestInfo{
Expand Down Expand Up @@ -293,6 +302,7 @@ func TestRecordDroppedRequests(t *testing.T) {
},
},
requestInfo: &request.RequestInfo{
Verb: "list",
APIGroup: "",
APIVersion: "v1",
Resource: "pods",
Expand All @@ -317,6 +327,7 @@ func TestRecordDroppedRequests(t *testing.T) {
},
},
requestInfo: &request.RequestInfo{
Verb: "create",
APIGroup: "",
APIVersion: "v1",
Resource: "pods",
Expand All @@ -329,22 +340,24 @@ func TestRecordDroppedRequests(t *testing.T) {
apiserver_dropped_requests_total{request_kind="mutating"} 1
# 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="429",component="apiserver",dry_run="",group="",resource="pods",scope="cluster",subresource="",verb="POST",version="v1"} 1
apiserver_request_total{code="429",component="apiserver",dry_run="",group="",resource="pods",scope="resource",subresource="",verb="POST",version="v1"} 1
`,
},
{
desc: "dry-run patch job status",
request: &http.Request{
Method: "PATCH",
URL: &url.URL{
RawPath: "/apis/batch/v1/namespaces/foo/pods/status",
RawPath: "/apis/batch/v1/namespaces/foo/jobs/bar/status",
RawQuery: "dryRun=All",
},
},
requestInfo: &request.RequestInfo{
Verb: "patch",
APIGroup: "batch",
APIVersion: "v1",
Resource: "jobs",
Name: "bar",
Subresource: "status",
IsResourceRequest: true,
},
Expand All @@ -355,7 +368,7 @@ func TestRecordDroppedRequests(t *testing.T) {
apiserver_dropped_requests_total{request_kind="mutating"} 1
# 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="429",component="apiserver",dry_run="All",group="batch",resource="jobs",scope="cluster",subresource="status",verb="PATCH",version="v1"} 1
apiserver_request_total{code="429",component="apiserver",dry_run="All",group="batch",resource="jobs",scope="resource",subresource="status",verb="PATCH",version="v1"} 1
`,
},
}
Expand Down

0 comments on commit 0e56766

Please sign in to comment.