mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
start to cover all test cases for scrape
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
This commit is contained in:
parent
f35c6649e4
commit
de9de320a4
|
@ -3522,6 +3522,7 @@ metric: <
|
||||||
metricsTexts := map[string]struct {
|
metricsTexts := map[string]struct {
|
||||||
text []string
|
text []string
|
||||||
contentType string
|
contentType string
|
||||||
|
hasClassic bool
|
||||||
hasExponential bool
|
hasExponential bool
|
||||||
}{
|
}{
|
||||||
"text": {
|
"text": {
|
||||||
|
@ -3542,6 +3543,7 @@ metric: <
|
||||||
genTestCounterText("test_metric_3_bucket", 1, true),
|
genTestCounterText("test_metric_3_bucket", 1, true),
|
||||||
genTestHistText("test_histogram_3", true),
|
genTestHistText("test_histogram_3", true),
|
||||||
},
|
},
|
||||||
|
hasClassic: true,
|
||||||
},
|
},
|
||||||
"text, in different order": {
|
"text, in different order": {
|
||||||
text: []string{
|
text: []string{
|
||||||
|
@ -3561,6 +3563,7 @@ metric: <
|
||||||
genTestCounterText("test_metric_3_sum", 1, true),
|
genTestCounterText("test_metric_3_sum", 1, true),
|
||||||
genTestCounterText("test_metric_3_bucket", 1, true),
|
genTestCounterText("test_metric_3_bucket", 1, true),
|
||||||
},
|
},
|
||||||
|
hasClassic: true,
|
||||||
},
|
},
|
||||||
"protobuf": {
|
"protobuf": {
|
||||||
text: []string{
|
text: []string{
|
||||||
|
@ -3581,6 +3584,7 @@ metric: <
|
||||||
genTestHistProto("test_histogram_3", true, false),
|
genTestHistProto("test_histogram_3", true, false),
|
||||||
},
|
},
|
||||||
contentType: "application/vnd.google.protobuf",
|
contentType: "application/vnd.google.protobuf",
|
||||||
|
hasClassic: true,
|
||||||
},
|
},
|
||||||
"protobuf, in different order": {
|
"protobuf, in different order": {
|
||||||
text: []string{
|
text: []string{
|
||||||
|
@ -3601,8 +3605,9 @@ metric: <
|
||||||
genTestCounterProto("test_metric_3_bucket", 1),
|
genTestCounterProto("test_metric_3_bucket", 1),
|
||||||
},
|
},
|
||||||
contentType: "application/vnd.google.protobuf",
|
contentType: "application/vnd.google.protobuf",
|
||||||
|
hasClassic: true,
|
||||||
},
|
},
|
||||||
"protobuf, with native exponential histogram": {
|
"protobuf, with additional native exponential histogram": {
|
||||||
text: []string{
|
text: []string{
|
||||||
genTestCounterProto("test_metric_1", 1),
|
genTestCounterProto("test_metric_1", 1),
|
||||||
genTestCounterProto("test_metric_1_count", 1),
|
genTestCounterProto("test_metric_1_count", 1),
|
||||||
|
@ -3621,6 +3626,28 @@ metric: <
|
||||||
genTestHistProto("test_histogram_3", true, true),
|
genTestHistProto("test_histogram_3", true, true),
|
||||||
},
|
},
|
||||||
contentType: "application/vnd.google.protobuf",
|
contentType: "application/vnd.google.protobuf",
|
||||||
|
hasClassic: true,
|
||||||
|
hasExponential: true,
|
||||||
|
},
|
||||||
|
"protobuf, with only native exponential histogram": {
|
||||||
|
text: []string{
|
||||||
|
genTestCounterProto("test_metric_1", 1),
|
||||||
|
genTestCounterProto("test_metric_1_count", 1),
|
||||||
|
genTestCounterProto("test_metric_1_sum", 1),
|
||||||
|
genTestCounterProto("test_metric_1_bucket", 1),
|
||||||
|
genTestHistProto("test_histogram_1", false, true),
|
||||||
|
genTestCounterProto("test_metric_2", 1),
|
||||||
|
genTestCounterProto("test_metric_2_count", 1),
|
||||||
|
genTestCounterProto("test_metric_2_sum", 1),
|
||||||
|
genTestCounterProto("test_metric_2_bucket", 1),
|
||||||
|
genTestHistProto("test_histogram_2", false, true),
|
||||||
|
genTestCounterProto("test_metric_3", 1),
|
||||||
|
genTestCounterProto("test_metric_3_count", 1),
|
||||||
|
genTestCounterProto("test_metric_3_sum", 1),
|
||||||
|
genTestCounterProto("test_metric_3_bucket", 1),
|
||||||
|
genTestHistProto("test_histogram_3", false, true),
|
||||||
|
},
|
||||||
|
contentType: "application/vnd.google.protobuf",
|
||||||
hasExponential: true,
|
hasExponential: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -3713,34 +3740,49 @@ metric: <
|
||||||
for name, tc := range map[string]struct {
|
for name, tc := range map[string]struct {
|
||||||
scrapeClassicHistograms bool
|
scrapeClassicHistograms bool
|
||||||
convertClassicHistograms bool
|
convertClassicHistograms bool
|
||||||
expectedClassicHistCount int
|
|
||||||
expectedNhcbCount int
|
|
||||||
}{
|
}{
|
||||||
"convert with scrape": {
|
"convert with scrape": {
|
||||||
scrapeClassicHistograms: true,
|
scrapeClassicHistograms: true,
|
||||||
convertClassicHistograms: true,
|
convertClassicHistograms: true,
|
||||||
expectedClassicHistCount: 1,
|
|
||||||
expectedNhcbCount: 1,
|
|
||||||
},
|
},
|
||||||
"convert without scrape": {
|
"convert without scrape": {
|
||||||
scrapeClassicHistograms: false,
|
scrapeClassicHistograms: false,
|
||||||
convertClassicHistograms: true,
|
convertClassicHistograms: true,
|
||||||
expectedClassicHistCount: 0,
|
|
||||||
expectedNhcbCount: 1,
|
|
||||||
},
|
},
|
||||||
"scrape without convert": {
|
"scrape without convert": {
|
||||||
scrapeClassicHistograms: true,
|
scrapeClassicHistograms: true,
|
||||||
convertClassicHistograms: false,
|
convertClassicHistograms: false,
|
||||||
expectedClassicHistCount: 1,
|
|
||||||
expectedNhcbCount: 0,
|
|
||||||
},
|
},
|
||||||
"neither scrape nor convert": {
|
"neither scrape nor convert": {
|
||||||
scrapeClassicHistograms: false,
|
scrapeClassicHistograms: false,
|
||||||
convertClassicHistograms: false,
|
convertClassicHistograms: false,
|
||||||
expectedClassicHistCount: 1, // since these are sent without native histograms
|
|
||||||
expectedNhcbCount: 0,
|
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
|
var expectedClassicHistCount, expectedNativeHistCount int
|
||||||
|
var expectCustomBuckets bool
|
||||||
|
switch {
|
||||||
|
case tc.scrapeClassicHistograms && tc.convertClassicHistograms:
|
||||||
|
expectedClassicHistCount = 1
|
||||||
|
expectedNativeHistCount = 1
|
||||||
|
expectCustomBuckets = true
|
||||||
|
case !tc.scrapeClassicHistograms && tc.convertClassicHistograms:
|
||||||
|
expectedClassicHistCount = 0
|
||||||
|
expectedNativeHistCount = 1
|
||||||
|
expectCustomBuckets = true
|
||||||
|
case tc.scrapeClassicHistograms && !tc.convertClassicHistograms:
|
||||||
|
expectedClassicHistCount = 1
|
||||||
|
expectedNativeHistCount = 0
|
||||||
|
case !tc.scrapeClassicHistograms && !tc.convertClassicHistograms:
|
||||||
|
expectedClassicHistCount = 1 // since these are sent without native histograms
|
||||||
|
expectedNativeHistCount = 0
|
||||||
|
}
|
||||||
|
if metricsText.hasExponential {
|
||||||
|
expectedNativeHistCount = 1
|
||||||
|
expectCustomBuckets = false
|
||||||
|
} else {
|
||||||
|
expectCustomBuckets = true
|
||||||
|
}
|
||||||
|
|
||||||
t.Run(fmt.Sprintf("%s with %s", name, metricsTextName), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%s with %s", name, metricsTextName), func(t *testing.T) {
|
||||||
simpleStorage := teststorage.New(t)
|
simpleStorage := teststorage.New(t)
|
||||||
defer simpleStorage.Close()
|
defer simpleStorage.Close()
|
||||||
|
@ -3830,20 +3872,23 @@ metric: <
|
||||||
checkFloatSeries(series, 1, 1.)
|
checkFloatSeries(series, 1, 1.)
|
||||||
|
|
||||||
series = q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", fmt.Sprintf("test_histogram_%d_count", i)))
|
series = q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", fmt.Sprintf("test_histogram_%d_count", i)))
|
||||||
checkFloatSeries(series, tc.expectedClassicHistCount, 1.)
|
checkFloatSeries(series, expectedClassicHistCount, 1.)
|
||||||
|
|
||||||
series = q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", fmt.Sprintf("test_histogram_%d_sum", i)))
|
series = q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", fmt.Sprintf("test_histogram_%d_sum", i)))
|
||||||
checkFloatSeries(series, tc.expectedClassicHistCount, 10.)
|
checkFloatSeries(series, expectedClassicHistCount, 10.)
|
||||||
|
|
||||||
series = q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", fmt.Sprintf("test_histogram_%d_bucket", i)))
|
series = q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", fmt.Sprintf("test_histogram_%d_bucket", i)))
|
||||||
checkBucketValues(tc.expectedClassicHistCount, metricsText.contentType, series)
|
checkBucketValues(expectedClassicHistCount, metricsText.contentType, series)
|
||||||
|
|
||||||
series = q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", fmt.Sprintf("test_histogram_%d", i)))
|
series = q.Select(ctx, false, nil, labels.MustNewMatcher(labels.MatchRegexp, "__name__", fmt.Sprintf("test_histogram_%d", i)))
|
||||||
if metricsText.hasExponential {
|
|
||||||
checkHistSeries(series, 1, 3)
|
var expectedSchema int32
|
||||||
|
if expectCustomBuckets {
|
||||||
|
expectedSchema = histogram.CustomBucketsSchema
|
||||||
} else {
|
} else {
|
||||||
checkHistSeries(series, tc.expectedNhcbCount, histogram.CustomBucketsSchema)
|
expectedSchema = 3
|
||||||
}
|
}
|
||||||
|
checkHistSeries(series, expectedNativeHistCount, expectedSchema)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue