Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/retina
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 86abced1a587f76e40bc20caacf19c387a50a1b9
Choose a base ref
..
head repository: microsoft/retina
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b4e6afb6c7be69902f5132299bff2106626494c8
Choose a head ref
Showing with 102 additions and 0 deletions.
  1. +102 −0 pkg/telemetry/telemetry_test.go
102 changes: 102 additions & 0 deletions pkg/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
@@ -117,6 +117,108 @@ func (t *tGatherer) Gather() ([]*io_prometheus_client.MetricFamily, error) {
return t.mf, nil
}

func TestMetricsCardinality(t *testing.T) {
counterType := io_prometheus_client.MetricType_COUNTER
histogramType := io_prometheus_client.MetricType_HISTOGRAM
gaugeHistogramType := io_prometheus_client.MetricType_GAUGE_HISTOGRAM
summaryType := io_prometheus_client.MetricType_SUMMARY

simpleCounter := prometheus.NewCounter(prometheus.CounterOpts{

Check failure on line 126 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, amd64)

Metric: test_counter Error: counter metrics should have "_total" suffix (promlinter)

Check failure on line 126 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, arm64)

Metric: test_counter Error: counter metrics should have "_total" suffix (promlinter)

Check failure on line 126 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, amd64)

Metric: test_counter Error: counter metrics should have "_total" suffix (promlinter)

Check failure on line 126 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, arm64)

Metric: test_counter Error: counter metrics should have "_total" suffix (promlinter)
Name: "test_counter",
Help: "test counter",
})

histogram3buckets := prometheus.NewHistogram(prometheus.HistogramOpts{

Check failure on line 131 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, amd64)

Metric: 3buckets_histogram Error: metric name should not include type 'histogram' (promlinter)

Check failure on line 131 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, arm64)

Metric: 3buckets_histogram Error: metric name should not include type 'histogram' (promlinter)

Check failure on line 131 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, amd64)

Metric: 3buckets_histogram Error: metric name should not include type 'histogram' (promlinter)

Check failure on line 131 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, arm64)

Metric: 3buckets_histogram Error: metric name should not include type 'histogram' (promlinter)
Name: "3buckets_histogram",
Help: "test histogram",
Buckets: []float64{1, 2, 3},
})

histogram5buckets := prometheus.NewHistogram(prometheus.HistogramOpts{

Check failure on line 137 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, amd64)

Metric: 5buckets_histogram Error: metric name should not include type 'histogram' (promlinter)

Check failure on line 137 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, arm64)

Metric: 5buckets_histogram Error: metric name should not include type 'histogram' (promlinter)

Check failure on line 137 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, amd64)

Metric: 5buckets_histogram Error: metric name should not include type 'histogram' (promlinter)

Check failure on line 137 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, arm64)

Metric: 5buckets_histogram Error: metric name should not include type 'histogram' (promlinter)
Name: "5buckets_histogram",
Help: "test histogram",
Buckets: []float64{1, 2, 3, 4, 5},
})
summary := prometheus.NewSummary(prometheus.SummaryOpts{

Check failure on line 142 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, amd64)

Metric: test_summary Error: metric name should not include type 'summary' (promlinter)

Check failure on line 142 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, arm64)

Metric: test_summary Error: metric name should not include type 'summary' (promlinter)

Check failure on line 142 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, amd64)

Metric: test_summary Error: metric name should not include type 'summary' (promlinter)

Check failure on line 142 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, arm64)

Metric: test_summary Error: metric name should not include type 'summary' (promlinter)
Name: "test_summary",
Help: "test summary",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
})

outputCounter := io_prometheus_client.Metric{}
simpleCounter.Write(&outputCounter)

Check failure on line 149 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, amd64)

Error return value of `simpleCounter.Write` is not checked (errcheck)

Check failure on line 149 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, arm64)

Error return value of `simpleCounter.Write` is not checked (errcheck)

Check failure on line 149 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, amd64)

Error return value of `simpleCounter.Write` is not checked (errcheck)

Check failure on line 149 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, arm64)

Error return value of `simpleCounter.Write` is not checked (errcheck)
testCounter := io_prometheus_client.MetricFamily{
Type: &counterType,
Metric: []*io_prometheus_client.Metric{
&outputCounter,
},
}

outputHistogram3Buckets := io_prometheus_client.Metric{}
histogram3buckets.Write(&outputHistogram3Buckets)

Check failure on line 158 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, amd64)

Error return value of `histogram3buckets.Write` is not checked (errcheck)

Check failure on line 158 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, arm64)

Error return value of `histogram3buckets.Write` is not checked (errcheck)

Check failure on line 158 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, amd64)

Error return value of `histogram3buckets.Write` is not checked (errcheck)

Check failure on line 158 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, arm64)

Error return value of `histogram3buckets.Write` is not checked (errcheck)
test3BucketsHistogram := io_prometheus_client.MetricFamily{
Type: &histogramType,
Metric: []*io_prometheus_client.Metric{
&outputHistogram3Buckets,
},
}

outputHistogram5Buckets := io_prometheus_client.Metric{}
histogram5buckets.Write(&outputHistogram5Buckets)

Check failure on line 167 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, amd64)

Error return value of `histogram5buckets.Write` is not checked (errcheck)

Check failure on line 167 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, arm64)

Error return value of `histogram5buckets.Write` is not checked (errcheck)

Check failure on line 167 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, amd64)

Error return value of `histogram5buckets.Write` is not checked (errcheck)

Check failure on line 167 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, arm64)

Error return value of `histogram5buckets.Write` is not checked (errcheck)
test5BucketsGaugeHistogram := io_prometheus_client.MetricFamily{
Type: &gaugeHistogramType,
Metric: []*io_prometheus_client.Metric{
&outputHistogram5Buckets,
},
}

outputSummary := io_prometheus_client.Metric{}
summary.Write(&outputSummary)

Check failure on line 176 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, amd64)

Error return value of `summary.Write` is not checked (errcheck)

Check failure on line 176 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (linux, arm64)

Error return value of `summary.Write` is not checked (errcheck)

Check failure on line 176 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, amd64)

Error return value of `summary.Write` is not checked (errcheck)

Check failure on line 176 in pkg/telemetry/telemetry_test.go

GitHub Actions / Lint (windows, arm64)

Error return value of `summary.Write` is not checked (errcheck)
testSummary := io_prometheus_client.MetricFamily{
Type: &summaryType,
Metric: []*io_prometheus_client.Metric{
&outputSummary,
},
}

testcases := []struct {
name string
mf []*io_prometheus_client.MetricFamily
expectedCardinality int
}{
{
"Simple Counter",
[]*io_prometheus_client.MetricFamily{&testCounter},
1,
},
{
"3 Buckets Histogram",
[]*io_prometheus_client.MetricFamily{&test3BucketsHistogram},
6,
},
{
"5 Buckets Gauge Histogram",
[]*io_prometheus_client.MetricFamily{&test5BucketsGaugeHistogram},
8,
},
{
"Summary",
[]*io_prometheus_client.MetricFamily{&testSummary},
5,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
testGatherer := tGatherer{
mf: tc.mf,
}
gotCardinality, err := metricsCardinality(&testGatherer)
require.NoError(t, err)
require.Equal(t, tc.expectedCardinality, gotCardinality)
})
}
}

func TestMetricsCardinality_NilHistogram(t *testing.T) {
histogramType := io_prometheus_client.MetricType_HISTOGRAM
gaugeHistogramType := io_prometheus_client.MetricType_GAUGE_HISTOGRAM