diff --git a/exporter/collector/integrationtest/metrics_test.go b/exporter/collector/integrationtest/metrics_test.go index ff767626f..b8b1bbd2e 100644 --- a/exporter/collector/integrationtest/metrics_test.go +++ b/exporter/collector/integrationtest/metrics_test.go @@ -63,6 +63,12 @@ func TestCollectorMetrics(t *testing.T) { } require.NoError(t, testServerExporter.Shutdown(ctx)) + if !test.ExpectRetries { + require.Zero(t, testServer.RetryCount, "Server returned >0 retries when not expected") + } else { + require.NotZero(t, testServer.RetryCount, "Server returned 0 retries when expected >0") + } + expectFixture := test.LoadMetricFixture( t, test.ExpectFixturePath, diff --git a/exporter/collector/integrationtest/testcases/testcase.go b/exporter/collector/integrationtest/testcases/testcase.go index deb427797..73697b4f8 100644 --- a/exporter/collector/integrationtest/testcases/testcase.go +++ b/exporter/collector/integrationtest/testcases/testcase.go @@ -78,6 +78,8 @@ type TestCase struct { SkipForSDK bool // ExpectErr sets whether the test is expected to fail ExpectErr bool + // ExpectRetries sets whether the test expects the server to report multiple attempts + ExpectRetries bool } func (tc *TestCase) LoadOTLPTracesInput( diff --git a/exporter/collector/integrationtest/testcases/testcases_metrics.go b/exporter/collector/integrationtest/testcases/testcases_metrics.go index 233c35dfd..1612720c3 100644 --- a/exporter/collector/integrationtest/testcases/testcases_metrics.go +++ b/exporter/collector/integrationtest/testcases/testcases_metrics.go @@ -252,5 +252,29 @@ var MetricsTestCases = []TestCase{ }, SkipForSDK: true, }, + { + Name: "Write ahead log enabled, basic Counter with unavailable return code", + OTLPInputFixturePath: "testdata/fixtures/metrics/basic_counter_metrics.json", + ExpectFixturePath: "testdata/fixtures/metrics/basic_counter_metrics_wal_unavailable_expect.json", + ConfigureCollector: func(cfg *collector.Config) { + cfg.ProjectID = "unavailableproject" + cfg.MetricConfig.WALConfig.Enabled = true + cfg.MetricConfig.WALConfig.Directory, _ = os.MkdirTemp("", "test-wal-") + }, + SkipForSDK: true, + ExpectRetries: true, + }, + { + Name: "Write ahead log enabled, basic Counter with deadline_exceeded return code", + OTLPInputFixturePath: "testdata/fixtures/metrics/basic_counter_metrics.json", + ExpectFixturePath: "testdata/fixtures/metrics/basic_counter_metrics_wal_deadline_expect.json", + ConfigureCollector: func(cfg *collector.Config) { + cfg.ProjectID = "deadline_exceededproject" + cfg.MetricConfig.WALConfig.Enabled = true + cfg.MetricConfig.WALConfig.Directory, _ = os.MkdirTemp("", "test-wal-") + }, + SkipForSDK: true, + ExpectRetries: true, + }, // TODO: Add integration tests for workload.googleapis.com metrics from the ops agent } diff --git a/exporter/collector/integrationtest/testdata/fixtures/metrics/basic_counter_metrics_wal_deadline_expect.json b/exporter/collector/integrationtest/testdata/fixtures/metrics/basic_counter_metrics_wal_deadline_expect.json new file mode 100644 index 000000000..af635c4eb --- /dev/null +++ b/exporter/collector/integrationtest/testdata/fixtures/metrics/basic_counter_metrics_wal_deadline_expect.json @@ -0,0 +1,715 @@ +{ + "createTimeSeriesRequests": [ + { + "name": "projects/deadline_exceededproject", + "timeSeries": [ + { + "metric": { + "type": "workload.googleapis.com/testcounter", + "labels": { + "foo": "bar" + } + }, + "resource": { + "type": "generic_node", + "labels": { + "location": "global", + "namespace": "", + "node_id": "" + } + }, + "metricKind": "CUMULATIVE", + "valueType": "INT64", + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "int64Value": "253" + } + } + ], + "unit": "1" + } + ] + } + ], + "createMetricDescriptorRequests": [ + { + "name": "projects/deadline_exceededproject", + "metricDescriptor": { + "name": "testcounter", + "type": "workload.googleapis.com/testcounter", + "labels": [ + { + "key": "foo" + } + ], + "metricKind": "CUMULATIVE", + "valueType": "INT64", + "unit": "1", + "description": "This is a test counter", + "displayName": "testcounter" + } + } + ], + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "name": "projects/myproject", + "timeSeries": [ + { + "metric": { + "type": "custom.googleapis.com/opencensus/googlecloudmonitoring/point_count", + "labels": { + "status": "DEADLINE_EXCEEDED" + } + }, + "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/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": "0" + } + } + ] + }, + { + "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": "DEADLINE_EXCEEDED" + } + }, + "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" + } + } + ] + } +} diff --git a/exporter/collector/integrationtest/testdata/fixtures/metrics/basic_counter_metrics_wal_unavailable_expect.json b/exporter/collector/integrationtest/testdata/fixtures/metrics/basic_counter_metrics_wal_unavailable_expect.json new file mode 100644 index 000000000..99eeb17b6 --- /dev/null +++ b/exporter/collector/integrationtest/testdata/fixtures/metrics/basic_counter_metrics_wal_unavailable_expect.json @@ -0,0 +1,715 @@ +{ + "createTimeSeriesRequests": [ + { + "name": "projects/unavailableproject", + "timeSeries": [ + { + "metric": { + "type": "workload.googleapis.com/testcounter", + "labels": { + "foo": "bar" + } + }, + "resource": { + "type": "generic_node", + "labels": { + "location": "global", + "namespace": "", + "node_id": "" + } + }, + "metricKind": "CUMULATIVE", + "valueType": "INT64", + "points": [ + { + "interval": { + "endTime": "1970-01-01T00:00:00Z", + "startTime": "1970-01-01T00:00:00Z" + }, + "value": { + "int64Value": "253" + } + } + ], + "unit": "1" + } + ] + } + ], + "createMetricDescriptorRequests": [ + { + "name": "projects/unavailableproject", + "metricDescriptor": { + "name": "testcounter", + "type": "workload.googleapis.com/testcounter", + "labels": [ + { + "key": "foo" + } + ], + "metricKind": "CUMULATIVE", + "valueType": "INT64", + "unit": "1", + "description": "This is a test counter", + "displayName": "testcounter" + } + } + ], + "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": "0" + } + } + ] + }, + { + "metric": { + "type": "custom.googleapis.com/opencensus/googlecloudmonitoring/point_count", + "labels": { + "status": "UNAVAILABLE" + } + }, + "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": "UNAVAILABLE" + } + }, + "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" + } + } + ] + } +} diff --git a/internal/cloudmock/metrics.go b/internal/cloudmock/metrics.go index c6832a061..78df75acd 100644 --- a/internal/cloudmock/metrics.go +++ b/internal/cloudmock/metrics.go @@ -36,6 +36,7 @@ type MetricsTestServer struct { createTimeSeriesReqs []*monitoringpb.CreateTimeSeriesRequest createServiceTimeSeriesReqs []*monitoringpb.CreateTimeSeriesRequest mu sync.Mutex + RetryCount int } func (m *MetricsTestServer) Shutdown() { @@ -104,10 +105,16 @@ func (f *fakeMetricServiceServer) CreateTimeSeries( var code codes.Code if strings.Contains(req.Name, "notfound") { code = codes.NotFound + } else if strings.Contains(req.Name, "unavailable") { + f.metricsTestServer.RetryCount++ + code = codes.Unavailable + } else if strings.Contains(req.Name, "deadline_exceeded") { + f.metricsTestServer.RetryCount++ + code = codes.DeadlineExceeded } statusResp := status.New(code, "FORCED_TEST_ERROR") - if code == codes.NotFound { + if code == codes.NotFound || code == codes.Unavailable || code == codes.DeadlineExceeded { statusResp, _ = statusResp.WithDetails(&monitoringpb.CreateTimeSeriesSummary{ TotalPointCount: int32(len(req.TimeSeries)), SuccessPointCount: 0,