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/rls: Add picker and cache unit tests for RLS Metrics #7614

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zasweq
Copy link
Contributor

@zasweq zasweq commented Sep 10, 2024

This PR adds picker and cache unit tests to test RLS Metrics.

RELEASE NOTES: N/A

@zasweq zasweq requested a review from dfawley September 10, 2024 23:19
@zasweq zasweq added this to the 1.68 Release milestone Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 10 lines in your changes missing coverage. Please review.

Project coverage is 81.84%. Comparing base (11c44fb) to head (d3c805c).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
internal/testutils/stats/test_metrics_recorder.go 66.66% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7614      +/-   ##
==========================================
- Coverage   81.93%   81.84%   -0.09%     
==========================================
  Files         361      361              
  Lines       27816    27814       -2     
==========================================
- Hits        22790    22764      -26     
- Misses       3837     3851      +14     
- Partials     1189     1199      +10     
Files with missing lines Coverage Δ
internal/testutils/stats/test_metrics_recorder.go 80.16% <66.66%> (+7.80%) ⬆️

... and 21 files with indirect coverage changes

@zasweq zasweq force-pushed the rls-metrics-cache-picker-test branch from dc4efec to 29ea040 Compare September 11, 2024 00:29
r.mu.Lock()
defer r.mu.Unlock()
if _, ok := r.data[estats.Metric(metricName)]; ok {
r.t.Fatalf("Data is present for metric %v", metricName)
Copy link
Member

Choose a reason for hiding this comment

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

This is following an anti-pattern: https://google.github.io/styleguide/go/decisions#assert

Now that we have more time, let's address this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't pass t to this component anymore, did all the assertions inline.

@@ -242,3 +242,50 @@ func (s) TestDataCache_ResetBackoffState(t *testing.T) {
t.Fatalf("unexpected diff in backoffState for cache entry after dataCache.resetBackoffState(): %s", diff)
}
}

var cacheEntriesMetricsTests = []*cacheEntry{
Copy link
Member

Choose a reason for hiding this comment

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

Please move inside test function so it's not global.

Copy link
Contributor Author

@zasweq zasweq Sep 12, 2024

Choose a reason for hiding this comment

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

Ah good point. Done. No need to clear back to original state too as I do later.

Comment on lines 268 to 272
// Resize down the cache to 3 entries. This should scale down the cache to 3
// entries with 3 bytes each, so should record 3 entries and 9 size.
dc.resize(9)
tmr.AssertDataForMetric("grpc.lb.rls.cache_entries", 3)
tmr.AssertDataForMetric("grpc.lb.rls.cache_size", 9)
Copy link
Member

Choose a reason for hiding this comment

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

This relies on having the same size for every entry? Or does order matter?

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 it relies. I think operations are deterministic if I tweak the numbers, but I don't know if we'll have that guarantee in the future. Let me play around with this some.

{size: 3},
{size: 3},
{size: 3},
{size: 3},
Copy link
Member

Choose a reason for hiding this comment

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

It seems like these should vary to have better coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to 12345, and scaled the assertions to follow this. Luckily all the cache operations are deterministic.

@dfawley dfawley assigned zasweq and unassigned dfawley Sep 12, 2024
@zasweq zasweq assigned dfawley and unassigned zasweq Sep 13, 2024
@zasweq zasweq force-pushed the rls-metrics-cache-picker-test branch from 2b745ab to 0ff3022 Compare September 13, 2024 20:12
balancer/weightedroundrobin/balancer_test.go Outdated Show resolved Hide resolved
balancer/rls/cache_test.go Outdated Show resolved Hide resolved
balancer/weightedroundrobin/balancer_test.go Show resolved Hide resolved
internal/testutils/stats/test_metrics_recorder.go Outdated Show resolved Hide resolved
@zasweq zasweq assigned zasweq and unassigned dfawley Sep 17, 2024
@zasweq zasweq force-pushed the rls-metrics-cache-picker-test branch 3 times, most recently from 5fb24a6 to e8ff69d Compare September 17, 2024 23:02
@zasweq zasweq force-pushed the rls-metrics-cache-picker-test branch from b2338c5 to 2c3d2f3 Compare September 17, 2024 23:11
intCountCh *testutils.Channel
floatCountCh *testutils.Channel
intHistoCh *testutils.Channel
floatHistoCh *testutils.Channel
intGaugeCh *testutils.Channel

// Mu protects Data.
// Mu protects data.
Mu sync.Mutex
Copy link
Member

Choose a reason for hiding this comment

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

The main goal of making a getter was so that mu didn't need to be exported and to make access simpler, since mutexes are generally internal state and complicate things.

Seems like you need something more complex if you need an atomic read of multiple values (though this wasn't supported previously?). func Metrics(name []string) (*float64)???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmmmm I just deleted the grab of it in balancer_test. I was worried due to the low time for weight updates (when time.Ticker goes off and reupdates scheduler) but I made it 30 seconds so should never race (it'll fail much earlier than that). So mutex still grabbed sometimes in this component in exported helpers.

@zasweq zasweq assigned dfawley and unassigned zasweq Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants