Skip to content

Commit

Permalink
[chore] Reduce code duplication in the metrics collection test helpers (
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored Oct 25, 2024
1 parent 5123302 commit 1e203cd
Show file tree
Hide file tree
Showing 22 changed files with 401 additions and 376 deletions.
32 changes: 18 additions & 14 deletions tests/exporters/signalfx/signalfx_translation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ import (
)

func TestSignalFxExporterTranslatesOTelCPUMetrics(t *testing.T) {
testutils.CheckGoldenFile(t, "cpu_translations_config.yaml", "cpu_translations_expected.yaml",
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreMetricAttributeValue("host.name"),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreSubsequentDataPoints(),
testutils.RunMetricsCollectionTest(t, "cpu_translations_config.yaml", "cpu_translations_expected.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreMetricAttributeValue("host.name"),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreSubsequentDataPoints(),
),
)
}

func TestSignalFxExporterTranslatesOTelMemoryMetrics(t *testing.T) {
testutils.CheckGoldenFile(t, "memory_translations_config.yaml", "memory_translations_expected.yaml",
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreMetricAttributeValue("host.name"),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreSubsequentDataPoints(),
testutils.RunMetricsCollectionTest(t, "memory_translations_config.yaml", "memory_translations_expected.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreMetricAttributeValue("host.name"),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreSubsequentDataPoints(),
),
)
}
72 changes: 39 additions & 33 deletions tests/general/envvar_expansion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,53 @@ import (
)

func TestExpandedDollarSignsViaStandardEnvVar(t *testing.T) {
testutils.CheckGoldenFileWithCollectorOptions(t, "envvar_labels.yaml", "envvar_labels_expected.yaml", func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(map[string]string{"AN_ENVVAR": "an-envvar-value"})
},
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
testutils.RunMetricsCollectionTest(t, "envvar_labels.yaml", "envvar_labels_expected.yaml",
testutils.WithCollectorEnvVars(map[string]string{"AN_ENVVAR": "an-envvar-value"}),
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
),
)
}

func TestExpandedDollarSignsViaEnvConfigSource(t *testing.T) {
testutils.CheckGoldenFileWithCollectorOptions(t, "env_config_source_labels.yaml", "env_config_source_labels_expected.yaml", func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(map[string]string{"AN_ENVVAR": "an-envvar-value"})
},
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
testutils.RunMetricsCollectionTest(t, "env_config_source_labels.yaml", "env_config_source_labels_expected.yaml",
testutils.WithCollectorEnvVars(map[string]string{"AN_ENVVAR": "an-envvar-value"}),
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
),
)
}

func TestExpandedYamlViaEnvConfigSource(t *testing.T) {
testutils.CheckGoldenFileWithCollectorOptions(t, "yaml_from_env.yaml", "yaml_from_env_expected.yaml", func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(map[string]string{"YAML": "[{action: update, include: .*, match_type: regexp, operations: [{action: add_label, new_label: yaml-from-env, new_value: value-from-env}]}]"})
},
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
testutils.RunMetricsCollectionTest(t, "yaml_from_env.yaml", "yaml_from_env_expected.yaml",
testutils.WithCollectorEnvVars(map[string]string{
"YAML": "[{action: update, include: .*, match_type: regexp, operations: [{action: add_label, " +
"new_label: yaml-from-env, new_value: value-from-env}]}]",
}),
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
),
)
}

Expand Down
26 changes: 14 additions & 12 deletions tests/receivers/apachespark/apachespark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ import (
const sparkPort = "4040"

func TestApacheSparkIntegration(t *testing.T) {
testutils.CheckGoldenFile(t, "all_metrics_config.yaml", "all_expected_metrics.yaml",
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreResourceAttributeValue("spark.application.id"),
pmetrictest.IgnoreResourceAttributeValue("spark.application.name"),
pmetrictest.IgnoreMetricAttributeValue("active", "spark.stage.status"),
pmetrictest.IgnoreMetricAttributeValue("complete", "spark.stage.status"),
pmetrictest.IgnoreMetricAttributeValue("failed", "spark.stage.status"),
pmetrictest.IgnoreMetricAttributeValue("pending", "spark.stage.status"),
pmetrictest.IgnoreMetricDataPointsOrder(),
testutils.RunMetricsCollectionTest(t, "all_metrics_config.yaml", "all_expected_metrics.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreResourceAttributeValue("spark.application.id"),
pmetrictest.IgnoreResourceAttributeValue("spark.application.name"),
pmetrictest.IgnoreMetricAttributeValue("active", "spark.stage.status"),
pmetrictest.IgnoreMetricAttributeValue("complete", "spark.stage.status"),
pmetrictest.IgnoreMetricAttributeValue("failed", "spark.stage.status"),
pmetrictest.IgnoreMetricAttributeValue("pending", "spark.stage.status"),
pmetrictest.IgnoreMetricDataPointsOrder(),
),
)
}
22 changes: 12 additions & 10 deletions tests/receivers/elasticsearch/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ import (
)

func TestElasticsearchIntegration(t *testing.T) {
testutils.CheckGoldenFile(t, "all_metrics_config.yaml", "all_expected_metrics.yaml",
pmetrictest.IgnoreResourceAttributeValue("elasticsearch.node.name"),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
testutils.RunMetricsCollectionTest(t, "all_metrics_config.yaml", "all_expected_metrics.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreResourceAttributeValue("elasticsearch.node.name"),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
),
)
}
20 changes: 11 additions & 9 deletions tests/receivers/haproxy/haproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ import (
)

func TestHAProxyIntegration(t *testing.T) {
testutils.CheckGoldenFile(t, "all_metrics_config.yaml", "all_expected.yaml",
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
testutils.RunMetricsCollectionTest(t, "all_metrics_config.yaml", "all_expected.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
),
)
}
22 changes: 12 additions & 10 deletions tests/receivers/jmxreceiver/jmxreceiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ import (
)

func TestJMXReceiverProvidesAllJVMMetrics(t *testing.T) {
testutils.CheckGoldenFile(t, "all_metrics_config.yaml", "jmx_expected.yaml",
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceAttributeValue("telemetry.sdk.version"),
testutils.RunMetricsCollectionTest(t, "all_metrics_config.yaml", "jmx_expected.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceAttributeValue("telemetry.sdk.version"),
),
)
}
28 changes: 15 additions & 13 deletions tests/receivers/kong/kong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ import (
)

func TestKongMetrics(t *testing.T) {
testutils.CheckGoldenFile(t, "kong_metrics_config.yaml", "kong_metrics_expected.yaml",
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricAttributeValue("node_id"),
pmetrictest.IgnoreMetricAttributeValue("pid"),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreSubsequentDataPoints(),
pmetrictest.IgnoreSummaryDataPointValueAtQuantileSliceOrder(),
testutils.RunMetricsCollectionTest(t, "kong_metrics_config.yaml", "kong_metrics_expected.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricAttributeValue("node_id"),
pmetrictest.IgnoreMetricAttributeValue("pid"),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreSubsequentDataPoints(),
pmetrictest.IgnoreSummaryDataPointValueAtQuantileSliceOrder(),
),
)
}
20 changes: 11 additions & 9 deletions tests/receivers/lightprometheus/internal_prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ import (
)

func TestHttpdBasicAuth(t *testing.T) {
testutils.CheckGoldenFile(t, "httpd_basic_auth.yaml", "httpd_basic_auth_expected.yaml",
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
testutils.RunMetricsCollectionTest(t, "httpd_basic_auth.yaml", "httpd_basic_auth_expected.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
),
)
}
20 changes: 11 additions & 9 deletions tests/receivers/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ import (
// The reported telemetry may need to be updated (resource metric file changes),
// They can detect breaking changes or bugs that may have been missed upstream.
func TestMysqlIntegration(t *testing.T) {
testutils.CheckGoldenFile(t, "all_metrics_config.yaml", "all_expected.yaml",
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
testutils.RunMetricsCollectionTest(t, "all_metrics_config.yaml", "all_expected.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
),
)
}
20 changes: 11 additions & 9 deletions tests/receivers/nginx/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ import (
)

func TestNginxIntegration(t *testing.T) {
testutils.CheckGoldenFile(t, "all_metrics_config.yaml", "all_expected_metrics.yaml",
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
testutils.RunMetricsCollectionTest(t, "all_metrics_config.yaml", "all_expected_metrics.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
),
)
}
21 changes: 12 additions & 9 deletions tests/receivers/oracledb/oracledb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ import (
// This test ensures the collector can connect to an Oracle DB, and properly get metrics. It's not intended to
// test the receiver itself.
func TestOracleDBIntegration(t *testing.T) {
testutils.CheckGoldenFile(t, "all_metrics_config.yaml", "all_expected.yaml",
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreMetricValues())
testutils.RunMetricsCollectionTest(t, "all_metrics_config.yaml", "all_expected.yaml",
testutils.WithCompareMetricsOptions(
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreMetricValues(),
),
)
}
Loading

0 comments on commit 1e203cd

Please sign in to comment.