forked from cockroachdb/cockroach
-
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.
metric: front-port a regression test
Front-ports some testing improvements from cockroachdb#88331. Note that 22.2 and master don't exhibit the bug fixed in that PR since we switched to using prometheus histograms in cockroachdb#86671. Release note: None
- Loading branch information
Showing
8 changed files
with
234 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
echo | ||
---- | ||
bar_gauge 2 | ||
bar_gauge{tenant_id="2"} 2 | ||
bar_gauge{tenant_id="3"} 0 | ||
baz_gauge 1.5 | ||
baz_gauge{tenant_id="2"} 1.5 | ||
baz_gauge{tenant_id="3"} 0 | ||
foo_counter 6 | ||
foo_counter{tenant_id="2"} 0 | ||
foo_counter{tenant_id="3"} 4 | ||
histo_gram_bucket{le="+Inf"} 2 | ||
histo_gram_bucket{le="1"} 0 | ||
histo_gram_bucket{le="1024"} 2 | ||
histo_gram_bucket{le="128"} 2 | ||
histo_gram_bucket{le="16"} 1 | ||
histo_gram_bucket{le="2"} 0 | ||
histo_gram_bucket{le="256"} 2 | ||
histo_gram_bucket{le="32"} 1 | ||
histo_gram_bucket{le="4"} 0 | ||
histo_gram_bucket{le="512"} 2 | ||
histo_gram_bucket{le="64"} 1 | ||
histo_gram_bucket{le="8"} 0 | ||
histo_gram_bucket{tenant_id="2",le="+Inf"} 1 | ||
histo_gram_bucket{tenant_id="2",le="1"} 0 | ||
histo_gram_bucket{tenant_id="2",le="1024"} 1 | ||
histo_gram_bucket{tenant_id="2",le="128"} 1 | ||
histo_gram_bucket{tenant_id="2",le="16"} 1 | ||
histo_gram_bucket{tenant_id="2",le="2"} 0 | ||
histo_gram_bucket{tenant_id="2",le="256"} 1 | ||
histo_gram_bucket{tenant_id="2",le="32"} 1 | ||
histo_gram_bucket{tenant_id="2",le="4"} 0 | ||
histo_gram_bucket{tenant_id="2",le="512"} 1 | ||
histo_gram_bucket{tenant_id="2",le="64"} 1 | ||
histo_gram_bucket{tenant_id="2",le="8"} 0 | ||
histo_gram_bucket{tenant_id="3",le="+Inf"} 0 | ||
histo_gram_bucket{tenant_id="3",le="1"} 0 | ||
histo_gram_bucket{tenant_id="3",le="1024"} 0 | ||
histo_gram_bucket{tenant_id="3",le="128"} 0 | ||
histo_gram_bucket{tenant_id="3",le="16"} 0 | ||
histo_gram_bucket{tenant_id="3",le="2"} 0 | ||
histo_gram_bucket{tenant_id="3",le="256"} 0 | ||
histo_gram_bucket{tenant_id="3",le="32"} 0 | ||
histo_gram_bucket{tenant_id="3",le="4"} 0 | ||
histo_gram_bucket{tenant_id="3",le="512"} 0 | ||
histo_gram_bucket{tenant_id="3",le="64"} 0 | ||
histo_gram_bucket{tenant_id="3",le="8"} 0 | ||
histo_gram_count 2 | ||
histo_gram_count{tenant_id="2"} 1 | ||
histo_gram_count{tenant_id="3"} 0 | ||
histo_gram_sum 100 | ||
histo_gram_sum{tenant_id="2"} 10 | ||
histo_gram_sum{tenant_id="3"} 0 |
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,53 @@ | ||
echo | ||
---- | ||
bar_gauge 4 | ||
bar_gauge{tenant_id="2"} 2 | ||
bar_gauge{tenant_id="3"} 2 | ||
baz_gauge 4 | ||
baz_gauge{tenant_id="2"} 1.5 | ||
baz_gauge{tenant_id="3"} 2.5 | ||
foo_counter 6 | ||
foo_counter{tenant_id="2"} 2 | ||
foo_counter{tenant_id="3"} 4 | ||
histo_gram_bucket{le="+Inf"} 2 | ||
histo_gram_bucket{le="1"} 0 | ||
histo_gram_bucket{le="1024"} 2 | ||
histo_gram_bucket{le="128"} 2 | ||
histo_gram_bucket{le="16"} 1 | ||
histo_gram_bucket{le="2"} 0 | ||
histo_gram_bucket{le="256"} 2 | ||
histo_gram_bucket{le="32"} 1 | ||
histo_gram_bucket{le="4"} 0 | ||
histo_gram_bucket{le="512"} 2 | ||
histo_gram_bucket{le="64"} 1 | ||
histo_gram_bucket{le="8"} 0 | ||
histo_gram_bucket{tenant_id="2",le="+Inf"} 1 | ||
histo_gram_bucket{tenant_id="2",le="1"} 0 | ||
histo_gram_bucket{tenant_id="2",le="1024"} 1 | ||
histo_gram_bucket{tenant_id="2",le="128"} 1 | ||
histo_gram_bucket{tenant_id="2",le="16"} 1 | ||
histo_gram_bucket{tenant_id="2",le="2"} 0 | ||
histo_gram_bucket{tenant_id="2",le="256"} 1 | ||
histo_gram_bucket{tenant_id="2",le="32"} 1 | ||
histo_gram_bucket{tenant_id="2",le="4"} 0 | ||
histo_gram_bucket{tenant_id="2",le="512"} 1 | ||
histo_gram_bucket{tenant_id="2",le="64"} 1 | ||
histo_gram_bucket{tenant_id="2",le="8"} 0 | ||
histo_gram_bucket{tenant_id="3",le="+Inf"} 1 | ||
histo_gram_bucket{tenant_id="3",le="1"} 0 | ||
histo_gram_bucket{tenant_id="3",le="1024"} 1 | ||
histo_gram_bucket{tenant_id="3",le="128"} 1 | ||
histo_gram_bucket{tenant_id="3",le="16"} 0 | ||
histo_gram_bucket{tenant_id="3",le="2"} 0 | ||
histo_gram_bucket{tenant_id="3",le="256"} 1 | ||
histo_gram_bucket{tenant_id="3",le="32"} 0 | ||
histo_gram_bucket{tenant_id="3",le="4"} 0 | ||
histo_gram_bucket{tenant_id="3",le="512"} 1 | ||
histo_gram_bucket{tenant_id="3",le="64"} 0 | ||
histo_gram_bucket{tenant_id="3",le="8"} 0 | ||
histo_gram_count 2 | ||
histo_gram_count{tenant_id="2"} 1 | ||
histo_gram_count{tenant_id="3"} 1 | ||
histo_gram_sum 100 | ||
histo_gram_sum{tenant_id="2"} 10 | ||
histo_gram_sum{tenant_id="3"} 90 |
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,36 @@ | ||
echo | ||
---- | ||
bar_gauge 2 | ||
bar_gauge{tenant_id="2"} 2 | ||
baz_gauge 1.5 | ||
baz_gauge{tenant_id="2"} 1.5 | ||
foo_counter 6 | ||
foo_counter{tenant_id="3"} 4 | ||
histo_gram_bucket{le="+Inf"} 2 | ||
histo_gram_bucket{le="1"} 0 | ||
histo_gram_bucket{le="1024"} 2 | ||
histo_gram_bucket{le="128"} 2 | ||
histo_gram_bucket{le="16"} 1 | ||
histo_gram_bucket{le="2"} 0 | ||
histo_gram_bucket{le="256"} 2 | ||
histo_gram_bucket{le="32"} 1 | ||
histo_gram_bucket{le="4"} 0 | ||
histo_gram_bucket{le="512"} 2 | ||
histo_gram_bucket{le="64"} 1 | ||
histo_gram_bucket{le="8"} 0 | ||
histo_gram_bucket{tenant_id="2",le="+Inf"} 1 | ||
histo_gram_bucket{tenant_id="2",le="1"} 0 | ||
histo_gram_bucket{tenant_id="2",le="1024"} 1 | ||
histo_gram_bucket{tenant_id="2",le="128"} 1 | ||
histo_gram_bucket{tenant_id="2",le="16"} 1 | ||
histo_gram_bucket{tenant_id="2",le="2"} 0 | ||
histo_gram_bucket{tenant_id="2",le="256"} 1 | ||
histo_gram_bucket{tenant_id="2",le="32"} 1 | ||
histo_gram_bucket{tenant_id="2",le="4"} 0 | ||
histo_gram_bucket{tenant_id="2",le="512"} 1 | ||
histo_gram_bucket{tenant_id="2",le="64"} 1 | ||
histo_gram_bucket{tenant_id="2",le="8"} 0 | ||
histo_gram_count 2 | ||
histo_gram_count{tenant_id="2"} 1 | ||
histo_gram_sum 100 | ||
histo_gram_sum{tenant_id="2"} 10 |
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,36 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package metric_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/echotest" | ||
"github.com/cockroachdb/cockroach/pkg/util/metric" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHistogramPrometheus(t *testing.T) { | ||
// Regression test against https://github.com/cockroachdb/cockroach/pull/88331. | ||
// The output includes buckets for which the upper bound equals the previous | ||
// bucket's upper bound. | ||
h := metric.NewHistogram(metric.Metadata{}, time.Second, []float64{1, 2, 3, 4, 5, 6, 10, 20, 30}) | ||
h.RecordValue(1) | ||
h.RecordValue(5) | ||
h.RecordValue(5) | ||
h.RecordValue(10) | ||
act, err := json.MarshalIndent(*h.ToPrometheusMetric().Histogram, "", " ") | ||
require.NoError(t, err) | ||
echotest.Require(t, string(act), testutils.TestDataPath(t, "histogram.txt")) | ||
} |
Oops, something went wrong.