-
Notifications
You must be signed in to change notification settings - Fork 840
Improve metrics integration tests #2308
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
pracucci
merged 5 commits into
cortexproject:master
from
pracucci:improve-metrics-integration-tests
Mar 20, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ff7e7b
Improve metrics integration tests
pracucci b859beb
Added alertmanager metric prefix to integration tests
pracucci 5f97a93
Fixed linter and improved tests
pracucci ad2a6aa
Remove cortex_alertmanager prefix check (I've been too much optimistic)
pracucci 4c50a6b
Fixed integration tests after rebasing master
pracucci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // +build requires_docker | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/cortexproject/cortex/integration/e2ecortex" | ||
| ) | ||
|
|
||
| type ServiceType int | ||
|
|
||
| const ( | ||
| Distributor = iota | ||
| Ingester | ||
| Querier | ||
| QueryFrontend | ||
| TableManager | ||
| AlertManager | ||
| Ruler | ||
| ) | ||
|
|
||
| var ( | ||
| // Service-specific metrics prefixes which shouldn't be used by any other service. | ||
| serviceMetricsPrefixes = map[ServiceType][]string{ | ||
| Distributor: []string{}, | ||
| Ingester: []string{}, | ||
| Querier: []string{}, | ||
| QueryFrontend: []string{"cortex_frontend", "cortex_query_frontend"}, | ||
| TableManager: []string{}, | ||
| AlertManager: []string{}, | ||
| Ruler: []string{}, | ||
| } | ||
|
|
||
| // Blacklisted metrics prefixes across any Cortex service. | ||
| blacklistedMetricsPrefixes = []string{ | ||
| "cortex_alert_manager", // It should be "cortex_alertmanager" | ||
| } | ||
| ) | ||
|
|
||
| func assertServiceMetricsPrefixes(t *testing.T, serviceType ServiceType, service *e2ecortex.CortexService) { | ||
| metrics, err := service.Metrics() | ||
| require.NoError(t, err) | ||
|
|
||
| // Build the list of blacklisted metrics prefixes for this specific service. | ||
| blacklist := getBlacklistedMetricsPrefixesByService(serviceType) | ||
|
|
||
| // Ensure no metric name matches the blacklisted prefixes. | ||
| for _, metricLine := range strings.Split(metrics, "\n") { | ||
| metricLine = strings.TrimSpace(metricLine) | ||
| if metricLine == "" || strings.HasPrefix(metricLine, "#") { | ||
| continue | ||
| } | ||
|
|
||
| for _, prefix := range blacklist { | ||
| assert.NotRegexp(t, "^"+prefix, metricLine, "service: %s", service.Name()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func getBlacklistedMetricsPrefixesByService(serviceType ServiceType) []string { | ||
| blacklist := append([]string{}, blacklistedMetricsPrefixes...) | ||
|
|
||
| // Add any service-specific metrics prefix excluding the service itself. | ||
| for t, prefixes := range serviceMetricsPrefixes { | ||
| if t == serviceType { | ||
| continue | ||
| } | ||
|
|
||
| blacklist = append(blacklist, prefixes...) | ||
| } | ||
|
|
||
| return blacklist | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm a bit confused where this is coming from?
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.
There's no such metric prefix. I just wanna avoid we'll add it in the future. I think it's a trivial mistake to do.
For example in the past we did a similar mistake with the query frontend and now we have mixed prefixes
cortex_query_frontendandcortex_frontend.Makes sense to you? If it's just my paranoia I can remove this.
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.
Fine to leave it IMO