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
Conversation
@kubernetes/sig-api-machinery-bugs |
b65e1f3
to
5c92ff5
Compare
@brandond you can exercise this unit test as follows.
For details on the calculations, make it |
5c92ff5
to
546cee3
Compare
546cee3
to
5fe48be
Compare
Add info message that explains what warnings are deliberate and expected.
77e9507
to
194c22f
Compare
The force-push to 194c22f fixes the traditional bazel oversight. |
/triage accepted |
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
/cc @YoyinZyc |
ddt := time.Microsecond * time.Duration(rand.Intn(ddtRange)-ddtOffset) | ||
t1 = t1.Add(ddt) | ||
diff := t1.Sub(t0) | ||
if diff > dt { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
It is much clearer with the comments. I am good to go. Thanks for adding the tests. :) |
/approve |
[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 |
/sig api-machinery |
@kubernetes/sig-api-machinery-bugs |
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?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: