Skip to content

Create ValidateMetrics #5988

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

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

CharlieTLe
Copy link
Member

The validation package is exporting Prometheus counters that are using the default Prometheus registry. This is problematic when unit tests are running tests in parallel because the distributors and ingesters will use the exported counters in their tests.

What this PR does:
Creates a ValidateMetrics struct to house the metrics defined in the validation package so that it can be registered to a registry.

The TestIngester_inflightPushRequests test was updated as well since it could fail if there were too many samples pushed (3600000 (also number of seconds in an hour)) and an out of bounds error would be thrown.

Which issue(s) this PR fixes:
Fixes: #5659

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

The validation package is exporting Prometheus counters that are using
the default Prometheus registry. This is problematic when unit tests are
running tests in parallel because the distributors and ingesters will
use the exported counters in their tests.

Signed-off-by: Charlie Le <[email protected]>
Comment on lines -4437 to -4457
count := 100000
target := time.Second

// find right count to make sure that push takes given target duration.
for {
req := generateSamplesForLabel(labels.FromStrings(labels.MetricName, fmt.Sprintf("test-%d", count)), count)

start := time.Now()
_, err := i.Push(ctx, req)
require.NoError(t, err)

elapsed := time.Since(start)
t.Log(count, elapsed)
if elapsed > time.Second {
break
}

count = int(float64(count) * float64(target/elapsed) * 1.5) // Adjust number of samples to hit our target push duration.
}

// Now repeat push with number of samples calibrated to our target.
Copy link
Member

Choose a reason for hiding this comment

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

is this change related to this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not, I can move it into a separate PR if you'd like. The change was included to address an issue with the test's flakiness. I added a note about it in the description of the PR:

The TestIngester_inflightPushRequests test was updated as well since it could fail if there were too many samples pushed (3600000 (also number of seconds in an hour)) and an out of bounds error would be thrown.

Copy link
Member

Choose a reason for hiding this comment

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

Its ok!

Signed-off-by: Charlie Le <[email protected]>
@@ -1,32 +1,34 @@
package ingester

import (
"github.com/cortexproject/cortex/pkg/util/validation"
Copy link
Member

Choose a reason for hiding this comment

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

Use formatting so the lint passes

These metrics could be registered by the distributor and the ingester in
single binary mode.

Signed-off-by: Charlie Le <[email protected]>
)
func registerCollector(r prometheus.Registerer, c prometheus.Collector) {
err := r.Register(c)
if err != nil && !errors.As(err, &prometheus.AlreadyRegisteredError{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we expect to have prometheus.AlreadyRegisteredError error?

Copy link
Member Author

@CharlieTLe CharlieTLe May 31, 2024

Choose a reason for hiding this comment

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

Yes, it will happen when the distributor and ingester are both instantiated in the test TestCortex. Also, these metrics could be registered by the distributor and the ingester in single binary mode.

[]string{discardReasonLabel, "user"},
)
registerCollector(r, discardedExemplars)
discardedMetadata := prometheus.NewCounterVec(
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can just use promauto package here which automatically registers the collector.

Copy link
Member Author

Choose a reason for hiding this comment

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

We cannot because promauto does MustRegister which will panic if there is a registration error (this includes AlreadyRegisteredError).

Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

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

Great work. I am going to merge it to address the flaky test in #5986.

@yeya24 yeya24 merged commit 60f24cf into cortexproject:master Jun 3, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky distributor test RelabelDropWillExportMetricOfDroppedSamples
4 participants