forked from cortexproject/cortex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic functional options support to metrics assertion in integration …
…tests (cortexproject#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]>
- Loading branch information
Showing
10 changed files
with
222 additions
and
132 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,52 @@ | ||
package e2e | ||
|
||
import ( | ||
io_prometheus_client "github.com/prometheus/client_model/go" | ||
"github.com/prometheus/prometheus/pkg/labels" | ||
) | ||
|
||
var ( | ||
DefaultMetricsOptions = MetricsOptions{ | ||
GetValue: getMetricValue, | ||
WaitMissingMetrics: false, | ||
} | ||
) | ||
|
||
// GetMetricValueFunc defined the signature of a function used to get the metric value. | ||
type GetMetricValueFunc func(m *io_prometheus_client.Metric) float64 | ||
|
||
// MetricsOption defined the signature of a function used to manipulate options. | ||
type MetricsOption func(*MetricsOptions) | ||
|
||
// MetricsOptions is the structure holding all options. | ||
type MetricsOptions struct { | ||
GetValue GetMetricValueFunc | ||
LabelMatchers []*labels.Matcher | ||
WaitMissingMetrics bool | ||
} | ||
|
||
// WithMetricCount is an option to get the histogram/summary count as metric value. | ||
func WithMetricCount(opts *MetricsOptions) { | ||
opts.GetValue = getMetricCount | ||
} | ||
|
||
// WithLabelMatchers is an option to filter only matching series. | ||
func WithLabelMatchers(matchers ...*labels.Matcher) MetricsOption { | ||
return func(opts *MetricsOptions) { | ||
opts.LabelMatchers = matchers | ||
} | ||
} | ||
|
||
// WithWaitMissingMetrics is an option to wait whenever an expected metric is missing. If this | ||
// option is not enabled, will return error on missing metrics. | ||
func WaitMissingMetrics(opts *MetricsOptions) { | ||
opts.WaitMissingMetrics = true | ||
} | ||
|
||
func buildMetricsOptions(opts []MetricsOption) MetricsOptions { | ||
result := DefaultMetricsOptions | ||
for _, opt := range opts { | ||
opt(&result) | ||
} | ||
return result | ||
} |
Oops, something went wrong.