Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions quickstarttest/testcases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Comment thread
psx95 marked this conversation as resolved.
{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
Expand Down Expand Up @@ -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))
Comment thread
psx95 marked this conversation as resolved.
}
29 changes: 25 additions & 4 deletions quickstarttest/testcases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down Expand Up @@ -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
Expand Down
Loading