From f8638674abadcd479e0bd8f2b808702e1536205f Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Wed, 8 Jun 2022 12:33:39 -0400 Subject: [PATCH] Add test where resources are out of order --- internal/scrapertest/compare_test.go | 19 + .../actual.json | 626 ++++++++++++++++++ .../expected.json | 626 ++++++++++++++++++ 3 files changed, 1271 insertions(+) create mode 100644 internal/scrapertest/testdata/ignore-one-resource-attribute-unordered/actual.json create mode 100644 internal/scrapertest/testdata/ignore-one-resource-attribute-unordered/expected.json diff --git a/internal/scrapertest/compare_test.go b/internal/scrapertest/compare_test.go index dbf5aac2f4d0..e7cbc5898916 100644 --- a/internal/scrapertest/compare_test.go +++ b/internal/scrapertest/compare_test.go @@ -422,6 +422,25 @@ func TestCompareMetrics(t *testing.T) { reason: "The unpredictable resource attribute was ignored on each resource that carried it, but the predictable attributes were preserved.", }, }, + { + name: "ignore-one-resource-attribute-unordered", + compareOptions: []CompareOption{ + IgnoreResourceAttributeValue("node_id"), + }, + withoutOptions: expectation{ + err: multierr.Combine( + errors.New("missing expected resource with attributes: map[namespace:test node_id:hasfewermetrics]"), + errors.New("missing expected resource with attributes: map[namespace:test node_id:hasmoremetrics]"), + errors.New("extra resource with attributes: map[namespace:test node_id:hasmoremetrics-actual]"), + errors.New("extra resource with attributes: map[namespace:test node_id:hasfewermetrics-actual]"), + ), + reason: "An unpredictable resource attribute will cause failures if not ignored.", + }, + withOptions: expectation{ + err: nil, + reason: "The unpredictable resource attribute was ignored on each resource that carried it, but the predictable attributes were preserved.", + }, + }, { name: "ignore-each-attribute-value", compareOptions: []CompareOption{ diff --git a/internal/scrapertest/testdata/ignore-one-resource-attribute-unordered/actual.json b/internal/scrapertest/testdata/ignore-one-resource-attribute-unordered/actual.json new file mode 100644 index 000000000000..4ff6f20dc0a1 --- /dev/null +++ b/internal/scrapertest/testdata/ignore-one-resource-attribute-unordered/actual.json @@ -0,0 +1,626 @@ +{ + "resourceMetrics": [ + { + "resource": { + "attributes": [ + { + "key": "namespace", + "value": { + "stringValue": "test" + } + }, + { + "key": "node_id", + "value": { + "stringValue": "hasmoremetrics-actual" + } + } + ] + }, + "instrumentationLibraryMetrics": [ + { + "instrumentationLibrary": { + "name": "otelcol/aerospikereceiver" + }, + "metrics": [ + { + "name": "aerospike.namespace.disk.available", + "description": "Minimum percentage of contiguous disk space free to the namespace across all devices", + "unit": "%", + "gauge": { + "dataPoints": [ + { + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "98" + } + ] + } + }, + { + "name": "aerospike.namespace.memory.free", + "description": "Percentage of the namespace's memory which is still free", + "unit": "%", + "gauge": { + "dataPoints": [ + { + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "95" + } + ] + } + }, + { + "name": "aerospike.namespace.memory.usage", + "description": "Memory currently used by each component of the namespace", + "unit": "By", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "component", + "value": { + "stringValue": "data" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "8513765" + }, + { + "attributes": [ + { + "key": "component", + "value": { + "stringValue": "index" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "41913920" + }, + { + "attributes": [ + { + "key": "component", + "value": { + "stringValue": "sindex" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "component", + "value": { + "stringValue": "set_index" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "aerospike.namespace.scan.count", + "description": "Number of scan operations performed on the namespace", + "unit": "{scans}", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "namespace", + "value": { + "stringValue": "test" + } + }, + { + "key": "node_id", + "value": { + "stringValue": "hasfewermetrics-actual" + } + } + ] + }, + "instrumentationLibraryMetrics": [ + { + "instrumentationLibrary": { + "name": "otelcol/aerospikereceiver" + }, + "metrics": [ + { + "name": "aerospike.namespace.scan.count", + "description": "Number of scan operations performed on the namespace", + "unit": "{scans}", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/internal/scrapertest/testdata/ignore-one-resource-attribute-unordered/expected.json b/internal/scrapertest/testdata/ignore-one-resource-attribute-unordered/expected.json new file mode 100644 index 000000000000..60edb3689d06 --- /dev/null +++ b/internal/scrapertest/testdata/ignore-one-resource-attribute-unordered/expected.json @@ -0,0 +1,626 @@ +{ + "resourceMetrics": [ + { + "resource": { + "attributes": [ + { + "key": "namespace", + "value": { + "stringValue": "test" + } + }, + { + "key": "node_id", + "value": { + "stringValue": "hasfewermetrics" + } + } + ] + }, + "instrumentationLibraryMetrics": [ + { + "instrumentationLibrary": { + "name": "otelcol/aerospikereceiver" + }, + "metrics": [ + { + "name": "aerospike.namespace.scan.count", + "description": "Number of scan operations performed on the namespace", + "unit": "{scans}", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "namespace", + "value": { + "stringValue": "test" + } + }, + { + "key": "node_id", + "value": { + "stringValue": "hasmoremetrics" + } + } + ] + }, + "instrumentationLibraryMetrics": [ + { + "instrumentationLibrary": { + "name": "otelcol/aerospikereceiver" + }, + "metrics": [ + { + "name": "aerospike.namespace.disk.available", + "description": "Minimum percentage of contiguous disk space free to the namespace across all devices", + "unit": "%", + "gauge": { + "dataPoints": [ + { + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "98" + } + ] + } + }, + { + "name": "aerospike.namespace.memory.free", + "description": "Percentage of the namespace's memory which is still free", + "unit": "%", + "gauge": { + "dataPoints": [ + { + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "95" + } + ] + } + }, + { + "name": "aerospike.namespace.memory.usage", + "description": "Memory currently used by each component of the namespace", + "unit": "By", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "component", + "value": { + "stringValue": "data" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "8513765" + }, + { + "attributes": [ + { + "key": "component", + "value": { + "stringValue": "index" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "41913920" + }, + { + "attributes": [ + { + "key": "component", + "value": { + "stringValue": "sindex" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "component", + "value": { + "stringValue": "set_index" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE" + } + }, + { + "name": "aerospike.namespace.scan.count", + "description": "Number of scan operations performed on the namespace", + "unit": "{scans}", + "sum": { + "dataPoints": [ + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "aggr" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "basic" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "ops_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "abort" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "complete" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + }, + { + "attributes": [ + { + "key": "type", + "value": { + "stringValue": "udf_bg" + } + }, + { + "key": "result", + "value": { + "stringValue": "error" + } + } + ], + "startTimeUnixNano": "1653329630290831862", + "timeUnixNano": "1653329645321022166", + "asInt": "0" + } + ], + "aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE", + "isMonotonic": true + } + } + ] + } + ] + } + ] +} \ No newline at end of file