From 777a342588dc9feca96c113bf185a9a6d01756b2 Mon Sep 17 00:00:00 2001 From: Pranav Sharma Date: Wed, 21 Jun 2023 23:32:24 +0000 Subject: [PATCH] Add fixture based test for bool metrics --- .../testcases/testcases_metrics.go | 6 + .../metrics/boolean_gauge_metrics.json | 65 ++ .../metrics/boolean_gauge_metrics_expect.json | 695 ++++++++++++++++++ 3 files changed, 766 insertions(+) create mode 100644 exporter/collector/integrationtest/testdata/fixtures/metrics/boolean_gauge_metrics.json create mode 100644 exporter/collector/integrationtest/testdata/fixtures/metrics/boolean_gauge_metrics_expect.json diff --git a/exporter/collector/integrationtest/testcases/testcases_metrics.go b/exporter/collector/integrationtest/testcases/testcases_metrics.go index f55501393..d2456ac6c 100644 --- a/exporter/collector/integrationtest/testcases/testcases_metrics.go +++ b/exporter/collector/integrationtest/testcases/testcases_metrics.go @@ -69,6 +69,12 @@ var MetricsTestCases = []TestCase{ cfg.MetricConfig.Prefix = "workload.googleapis.com" }, }, + { + Name: "Boolean valued gauge metrics represented through int gauges", + OTLPInputFixturePath: "testdata/fixtures/metrics/boolean_gauge_metrics.json", + ExpectFixturePath: "testdata/fixtures/metrics/boolean_gauge_metrics_expect.json", + SkipForSDK: true, // Boolean valued metrics not implemented in SDK + }, { Name: "Delta Counter", OTLPInputFixturePath: "testdata/fixtures/metrics/delta_counter_metrics.json", diff --git a/exporter/collector/integrationtest/testdata/fixtures/metrics/boolean_gauge_metrics.json b/exporter/collector/integrationtest/testdata/fixtures/metrics/boolean_gauge_metrics.json new file mode 100644 index 000000000..83774b61b --- /dev/null +++ b/exporter/collector/integrationtest/testdata/fixtures/metrics/boolean_gauge_metrics.json @@ -0,0 +1,65 @@ +{ + "resourceMetrics": [ + { + "resource": { + "attributes": [ + { + "key": "service.name", + "value": { + "stringValue": "unknown_service:sample" + } + }, + { + "key": "telemetry.sdk.language", + "value": { + "stringValue": "go" + } + }, + { + "key": "telemetry.sdk.name", + "value": { + "stringValue": "opentelemetry" + } + }, + { + "key": "telemetry.sdk.version", + "value": { + "stringValue": "1.16.0" + } + } + ] + }, + "scopeMetrics": [ + { + "scope": { + "name": "github.com/GoogleCloudPlatform/opentelemetry-operations-go/example/collector/metric" + }, + "metrics": [ + { + "name": "observer-boolean-collector", + "unit": "{gcp.BOOL}", + "gauge": { + "dataPoints": [ + { + "attributes": [ + { + "key": "key", + "value": { + "stringValue": "value" + } + } + ], + "startTimeUnixNano": "11651379494838206464", + "timeUnixNano": "1687377293673694987", + "asInt": "0" + } + ] + } + } + ] + } + ], + "schemaUrl": "https://opentelemetry.io/schemas/1.17.0" + } + ] +} diff --git a/exporter/collector/integrationtest/testdata/fixtures/metrics/boolean_gauge_metrics_expect.json b/exporter/collector/integrationtest/testdata/fixtures/metrics/boolean_gauge_metrics_expect.json new file mode 100644 index 000000000..3352d397d --- /dev/null +++ b/exporter/collector/integrationtest/testdata/fixtures/metrics/boolean_gauge_metrics_expect.json @@ -0,0 +1,695 @@ +{ + "createTimeSeriesRequests": [ + { + "name": "projects/fakeprojectid", + "timeSeries": [ + { + "metric": { + "type": "workload.googleapis.com/observer-boolean-collector", + "labels": { + "key": "value", + "service_name": "unknown_service:sample" + } + }, + "resource": { + "type": "generic_node", + "labels": { + "location": "global", + "namespace": "", + "node_id": "" + } + }, + "metricKind": "GAUGE", + "valueType": "BOOL", + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z" + }, + "value": { + "boolValue": false + } + } + ], + "unit": "{gcp.BOOL}" + } + ] + } + ], + "createMetricDescriptorRequests": [ + { + "name": "projects/fakeprojectid", + "metricDescriptor": { + "name": "observer-boolean-collector", + "type": "workload.googleapis.com/observer-boolean-collector", + "labels": [ + { + "key": "key" + }, + { + "key": "service_name" + } + ], + "metricKind": "GAUGE", + "valueType": "BOOL", + "unit": "{gcp.BOOL}", + "displayName": "observer-boolean-collector" + } + } + ], + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "name": "projects/myproject", + "timeSeries": [ + { + "metric": { + "type": "custom.googleapis.com/opencensus/googlecloudmonitoring/point_count", + "labels": { + "status": "OK" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "int64Value": "1" + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/grpc.io/client/completed_rpcs", + "labels": { + "grpc_client_method": "google.monitoring.v3.MetricService/CreateMetricDescriptor", + "grpc_client_status": "OK" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "int64Value": "1" + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/grpc.io/client/completed_rpcs", + "labels": { + "grpc_client_method": "google.monitoring.v3.MetricService/CreateTimeSeries", + "grpc_client_status": "OK" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "int64Value": "1" + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/grpc.io/client/received_bytes_per_rpc", + "labels": { + "grpc_client_method": "google.monitoring.v3.MetricService/CreateMetricDescriptor" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "distributionValue": { + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 0, + 1024, + 2048, + 4096, + 16384, + 65536, + 262144, + 1048576, + 4194304, + 16777216, + 67108864, + 268435456, + 1073741824, + 4294967296 + ] + } + }, + "bucketCounts": [ + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0" + ] + } + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/grpc.io/client/received_bytes_per_rpc", + "labels": { + "grpc_client_method": "google.monitoring.v3.MetricService/CreateTimeSeries" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "distributionValue": { + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 0, + 1024, + 2048, + 4096, + 16384, + 65536, + 262144, + 1048576, + 4194304, + 16777216, + 67108864, + 268435456, + 1073741824, + 4294967296 + ] + } + }, + "bucketCounts": [ + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0" + ] + } + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/grpc.io/client/roundtrip_latency", + "labels": { + "grpc_client_method": "google.monitoring.v3.MetricService/CreateMetricDescriptor" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "distributionValue": { + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 0, + 0.01, + 0.05, + 0.1, + 0.3, + 0.6, + 0.8, + 1, + 2, + 3, + 4, + 5, + 6, + 8, + 10, + 13, + 16, + 20, + 25, + 30, + 40, + 50, + 65, + 80, + 100, + 130, + 160, + 200, + 250, + 300, + 400, + 500, + 650, + 800, + 1000, + 2000, + 5000, + 10000, + 20000, + 50000, + 100000 + ] + } + }, + "bucketCounts": [ + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0" + ] + } + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/grpc.io/client/roundtrip_latency", + "labels": { + "grpc_client_method": "google.monitoring.v3.MetricService/CreateTimeSeries" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "distributionValue": { + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 0, + 0.01, + 0.05, + 0.1, + 0.3, + 0.6, + 0.8, + 1, + 2, + 3, + 4, + 5, + 6, + 8, + 10, + 13, + 16, + 20, + 25, + 30, + 40, + 50, + 65, + 80, + 100, + 130, + 160, + 200, + 250, + 300, + 400, + 500, + 650, + 800, + 1000, + 2000, + 5000, + 10000, + 20000, + 50000, + 100000 + ] + } + }, + "bucketCounts": [ + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0" + ] + } + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/grpc.io/client/sent_bytes_per_rpc", + "labels": { + "grpc_client_method": "google.monitoring.v3.MetricService/CreateMetricDescriptor" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "distributionValue": { + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 0, + 1024, + 2048, + 4096, + 16384, + 65536, + 262144, + 1048576, + 4194304, + 16777216, + 67108864, + 268435456, + 1073741824, + 4294967296 + ] + } + }, + "bucketCounts": [ + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0" + ] + } + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/grpc.io/client/sent_bytes_per_rpc", + "labels": { + "grpc_client_method": "google.monitoring.v3.MetricService/CreateTimeSeries" + } + }, + "resource": { + "type": "global" + }, + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "distributionValue": { + "bucketOptions": { + "explicitBuckets": { + "bounds": [ + 0, + 1024, + 2048, + 4096, + 16384, + 65536, + 262144, + 1048576, + 4194304, + 16777216, + 67108864, + 268435456, + 1073741824, + 4294967296 + ] + } + }, + "bucketCounts": [ + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0" + ] + } + } + } + ] + } + ] + } + ], + "createMetricDescriptorRequests": [ + { + "name": "projects/myproject", + "metricDescriptor": { + "name": "projects/myproject/metricDescriptors/custom.googleapis.com/opencensus/googlecloudmonitoring/point_count", + "type": "custom.googleapis.com/opencensus/googlecloudmonitoring/point_count", + "labels": [ + { + "key": "status" + } + ], + "metricKind": "CUMULATIVE", + "valueType": "INT64", + "unit": "1", + "description": "Count of metric points written to Cloud Monitoring.", + "displayName": "OpenCensus/googlecloudmonitoring/point_count" + } + }, + { + "name": "projects/myproject", + "metricDescriptor": { + "name": "projects/myproject/metricDescriptors/custom.googleapis.com/opencensus/grpc.io/client/completed_rpcs", + "type": "custom.googleapis.com/opencensus/grpc.io/client/completed_rpcs", + "labels": [ + { + "key": "grpc_client_method" + }, + { + "key": "grpc_client_status" + } + ], + "metricKind": "CUMULATIVE", + "valueType": "INT64", + "unit": "1", + "description": "Count of RPCs by method and status.", + "displayName": "OpenCensus/grpc.io/client/completed_rpcs" + } + }, + { + "name": "projects/myproject", + "metricDescriptor": { + "name": "projects/myproject/metricDescriptors/custom.googleapis.com/opencensus/grpc.io/client/received_bytes_per_rpc", + "type": "custom.googleapis.com/opencensus/grpc.io/client/received_bytes_per_rpc", + "labels": [ + { + "key": "grpc_client_method" + } + ], + "metricKind": "CUMULATIVE", + "valueType": "DISTRIBUTION", + "unit": "By", + "description": "Distribution of bytes received per RPC, by method.", + "displayName": "OpenCensus/grpc.io/client/received_bytes_per_rpc" + } + }, + { + "name": "projects/myproject", + "metricDescriptor": { + "name": "projects/myproject/metricDescriptors/custom.googleapis.com/opencensus/grpc.io/client/roundtrip_latency", + "type": "custom.googleapis.com/opencensus/grpc.io/client/roundtrip_latency", + "labels": [ + { + "key": "grpc_client_method" + } + ], + "metricKind": "CUMULATIVE", + "valueType": "DISTRIBUTION", + "unit": "ms", + "description": "Distribution of round-trip latency, by method.", + "displayName": "OpenCensus/grpc.io/client/roundtrip_latency" + } + }, + { + "name": "projects/myproject", + "metricDescriptor": { + "name": "projects/myproject/metricDescriptors/custom.googleapis.com/opencensus/grpc.io/client/sent_bytes_per_rpc", + "type": "custom.googleapis.com/opencensus/grpc.io/client/sent_bytes_per_rpc", + "labels": [ + { + "key": "grpc_client_method" + } + ], + "metricKind": "CUMULATIVE", + "valueType": "DISTRIBUTION", + "unit": "By", + "description": "Distribution of bytes sent per RPC, by method.", + "displayName": "OpenCensus/grpc.io/client/sent_bytes_per_rpc" + } + } + ] + } +}