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

balancer/weightedroundrobin: Add recording point for endpoint weight not yet usable and add metrics tests #7466

Merged
merged 5 commits into from
Aug 10, 2024

Conversation

zasweq
Copy link
Contributor

@zasweq zasweq commented Aug 1, 2024

This PR adds unit test assertions for Weighted Roudn Robin Metrics and an e2e test with exact OpenTelemetry metrics atoms expected.

It also fixes the "startup" case for WeightedSubConns when a WeightedSubConn has not received a load report yet. Previously, it would record an endpoint weight stale metric, but I added logic to make this case record on endpoint weight not yet usable instead.

RELEASE NOTES: N/A

@zasweq zasweq requested a review from dfawley August 1, 2024 01:59
@zasweq zasweq added this to the 1.66 Release milestone Aug 1, 2024
Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 81.53%. Comparing base (3eb0145) to head (761b729).
Report is 15 commits behind head on master.

Files Patch % Lines
internal/testutils/stats/test_metrics_recorder.go 73.68% 9 Missing and 1 partial ⚠️
internal/testutils/xds/e2e/setup/setup.go 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7466      +/-   ##
==========================================
- Coverage   81.57%   81.53%   -0.05%     
==========================================
  Files         354      358       +4     
  Lines       27076    27278     +202     
==========================================
+ Hits        22088    22240     +152     
- Misses       3798     3824      +26     
- Partials     1190     1214      +24     
Files Coverage Δ
balancer/weightedroundrobin/balancer.go 80.51% <100.00%> (+0.29%) ⬆️
balancer/weightedroundrobin/scheduler.go 100.00% <100.00%> (ø)
internal/testutils/xds/e2e/setup/setup.go 81.81% <81.81%> (ø)
internal/testutils/stats/test_metrics_recorder.go 75.20% <73.68%> (+2.58%) ⬆️

... and 30 files with indirect coverage changes

@zasweq zasweq force-pushed the add-tests-wrr-metrics branch 2 times, most recently from 270a26d to 37e724c Compare August 1, 2024 02:29
@zasweq zasweq force-pushed the add-tests-wrr-metrics branch from 37e724c to f8aed9e Compare August 1, 2024 03:36
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Sending comments discussed offline

// load report, giving that SubConn a weight which will eventually expire.
// Two backends needed as for only one backend, WRR does not recompute the
// scheduler.
for i := 0; i < 100; i++ {
Copy link
Member

Choose a reason for hiding this comment

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

Use a map to guarantee you're hitting both backends. Or make RPCs simultaneously with checking metrics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided to just set weights on both of them, and do the latter. Even if I fork a goroutine here, I don't think there's a guarantee it doesn't just hit backend 2 over and over again 100 times even if I have a metrics emission (will emit endpoint weight metric even if doesn't have a weight).

Comment on lines 456 to 463
rm := &metricdata.ResourceMetrics{}
reader.Collect(ctx, rm)
gotMetrics := map[string]metricdata.Metrics{}
for _, sm := range rm.ScopeMetrics {
for _, m := range sm.Metrics {
gotMetrics[m.Name] = m
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Refactor into a function

@dfawley dfawley assigned zasweq and unassigned dfawley Aug 2, 2024
@zasweq zasweq assigned dfawley and unassigned zasweq Aug 2, 2024
@zasweq zasweq force-pushed the add-tests-wrr-metrics branch from ac5b190 to f50574a Compare August 3, 2024 01:44
@zasweq zasweq force-pushed the add-tests-wrr-metrics branch from f50574a to 6ff2e00 Compare August 3, 2024 02:40
Comment on lines +107 to +108
// ClearMetrics clears the metrics data stores of the test metrics recorder by
// setting all the data to 0.
Copy link
Member

Choose a reason for hiding this comment

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

Why set everything to zero instead of r.data = make(...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is what I do in my constructor, but it seems like it doesn't matter because the writes in RecordSomething() will write a new data type. Should I get rid of that logic in constructor too and here?

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see.. Yes, I would just create an empty map unless there's a need to do otherwise (and then...question whether that need is truly necessary). The zero value as the default should make everything "just work".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah fair. Switched to just making an empty map, and letting new map write take care of it. Made no sense to configure with metrics name list I guess.

@dfawley dfawley assigned zasweq and unassigned dfawley Aug 5, 2024
@zasweq zasweq force-pushed the add-tests-wrr-metrics branch from 5e8a314 to aa9ea9f Compare August 7, 2024 01:47
@zasweq zasweq assigned dfawley and unassigned zasweq Aug 7, 2024
@zasweq zasweq force-pushed the add-tests-wrr-metrics branch from aa9ea9f to 761b729 Compare August 7, 2024 02:06
Comment on lines 112 to 121
wsc := &weightedSubConn{
metricsRecorder: tmr,
weightVal: 3,
}
if test.lastUpdatedSet {
wsc.lastUpdated = time.Now()
}
if test.nonEmptySet {
wsc.nonEmptySince = time.Now()
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider instead to have lastUpdated and nonEmptySince as fields in the test cases struct as time.Times, and just set them to either time.Time{} or time.Now(). Then there's less logic which should make things easier to read & understand in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right sounds good. Switched.

@dfawley dfawley assigned zasweq and unassigned dfawley Aug 9, 2024
@zasweq zasweq merged commit 54b48f7 into grpc:master Aug 10, 2024
10 of 11 checks passed
infovivek2020 pushed a commit to infovivek2020/grpc-go that referenced this pull request Aug 18, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants