diff --git a/quickstarttest/testcases.go b/quickstarttest/testcases.go index fc48a14..d64b600 100644 --- a/quickstarttest/testcases.go +++ b/quickstarttest/testcases.go @@ -41,14 +41,17 @@ const ( type testCase struct { metricName string - exporter string + exporters []string threshold float64 } +// Multiple strings for exporters are the names of the exporters that the testcases will recognize. +// Multiple variations of otlp exporter strings are used to ensure that the tests recognize the exporters from various collector versions. +// The otlp exporters have been referred to by different names under different collector versions. var testCases = []testCase{ - {metricName: "otelcol_exporter_sent_spans", exporter: "otlphttp", threshold: sentItemsThreshold}, - {metricName: "otelcol_exporter_sent_log_records", exporter: "googlecloud", threshold: sentItemsThreshold}, - {metricName: "otelcol_exporter_sent_metric_points", exporter: "googlemanagedprometheus", threshold: sentItemsThreshold}, + {metricName: "otelcol_exporter_sent_spans", exporters: []string{"otlphttp", "otlp_http", "otlp", "googlecloud"}, threshold: sentItemsThreshold}, + {metricName: "otelcol_exporter_sent_log_records", exporters: []string{"googlecloud", "otlphttp", "otlp_http", "otlp"}, threshold: sentItemsThreshold}, + {metricName: "otelcol_exporter_sent_metric_points", exporters: []string{"googlemanagedprometheus", "otlphttp", "otlp_http", "otlp", "googlecloud"}, threshold: sentItemsThreshold}, } // InstrumentationQuickstartTest runs the instrumentation quickstart docker compose setup in @@ -173,12 +176,16 @@ func verifyPromMetric(t assert.TestingT, promMetrics map[string]*dto.MetricFamil for _, metric := range mf.Metric { for _, labelPair := range metric.GetLabel() { - if labelPair.GetName() == "exporter" && labelPair.GetValue() == tc.exporter { - value := metric.GetCounter().GetValue() - assert.Greaterf(t, value, tc.threshold, "Metric %v was expected to have value > %v, got %v", metric, sentItemsThreshold, value) - return + if labelPair.GetName() == "exporter" { + for _, expectedExporter := range tc.exporters { + if labelPair.GetValue() == expectedExporter { + value := metric.GetCounter().GetValue() + assert.Greaterf(t, value, tc.threshold, "Metric %v was expected to have value > %v, got %v", metric, sentItemsThreshold, value) + return + } + } } } } - assert.Failf(t, "Could not find a metric sample for exporter=%v, got metrics %v", tc.exporter, mf) + assert.Fail(t, fmt.Sprintf("Could not find a metric sample for exporters=%v, got metrics %v", tc.exporters, mf)) } diff --git a/quickstarttest/testcases_test.go b/quickstarttest/testcases_test.go index ff0f93a..b7482fb 100644 --- a/quickstarttest/testcases_test.go +++ b/quickstarttest/testcases_test.go @@ -49,7 +49,7 @@ func TestVerifyPromMetric(t *testing.T) { otelcol_exporter_sent_log_records{exporter="googlecloud"} 631 `, testCase: testCase{ - exporter: "googlecloud", + exporters: []string{"googlecloud"}, metricName: "otelcol_exporter_sent_log_records", threshold: 100, }, @@ -63,7 +63,7 @@ func TestVerifyPromMetric(t *testing.T) { `, expectFail: true, testCase: testCase{ - exporter: "googlecloud", + exporters: []string{"googlecloud"}, metricName: "otelcol_exporter_sent_log_records", threshold: 100, }, @@ -72,7 +72,7 @@ func TestVerifyPromMetric(t *testing.T) { name: "metric is not present fail", textFormat: ``, testCase: testCase{ - exporter: "googlecloud", + exporters: []string{"googlecloud"}, metricName: "otelcol_exporter_sent_log_records", threshold: 100, }, @@ -87,7 +87,7 @@ func TestVerifyPromMetric(t *testing.T) { `, expectFail: true, testCase: testCase{ - exporter: "fooexporter", + exporters: []string{"fooexporter"}, metricName: "otelcol_exporter_sent_log_records", threshold: 100, }, @@ -131,6 +131,27 @@ func TestVerifyPromRealTestCasesSuccess(t *testing.T) { } } +func TestVerifyPromRealTestCasesSuccessOTLP(t *testing.T) { + parser := expfmt.NewTextParser(model.UTF8Validation) + // Taken from a real run of the quickstart with OTLP exporters + actual, err := parser.TextToMetricFamilies(strings.NewReader(` + # HELP otelcol_exporter_sent_log_records Number of log record successfully sent to destination. + # TYPE otelcol_exporter_sent_log_records counter + 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 + # HELP otelcol_exporter_sent_metric_points Number of metric points successfully sent to destination. + # TYPE otelcol_exporter_sent_metric_points counter + 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 + # HELP otelcol_exporter_sent_spans Number of spans successfully sent to destination. + # TYPE otelcol_exporter_sent_spans counter + otelcol_exporter_sent_spans{exporter="otlphttp",service_instance_id="cc2396b4-e313-4c5a-8c35-0cb221a02fa8",service_name="otelcol-contrib",service_version="0.155.0"} 499 + `)) + require.NoError(t, err) + + for _, tc := range testCases { + verifyPromMetric(t, actual, tc) + } +} + func TestVerifyPromRealTestCasesFails(t *testing.T) { parser := expfmt.NewTextParser(model.UTF8Validation) // Taken from a real run of the quickstart