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 unit test for sample-and-watermark histograms #97753

Merged
merged 4 commits into from Feb 2, 2021

Conversation

MikeSpreitzer
Copy link
Member

What type of PR is this?

/kind cleanup
/kind regression

What this PR does / why we need it:
This PR adds unit tests for sample-and-watermark histograms. This is good for two reasons. One is helping to investigate the possible compiler bug in #97685 . The other is to satisfy #96543 .

Which issue(s) this PR fixes:

Fixes #96543

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@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. kind/regression Categorizes issue or PR as related to a regression from a prior release. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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 Jan 6, 2021
@MikeSpreitzer
Copy link
Member Author

@kubernetes/sig-api-machinery-bugs

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. kind/bug Categorizes issue or PR as related to a bug. area/apiserver area/dependency Issues or PRs related to dependency changes labels Jan 6, 2021
@k8s-ci-robot k8s-ci-robot requested review from deads2k, liggitt and a team January 6, 2021 04:36
@MikeSpreitzer
Copy link
Member Author

/cc @lavalamp
@yue9944882
@tkashem

@MikeSpreitzer
Copy link
Member Author

@erikwilson
@brandond

@MikeSpreitzer
Copy link
Member Author

MikeSpreitzer commented Jan 6, 2021

@brandond you can exercise this unit test as follows.

cd staging/src/k8s.io/apiserver/pkg/util/flowcontrol/metrics
go test

For details on the calculations, make it go test . -v.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 6, 2021
@MikeSpreitzer
Copy link
Member Author

@adtac
@wojtek-t

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 6, 2021
Add info message that explains what warnings are deliberate and expected.
@MikeSpreitzer
Copy link
Member Author

The force-push to 194c22f fixes the traditional bazel oversight.

@caesarxuchao
Copy link
Member

/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 Jan 12, 2021
@lavalamp
Copy link
Member

I think in the comment of mine that apparently inspired this, I was hoping for a tabular test of just the quantize function. This is testing a lot more than that and I'm finding it very difficult to follow.

klog.Infof("Expect about %v warnings about time going backwards; this is fake time deliberately misbehaving.", (numIterations*ddtOffset)/ddtRange)
t.Logf("t0=%s", t0)
for i := 0; i < numIterations; i++ {
ddt := time.Microsecond * time.Duration(rand.Intn(ddtRange)-ddtOffset)
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry, I've been staring at this for a while now and I don't really get what exactly is being tested or why it's being tested like this :( I'm really sorry to give feedback this vague but I'm not sure what would help here.

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 added a comment explaining the new test func.
I prefer behavior tests to checksum tests. This behavioral test exercises the quantize function, so should cover the original ask.

@logicalhan
Copy link
Member

/cc @YoyinZyc

ddt := time.Microsecond * time.Duration(rand.Intn(ddtRange)-ddtOffset)
t1 = t1.Add(ddt)
diff := t1.Sub(t0)
if diff > dt {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am so sorry I don't really get the logic behind this code. Can you explain more about the relationship between clock and the histogram count? Also how do you calculate the expectedCount?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added/expanded comments, hopefully it is clearer now.

t0 := time.Now()
clk := clock.NewFakePassiveClock(t0)
buckets := []float64{0, 1}
const samplingPeriod = time.Millisecond
Copy link
Contributor

Choose a reason for hiding this comment

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

Put samplingPeriod into above const block?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

for _, reg := range regs {
legacyregistry.MustRegister(reg)
}
dt := 2 * samplingPeriod
Copy link
Contributor

Choose a reason for hiding this comment

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

what is dt? Why it is 2 samplingPeriod?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added comment explaining what dt is. Changed my mind about initialization; the original was to avoid the case of a net negative time difference, and I decided to not try to avoid that.

dt = diff
}
clk.SetTime(t1)
saw.Set(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to test other timeObserver operation like Add or SetX1?

Copy link
Member Author

Choose a reason for hiding this comment

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

Additional tests could be created for those. This one is explicitly and exclusively focused on the question of when samples are taken.

@YoyinZyc
Copy link
Contributor

YoyinZyc commented Feb 1, 2021

It is much clearer with the comments. I am good to go. Thanks for adding the tests. :)
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 1, 2021
@lavalamp
Copy link
Member

lavalamp commented Feb 1, 2021

/approve
/sig api-machinery

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lavalamp, MikeSpreitzer

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

@MikeSpreitzer
Copy link
Member Author

/sig api-machinery

@MikeSpreitzer
Copy link
Member Author

@kubernetes/sig-api-machinery-bugs

@BenTheElder BenTheElder removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Feb 2, 2021
@k8s-ci-robot k8s-ci-robot merged commit b36afa5 into kubernetes:master Feb 2, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Feb 2, 2021
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 area/dependency Issues or PRs related to dependency changes cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/regression Categorizes issue or PR as related to a regression from a prior release. 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. 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.

Want better testing of monotonic time in sample_and_watermark.go
7 participants