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

distributor: make unit tests more flexible #7205

Conversation

dimitarvdimitrov
Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov commented Jan 24, 2024

This PR is a prerequisite to the work that @pstibrany, @pracucci and I are doing to support a ring for partitions.

The major changes in this PR are:

  • add the ability to specify ingester state by zone; this allows to have a different number of failing ingesters per zone; this is useful in testing the ring retry mechanisms
  • add the ability to specify ingester ring state by zone
  • add the ability to inject data into mockIngesters; this removes the need to push data to ingesters in order ot test query logic. This is necessary when testing ingest storage and removes the need to spin up a kafka-compatible backend and consume from it in order to assert on querying logic

These are the kind of tests this PR enables

This PR is a prerequisite to work that pstibrany and I are doing to support a ring for partitions.

The major changes in this PR are:
* add the ability to specify ingester state by zone; this allows to have a different number of failing ingesters per zone; this is useful in testing the ring retry mechanisms
* add the ability to specify ingester ring state by zone
* add the ability to inject data into `mockIngester`s; this removes the need to push data to ingesters in order ot test query logic. This is necessary when testing ingest storage and removes the need to spin up a kafka-compatible backend and consume from it in order to assert on querying logic

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@dimitarvdimitrov dimitarvdimitrov requested a review from a team as a code owner January 24, 2024 17:02
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Comment on lines -3501 to -3507
for i := cfg.happyIngesters; i < cfg.numIngesters; i++ {
ingesters = append(ingesters, mockIngester{
queryDelay: cfg.queryDelay,
pushDelay: cfg.pushDelay,
seriesCountTotal: cfg.ingestersSeriesCountTotal,
})
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously unhappy ingesters didn't have a zone set, I think this was a bug

for i := range ingesters {
addr := fmt.Sprintf("%d", i)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the address was opaque, so changing it to something more involved shouldn't make a difference

This reverts commit 92cd090.
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@pracucci pracucci self-requested a review January 25, 2024 07:47
Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Nice job! Looks non controversial to me. I left a couple of nits. No need for having me re-reviewing this PR before merging. Thanks!

Comment on lines 4063 to 4065
if len(metrics) == 0 {
metrics = []string{"foo"}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] Have you considered always specifying it? I understand it may require many changes to callers, but would make the logic in the caller easier to follow because it's not based on the assupmption that "no metrics" mean "foo" metric.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't mind. I think it will make the tests easier to follow. done in 69b2c0f

pkg/distributor/distributor_test.go Outdated Show resolved Hide resolved
return ingestersRing.InstancesCount()
})

factory := ring_client.PoolInstFunc(func(inst ring.InstanceDesc) (ring_client.PoolClient, error) {
return ingestersByAddr[inst.Addr], nil
for i := range ingesters {
ing := &ingesters[i] // Take a pointer, so we don't copy the sync.Mutex in the mockIngester
Copy link
Collaborator

Choose a reason for hiding this comment

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

[non blocking] In a follow up PR we may consider changing mockIngester to be a pointer everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened #7223


}

func prepareIngesterZone(zone string, state ingesterZoneState, cfg prepConfig) []mockIngester {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] Plural ingesters?

Suggested change
func prepareIngesterZone(zone string, state ingesterZoneState, cfg prepConfig) []mockIngester {
func prepareIngestersZone(zone string, state ingesterZoneState, cfg prepConfig) []mockIngester {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's one zone of ingesters. Here ingester is an adjective, not a noun.

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@dimitarvdimitrov dimitarvdimitrov enabled auto-merge (squash) January 25, 2024 11:53
@dimitarvdimitrov dimitarvdimitrov merged commit dbb47fd into main Jan 25, 2024
28 checks passed
@dimitarvdimitrov dimitarvdimitrov deleted the dimitar/distributor/add-testing-fscilities-for-partitions-testing branch January 25, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants