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 request body size metric for the write path. #111917

Merged
merged 2 commits into from Aug 30, 2022

Conversation

logicalhan
Copy link
Member

We can use this metric in conjunction with apiserver_storage_objects to
determine if a LIST is likely to be near a timeout threshold.

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

This metric exposes the request body sizes that have been accepted as being under the apiserver max request body threshold. This metric has two primary usecases:

  1. alerting for when writes begin to approach the threshold in the apiserver
  2. calculating the approximate size of a LIST request by the following function:
    • avg(apiserver_request_body_size{resource="a"}) * apiserver_storage_objects{resource="a"}

Which issue(s) this PR fixes:

Fixes #111893

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 18, 2022
@k8s-ci-robot
Copy link
Contributor

Please note that we're already in Test Freeze for the release-1.25 branch. This means every merged PR will be automatically fast-forwarded via the periodic ci-fast-forward job to the release branch of the upcoming v1.25.0 release.

Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Thu Aug 18 13:40:40 UTC 2022.

@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Aug 18, 2022
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Aug 18, 2022
@logicalhan logicalhan force-pushed the request-sizes branch 2 times, most recently from 54bb697 to 7ce56e0 Compare August 18, 2022 17:58
@logicalhan
Copy link
Member Author

/retest

@apelisse
Copy link
Member

There's the size of the request (the size of the body in the request), and the size of the object as we store in etcd. Differences comes from format used for the request can be different from the storage format (YAML vs Protobuf), but also yaml has some alias and anchor mechanisms that can significantly reduce the size of the object compared to its expanded form. Is this what we want to measure?

@logicalhan
Copy link
Member Author

There's the size of the request (the size of the body in the request), and the size of the object as we store in etcd. Differences comes from format used for the request can be different from the storage format (YAML vs Protobuf), but also yaml has some alias and anchor mechanisms that can significantly reduce the size of the object compared to its expanded form. Is this what we want to measure?

One thing we want to measure is the size of the incoming request. And that's because we have a 3 meg limit and we want to know if our incoming payloads are getting close to that threshold.

The second thing we want is basically size of the outgoing object, which I actually do realize this does not accurately represent. The reason for approximating the size of the outgoing object is basically to have something as a proxy for outgoing object size so that we can do math and determine the estimate size of a full list request so that we can know if the total volume of objects that we have is potentially close to the timeout of a full list.

But actually, I think I need to make the buckets more granular for this.

@leilajal
Copy link
Contributor

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Aug 23, 2022
Change-Id: Ic2bcf39caef791b2e13448a97d2c3203ed1d94b9
@logicalhan logicalhan force-pushed the request-sizes branch 2 times, most recently from dfa83e8 to 67f5af4 Compare August 24, 2022 16:19
Change-Id: Ica5d9b5457d4f844c4500b2c05b2f0631c27454c
@apelisse
Copy link
Member

/lgtm
/approve
Thanks Han!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 24, 2022
Copy link
Member Author

@logicalhan logicalhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/assign @lavalamp

@logicalhan
Copy link
Member Author

/retest

Copy link
Member

@lavalamp lavalamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculating the approximate size of a LIST request by the following function

You can't do that with this metric, request body and stored object sizes have very little to do with each other (imagine encoding differences & create / update sequences)

requestBody: strings.NewReader("aaaa"),
limit: 5,
expectedMetrics: `
# HELP apiserver_request_body_sizes [ALPHA] Apiserver request body sizes broken out by size.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a change detector, is there a better way to verify what happened?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I want to test the exact metric output, so a change detector is actually kinda what I want..

@lavalamp
Copy link
Member

The second thing we want is basically size of the outgoing object, which I actually do realize this does not accurately represent. The reason for approximating the size of the outgoing object is basically to have something as a proxy for outgoing object size so that we can do math and determine the estimate size of a full list request so that we can know if the total volume of objects that we have is potentially close to the timeout of a full list.

I think this metric doesn't get anywhere near close enough for this purpose. The way to do this is to update a metric on GET / LIST requests (divide by number of items returned)

@logicalhan
Copy link
Member Author

I think this metric doesn't get anywhere near close enough for this purpose. The way to do this is to update a metric on GET / LIST requests (divide by number of items returned)

Discussed offline, I'll create another metric for this.

@lavalamp
Copy link
Member

/approve

avg(apiserver_request_body_size{resource="a"}) * apiserver_storage_objects{resource="a"}

I think I'm not worried about people thinking this would work because it won't be obvious at all how to account for create/update/patch request differences.

The other use seems valid though.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse, lavalamp, logicalhan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 30, 2022
@logicalhan
Copy link
Member Author

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apiserver_request_size metrics should be present on kube-apiserver
5 participants