Skip to content

Conversation

@pracucci
Copy link
Contributor

@pracucci pracucci commented Apr 24, 2020

What this PR does:
In #2515 (by Joe) I wanted to assert on cortex_request_duration_seconds in the integration tests, but I wasn't able because unable to assert on a histogram's count value.

In this PR I'm doing baby steps do add functional options support to metrics assection in integration tests. Could be improved in many ways (and I will do in subsequent PRs if this one is approved), but in this PR I would prefer to keep the change set as smallest as possible to validate the basic design.

/cc @bwplotka

Which issue(s) this PR fixes:
Fixes #2975.

Checklist

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

@pstibrany
Copy link
Contributor

This feels bit complicated, but if we don't find a simpler way, I'm fine with it. Each time I need to write new metric-based condition, I need to find out how.

As an alternative, what do you think about a possibility to use PromQL expressions for checking these conditions?

Copy link
Contributor

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Looks good, one suggestion though (:

It's nicely extensible.

@pstibrany while PromQL would be nice it will be massive pain to implement, plus we have only current metric values and PromQL works on step aligned query etc, plus we will need to block 98.9 % of functions operators, etc so literally writing our own parser so it's just complex ;p

I think I like Marco's approach, just we could simplify a bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I get the use case, plus, sometimes you really want only certain label, so we could have WithLabelEquals(name, value string)

However what do you think about simplifying interfaces and having just single metric name? We can save on []string{ boilerplate 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However what do you think about simplifying interfaces and having just single metric name? We can save on []string{ boilerplate

We could, but then the testers *AmongTwo wouldn't work anymore. Cortex is not using it, but Thanos does. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so we could have WithLabelEquals(name, value string)

Agree, done.

Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

👍 (sorry for late review, haven't realized it's not approved yet)

@stale
Copy link

stale bot commented Aug 3, 2020

This issue has been automatically marked as stale because it has not had any activity in the past 60 days. It will be closed in 15 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 3, 2020
@pracucci
Copy link
Contributor Author

pracucci commented Aug 3, 2020

We decided to move forward with this, but haven't got the time to do it yet.

@pracucci pracucci force-pushed the more-flexible-wait-metrics branch from 9bb8c87 to 69630eb Compare August 4, 2020 14:10
Copy link
Contributor

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

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

Assuming the CI passes.


time.Sleep(2 * time.Second)
require.NoError(t, am.WaitSumMetrics(e2e.Equals(0), "cortex_alertmanager_config_invalid"))
require.NoError(t, am.WaitSumMetricsWithOptions(e2e.Equals(0), []string{"cortex_alertmanager_config_invalid"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

LGTM

I am a big fan of the Option pattern you utilized here.

@pracucci pracucci merged commit d8edc95 into cortexproject:master Aug 5, 2020
@pracucci pracucci deleted the more-flexible-wait-metrics branch August 5, 2020 06:48
simonswine pushed a commit to grafana/e2e that referenced this pull request Jan 13, 2022
…tests (cortexproject/cortex#2522)

* Basic functional options support to metrics assertion in integration tests

Signed-off-by: Marco Pracucci <[email protected]>

* Added WithLabelMatchers() option to integration tests

Signed-off-by: Marco Pracucci <[email protected]>

* Removed time.Sleep() from TestAlertmanagerStoreAPI

Signed-off-by: Marco Pracucci <[email protected]>

* Removed last time.Sleep() from integration tests

Signed-off-by: Marco Pracucci <[email protected]>

* Renamed WaitMissingMetric() into WaitRemovedMetric()

Signed-off-by: Marco Pracucci <[email protected]>
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.

Integration Tests: Add Assertion for waiting on a metric to appear

5 participants