-
Notifications
You must be signed in to change notification settings - Fork 460
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
distributor: make unit tests more flexible #7205
Conversation
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>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
for i := cfg.happyIngesters; i < cfg.numIngesters; i++ { | ||
ingesters = append(ingesters, mockIngester{ | ||
queryDelay: cfg.queryDelay, | ||
pushDelay: cfg.pushDelay, | ||
seriesCountTotal: cfg.ingestersSeriesCountTotal, | ||
}) | ||
} |
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.
previously unhappy ingesters didn't have a zone set, I think this was a bug
for i := range ingesters { | ||
addr := fmt.Sprintf("%d", i) |
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.
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>
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.
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!
pkg/distributor/distributor_test.go
Outdated
if len(metrics) == 0 { | ||
metrics = []string{"foo"} | ||
} |
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.
[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.
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 don't mind. I think it will make the tests easier to follow. done in 69b2c0f
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 |
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.
[non blocking] In a follow up PR we may consider changing mockIngester
to be a pointer everywhere.
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 opened #7223
|
||
} | ||
|
||
func prepareIngesterZone(zone string, state ingesterZoneState, cfg prepConfig) []mockIngester { |
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.
[nit] Plural ingesters?
func prepareIngesterZone(zone string, state ingesterZoneState, cfg prepConfig) []mockIngester { | |
func prepareIngestersZone(zone string, state ingesterZoneState, cfg prepConfig) []mockIngester { |
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.
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>
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:
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 logicThese are the kind of tests this PR enables