Skip to content

Commit 4892b63

Browse files
authored
Allow quickstarttest to be compatible with various exporters (#114)
* Allow quickstarttest to be compatible with various exporters * Add comment explaining multiple strings for exporters
1 parent b2253b1 commit 4892b63

2 files changed

Lines changed: 41 additions & 13 deletions

File tree

quickstarttest/testcases.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ const (
4141

4242
type testCase struct {
4343
metricName string
44-
exporter string
44+
exporters []string
4545
threshold float64
4646
}
4747

48+
// Multiple strings for exporters are the names of the exporters that the testcases will recognize.
49+
// Multiple variations of otlp exporter strings are used to ensure that the tests recognize the exporters from various collector versions.
50+
// The otlp exporters have been referred to by different names under different collector versions.
4851
var testCases = []testCase{
49-
{metricName: "otelcol_exporter_sent_spans", exporter: "otlphttp", threshold: sentItemsThreshold},
50-
{metricName: "otelcol_exporter_sent_log_records", exporter: "googlecloud", threshold: sentItemsThreshold},
51-
{metricName: "otelcol_exporter_sent_metric_points", exporter: "googlemanagedprometheus", threshold: sentItemsThreshold},
52+
{metricName: "otelcol_exporter_sent_spans", exporters: []string{"otlphttp", "otlp_http", "otlp", "googlecloud"}, threshold: sentItemsThreshold},
53+
{metricName: "otelcol_exporter_sent_log_records", exporters: []string{"googlecloud", "otlphttp", "otlp_http", "otlp"}, threshold: sentItemsThreshold},
54+
{metricName: "otelcol_exporter_sent_metric_points", exporters: []string{"googlemanagedprometheus", "otlphttp", "otlp_http", "otlp", "googlecloud"}, threshold: sentItemsThreshold},
5255
}
5356

5457
// InstrumentationQuickstartTest runs the instrumentation quickstart docker compose setup in
@@ -173,12 +176,16 @@ func verifyPromMetric(t assert.TestingT, promMetrics map[string]*dto.MetricFamil
173176

174177
for _, metric := range mf.Metric {
175178
for _, labelPair := range metric.GetLabel() {
176-
if labelPair.GetName() == "exporter" && labelPair.GetValue() == tc.exporter {
177-
value := metric.GetCounter().GetValue()
178-
assert.Greaterf(t, value, tc.threshold, "Metric %v was expected to have value > %v, got %v", metric, sentItemsThreshold, value)
179-
return
179+
if labelPair.GetName() == "exporter" {
180+
for _, expectedExporter := range tc.exporters {
181+
if labelPair.GetValue() == expectedExporter {
182+
value := metric.GetCounter().GetValue()
183+
assert.Greaterf(t, value, tc.threshold, "Metric %v was expected to have value > %v, got %v", metric, sentItemsThreshold, value)
184+
return
185+
}
186+
}
180187
}
181188
}
182189
}
183-
assert.Failf(t, "Could not find a metric sample for exporter=%v, got metrics %v", tc.exporter, mf)
190+
assert.Fail(t, fmt.Sprintf("Could not find a metric sample for exporters=%v, got metrics %v", tc.exporters, mf))
184191
}

quickstarttest/testcases_test.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestVerifyPromMetric(t *testing.T) {
4949
otelcol_exporter_sent_log_records{exporter="googlecloud"} 631
5050
`,
5151
testCase: testCase{
52-
exporter: "googlecloud",
52+
exporters: []string{"googlecloud"},
5353
metricName: "otelcol_exporter_sent_log_records",
5454
threshold: 100,
5555
},
@@ -63,7 +63,7 @@ func TestVerifyPromMetric(t *testing.T) {
6363
`,
6464
expectFail: true,
6565
testCase: testCase{
66-
exporter: "googlecloud",
66+
exporters: []string{"googlecloud"},
6767
metricName: "otelcol_exporter_sent_log_records",
6868
threshold: 100,
6969
},
@@ -72,7 +72,7 @@ func TestVerifyPromMetric(t *testing.T) {
7272
name: "metric is not present fail",
7373
textFormat: ``,
7474
testCase: testCase{
75-
exporter: "googlecloud",
75+
exporters: []string{"googlecloud"},
7676
metricName: "otelcol_exporter_sent_log_records",
7777
threshold: 100,
7878
},
@@ -87,7 +87,7 @@ func TestVerifyPromMetric(t *testing.T) {
8787
`,
8888
expectFail: true,
8989
testCase: testCase{
90-
exporter: "fooexporter",
90+
exporters: []string{"fooexporter"},
9191
metricName: "otelcol_exporter_sent_log_records",
9292
threshold: 100,
9393
},
@@ -131,6 +131,27 @@ func TestVerifyPromRealTestCasesSuccess(t *testing.T) {
131131
}
132132
}
133133

134+
func TestVerifyPromRealTestCasesSuccessOTLP(t *testing.T) {
135+
parser := expfmt.NewTextParser(model.UTF8Validation)
136+
// Taken from a real run of the quickstart with OTLP exporters
137+
actual, err := parser.TextToMetricFamilies(strings.NewReader(`
138+
# HELP otelcol_exporter_sent_log_records Number of log record successfully sent to destination.
139+
# TYPE otelcol_exporter_sent_log_records counter
140+
otelcol_exporter_sent_log_records{exporter="otlphttp",service_instance_id="cc2396b4-e313-4c5a-8c35-0cb221a02fa8",service_name="otelcol-contrib",service_version="0.155.0"} 437
141+
# HELP otelcol_exporter_sent_metric_points Number of metric points successfully sent to destination.
142+
# TYPE otelcol_exporter_sent_metric_points counter
143+
otelcol_exporter_sent_metric_points{exporter="otlphttp",service_instance_id="cc2396b4-e313-4c5a-8c35-0cb221a02fa8",service_name="otelcol-contrib",service_version="0.155.0"} 333
144+
# HELP otelcol_exporter_sent_spans Number of spans successfully sent to destination.
145+
# TYPE otelcol_exporter_sent_spans counter
146+
otelcol_exporter_sent_spans{exporter="otlphttp",service_instance_id="cc2396b4-e313-4c5a-8c35-0cb221a02fa8",service_name="otelcol-contrib",service_version="0.155.0"} 499
147+
`))
148+
require.NoError(t, err)
149+
150+
for _, tc := range testCases {
151+
verifyPromMetric(t, actual, tc)
152+
}
153+
}
154+
134155
func TestVerifyPromRealTestCasesFails(t *testing.T) {
135156
parser := expfmt.NewTextParser(model.UTF8Validation)
136157
// Taken from a real run of the quickstart

0 commit comments

Comments
 (0)