From d3c18d01256fc5aa1db651deb2516b11330d5c3a Mon Sep 17 00:00:00 2001 From: Aaron Abbott Date: Thu, 20 Jan 2022 02:31:22 +0000 Subject: [PATCH] Use OC stackdriver exporter to capture self observability metrics as GCM protos --- .../cmd/recordfixtures/main.go | 4 +- .../{ => config}/config_test.go | 4 +- .../internal/integrationtest/fixtures.pb.go | 101 ++++++++-------- .../internal/integrationtest/fixtures.proto | 10 +- .../collector/internal/integrationtest/go.mod | 2 + .../integrationtest/inmemoryocexporter.go | 111 +++++++++++------- .../internal/integrationtest/metrics_test.go | 5 +- .../internal/integrationtest/testcase.go | 11 +- .../basic_counter_metrics_expect.json | 54 +++++++-- ...ate_service_timeseries_metrics_expect.json | 54 +++++++-- .../delta_counter_metrics_expect.json | 54 +++++++-- .../exponential_histogram_metrics_expect.json | 54 +++++++-- ...ol_plane_metrics_agent_metrics_expect.json | 54 +++++++-- .../gke_metrics_agent_metrics_expect.json | 54 +++++++-- .../nonmonotonic_counter_metrics_expect.json | 54 +++++++-- .../ops_agent_host_metrics_expect.json | 54 +++++++-- .../ops_agent_self_metrics_expect.json | 54 +++++++-- .../fixtures/summary_metrics_expect.json | 54 +++++++-- .../unknown_domain_metrics_expect.json | 54 +++++++-- ...kloadgoogleapis_prefix_metrics_expect.json | 54 +++++++-- 20 files changed, 690 insertions(+), 206 deletions(-) rename exporter/collector/internal/integrationtest/{ => config}/config_test.go (96%) diff --git a/exporter/collector/internal/integrationtest/cmd/recordfixtures/main.go b/exporter/collector/internal/integrationtest/cmd/recordfixtures/main.go index 1f6fee014..43f4a6f56 100644 --- a/exporter/collector/internal/integrationtest/cmd/recordfixtures/main.go +++ b/exporter/collector/internal/integrationtest/cmd/recordfixtures/main.go @@ -71,11 +71,13 @@ func main() { require.NoError(t, testServerExporter.PushMetrics(ctx, metrics), "failed to export metrics to local test server") require.NoError(t, testServerExporter.Shutdown(ctx)) + selfObsMetrics, err := inMemoryOCExporter.Proto(ctx) + require.NoError(t, err) fixture := &integrationtest.MetricExpectFixture{ CreateMetricDescriptorRequests: testServer.CreateMetricDescriptorRequests(), CreateTimeSeriesRequests: testServer.CreateTimeSeriesRequests(), CreateServiceTimeSeriesRequests: testServer.CreateServiceTimeSeriesRequests(), - SelfObservabilityMetrics: inMemoryOCExporter.Proto(), + SelfObservabilityMetrics: selfObsMetrics, } test.SaveRecordedFixtures(t, fixture) }() diff --git a/exporter/collector/internal/integrationtest/config_test.go b/exporter/collector/internal/integrationtest/config/config_test.go similarity index 96% rename from exporter/collector/internal/integrationtest/config_test.go rename to exporter/collector/internal/integrationtest/config/config_test.go index b1fdaa80f..eb1a2d261 100644 --- a/exporter/collector/internal/integrationtest/config_test.go +++ b/exporter/collector/internal/integrationtest/config/config_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package integrationtest +package config import ( "path" @@ -39,7 +39,7 @@ func TestLoadConfig(t *testing.T) { factory := newFactory() factories.Exporters[typeStr] = factory - cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) + cfg, err := configtest.LoadConfigAndValidate(path.Join("..", "testdata", "config.yaml"), factories) require.NoError(t, err) require.NotNil(t, cfg) diff --git a/exporter/collector/internal/integrationtest/fixtures.pb.go b/exporter/collector/internal/integrationtest/fixtures.pb.go index 7832f356d..d94604cc0 100644 --- a/exporter/collector/internal/integrationtest/fixtures.pb.go +++ b/exporter/collector/internal/integrationtest/fixtures.pb.go @@ -43,7 +43,7 @@ type MetricExpectFixture struct { CreateTimeSeriesRequests []*v3.CreateTimeSeriesRequest `protobuf:"bytes,1,rep,name=create_time_series_requests,json=createTimeSeriesRequests,proto3" json:"create_time_series_requests,omitempty"` CreateMetricDescriptorRequests []*v3.CreateMetricDescriptorRequest `protobuf:"bytes,2,rep,name=create_metric_descriptor_requests,json=createMetricDescriptorRequests,proto3" json:"create_metric_descriptor_requests,omitempty"` CreateServiceTimeSeriesRequests []*v3.CreateTimeSeriesRequest `protobuf:"bytes,3,rep,name=create_service_time_series_requests,json=createServiceTimeSeriesRequests,proto3" json:"create_service_time_series_requests,omitempty"` - SelfObservabilityMetrics []*SelfObservabilityMetric `protobuf:"bytes,4,rep,name=self_observability_metrics,json=selfObservabilityMetrics,proto3" json:"self_observability_metrics,omitempty"` + SelfObservabilityMetrics *SelfObservabilityMetric `protobuf:"bytes,4,opt,name=self_observability_metrics,json=selfObservabilityMetrics,proto3" json:"self_observability_metrics,omitempty"` } func (x *MetricExpectFixture) Reset() { @@ -99,7 +99,7 @@ func (x *MetricExpectFixture) GetCreateServiceTimeSeriesRequests() []*v3.CreateT return nil } -func (x *MetricExpectFixture) GetSelfObservabilityMetrics() []*SelfObservabilityMetric { +func (x *MetricExpectFixture) GetSelfObservabilityMetrics() *SelfObservabilityMetric { if x != nil { return x.SelfObservabilityMetrics } @@ -111,12 +111,8 @@ type SelfObservabilityMetric struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // metric name - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // stringified value - Val string `protobuf:"bytes,2,opt,name=val,proto3" json:"val,omitempty"` - // stringified labels - Labels map[string]string `protobuf:"bytes,3,rep,name=labels,proto3" json:"labels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + CreateTimeSeriesRequests []*v3.CreateTimeSeriesRequest `protobuf:"bytes,1,rep,name=create_time_series_requests,json=createTimeSeriesRequests,proto3" json:"create_time_series_requests,omitempty"` + CreateMetricDescriptorRequests []*v3.CreateMetricDescriptorRequest `protobuf:"bytes,2,rep,name=create_metric_descriptor_requests,json=createMetricDescriptorRequests,proto3" json:"create_metric_descriptor_requests,omitempty"` } func (x *SelfObservabilityMetric) Reset() { @@ -151,23 +147,16 @@ func (*SelfObservabilityMetric) Descriptor() ([]byte, []int) { return file_fixtures_proto_rawDescGZIP(), []int{1} } -func (x *SelfObservabilityMetric) GetName() string { +func (x *SelfObservabilityMetric) GetCreateTimeSeriesRequests() []*v3.CreateTimeSeriesRequest { if x != nil { - return x.Name - } - return "" -} - -func (x *SelfObservabilityMetric) GetVal() string { - if x != nil { - return x.Val + return x.CreateTimeSeriesRequests } - return "" + return nil } -func (x *SelfObservabilityMetric) GetLabels() map[string]string { +func (x *SelfObservabilityMetric) GetCreateMetricDescriptorRequests() []*v3.CreateMetricDescriptorRequest { if x != nil { - return x.Labels + return x.CreateMetricDescriptorRequests } return nil } @@ -204,30 +193,34 @@ var file_fixtures_proto_rawDesc = []byte{ 0x65, 0x54, 0x69, 0x6d, 0x65, 0x53, 0x65, 0x72, 0x69, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x12, 0x5f, 0x0a, 0x1a, 0x73, 0x65, 0x6c, 0x66, 0x5f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x66, 0x69, 0x78, 0x74, 0x75, 0x72, + 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x66, 0x69, 0x78, 0x74, 0x75, 0x72, 0x65, 0x73, 0x2e, 0x53, 0x65, 0x6c, 0x66, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x18, 0x73, 0x65, 0x6c, 0x66, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x4d, 0x65, 0x74, - 0x72, 0x69, 0x63, 0x73, 0x22, 0xc1, 0x01, 0x0a, 0x17, 0x53, 0x65, 0x6c, 0x66, 0x4f, 0x62, 0x73, + 0x72, 0x69, 0x63, 0x73, 0x22, 0x87, 0x02, 0x0a, 0x17, 0x53, 0x65, 0x6c, 0x66, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, 0x69, 0x74, 0x79, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, - 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x12, 0x45, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, - 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x66, 0x69, 0x78, 0x74, 0x75, 0x72, 0x65, - 0x73, 0x2e, 0x53, 0x65, 0x6c, 0x66, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x62, 0x69, 0x6c, - 0x69, 0x74, 0x79, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x2e, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, - 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x1a, 0x39, 0x0a, - 0x0b, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x68, 0x5a, 0x66, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x43, 0x6c, 0x6f, - 0x75, 0x64, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x74, - 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2d, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x2d, 0x67, 0x6f, 0x2f, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2f, - 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, - 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x74, 0x65, - 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x6c, 0x0a, 0x1b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, + 0x73, 0x65, 0x72, 0x69, 0x65, 0x73, 0x5f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x6d, + 0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x33, 0x2e, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x53, 0x65, 0x72, 0x69, 0x65, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x52, 0x18, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, + 0x53, 0x65, 0x72, 0x69, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x12, 0x7e, + 0x0a, 0x21, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x5f, + 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x5f, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x33, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x6d, 0x6f, 0x6e, 0x69, 0x74, 0x6f, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x33, + 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x44, 0x65, 0x73, + 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x1e, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x44, 0x65, 0x73, 0x63, + 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x73, 0x42, 0x68, + 0x5a, 0x66, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x47, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x43, 0x6c, 0x6f, 0x75, 0x64, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, + 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x74, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x2d, 0x6f, + 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2d, 0x67, 0x6f, 0x2f, 0x65, 0x78, 0x70, + 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2f, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x74, 0x65, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -242,25 +235,25 @@ func file_fixtures_proto_rawDescGZIP() []byte { return file_fixtures_proto_rawDescData } -var file_fixtures_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_fixtures_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_fixtures_proto_goTypes = []interface{}{ (*MetricExpectFixture)(nil), // 0: fixtures.MetricExpectFixture (*SelfObservabilityMetric)(nil), // 1: fixtures.SelfObservabilityMetric - nil, // 2: fixtures.SelfObservabilityMetric.LabelsEntry - (*v3.CreateTimeSeriesRequest)(nil), // 3: google.monitoring.v3.CreateTimeSeriesRequest - (*v3.CreateMetricDescriptorRequest)(nil), // 4: google.monitoring.v3.CreateMetricDescriptorRequest + (*v3.CreateTimeSeriesRequest)(nil), // 2: google.monitoring.v3.CreateTimeSeriesRequest + (*v3.CreateMetricDescriptorRequest)(nil), // 3: google.monitoring.v3.CreateMetricDescriptorRequest } var file_fixtures_proto_depIdxs = []int32{ - 3, // 0: fixtures.MetricExpectFixture.create_time_series_requests:type_name -> google.monitoring.v3.CreateTimeSeriesRequest - 4, // 1: fixtures.MetricExpectFixture.create_metric_descriptor_requests:type_name -> google.monitoring.v3.CreateMetricDescriptorRequest - 3, // 2: fixtures.MetricExpectFixture.create_service_time_series_requests:type_name -> google.monitoring.v3.CreateTimeSeriesRequest + 2, // 0: fixtures.MetricExpectFixture.create_time_series_requests:type_name -> google.monitoring.v3.CreateTimeSeriesRequest + 3, // 1: fixtures.MetricExpectFixture.create_metric_descriptor_requests:type_name -> google.monitoring.v3.CreateMetricDescriptorRequest + 2, // 2: fixtures.MetricExpectFixture.create_service_time_series_requests:type_name -> google.monitoring.v3.CreateTimeSeriesRequest 1, // 3: fixtures.MetricExpectFixture.self_observability_metrics:type_name -> fixtures.SelfObservabilityMetric - 2, // 4: fixtures.SelfObservabilityMetric.labels:type_name -> fixtures.SelfObservabilityMetric.LabelsEntry - 5, // [5:5] is the sub-list for method output_type - 5, // [5:5] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name + 2, // 4: fixtures.SelfObservabilityMetric.create_time_series_requests:type_name -> google.monitoring.v3.CreateTimeSeriesRequest + 3, // 5: fixtures.SelfObservabilityMetric.create_metric_descriptor_requests:type_name -> google.monitoring.v3.CreateMetricDescriptorRequest + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_fixtures_proto_init() } @@ -300,7 +293,7 @@ func file_fixtures_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_fixtures_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 2, NumExtensions: 0, NumServices: 0, }, diff --git a/exporter/collector/internal/integrationtest/fixtures.proto b/exporter/collector/internal/integrationtest/fixtures.proto index 30a1f30bc..9575fb502 100644 --- a/exporter/collector/internal/integrationtest/fixtures.proto +++ b/exporter/collector/internal/integrationtest/fixtures.proto @@ -22,14 +22,10 @@ message MetricExpectFixture { repeated google.monitoring.v3.CreateTimeSeriesRequest create_time_series_requests = 1; repeated google.monitoring.v3.CreateMetricDescriptorRequest create_metric_descriptor_requests = 2; repeated google.monitoring.v3.CreateTimeSeriesRequest create_service_time_series_requests = 3; - repeated SelfObservabilityMetric self_observability_metrics = 4; + SelfObservabilityMetric self_observability_metrics = 4; } message SelfObservabilityMetric { - // metric name - string name = 1; - // stringified value - string val = 2; - // stringified labels - map labels = 3; + repeated google.monitoring.v3.CreateTimeSeriesRequest create_time_series_requests = 1; + repeated google.monitoring.v3.CreateMetricDescriptorRequest create_metric_descriptor_requests = 2; } diff --git a/exporter/collector/internal/integrationtest/go.mod b/exporter/collector/internal/integrationtest/go.mod index f2249c5a9..c0aa28594 100644 --- a/exporter/collector/internal/integrationtest/go.mod +++ b/exporter/collector/internal/integrationtest/go.mod @@ -3,6 +3,7 @@ module github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/colle go 1.16 require ( + contrib.go.opencensus.io/exporter/stackdriver v0.13.10 github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector v0.0.0-20220111155622-771af0772772 github.com/google/go-cmp v0.5.6 github.com/stretchr/testify v1.7.0 @@ -10,6 +11,7 @@ require ( go.opentelemetry.io/collector v0.40.0 go.opentelemetry.io/collector/model v0.40.0 go.uber.org/zap v1.19.1 + google.golang.org/api v0.60.0 google.golang.org/genproto v0.0.0-20211021150943-2b146023228c google.golang.org/grpc v1.42.0 google.golang.org/protobuf v1.27.1 diff --git a/exporter/collector/internal/integrationtest/inmemoryocexporter.go b/exporter/collector/internal/integrationtest/inmemoryocexporter.go index 5f3347509..59c56d27e 100644 --- a/exporter/collector/internal/integrationtest/inmemoryocexporter.go +++ b/exporter/collector/internal/integrationtest/inmemoryocexporter.go @@ -16,85 +16,108 @@ package integrationtest import ( "context" - "fmt" - "sort" "time" - "go.opencensus.io/metric/metricdata" + "contrib.go.opencensus.io/exporter/stackdriver" "go.opencensus.io/metric/metricexport" "go.opencensus.io/plugin/ocgrpc" "go.opencensus.io/stats/view" + "google.golang.org/api/option" + "google.golang.org/grpc" "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector" ) -var _ metricexport.Exporter = (*InMemoryOCExporter)(nil) - // OC stats/metrics exporter used to capture self observability metrics type InMemoryOCExporter struct { - c chan []*metricdata.Metric - reader *metricexport.Reader + testServer *MetricsTestServer + reader *metricexport.Reader + stackdriverExporter *stackdriver.Exporter } -func (i *InMemoryOCExporter) ExportMetrics(ctx context.Context, data []*metricdata.Metric) error { - i.c <- data - return nil +func getViews() []*view.View { + views := []*view.View{} + views = append(views, collector.MetricViews()...) + // TODO: enable this + // views = append(views, ocgrpc.DefaultClientViews...) + return views } -func (i *InMemoryOCExporter) Proto() []*SelfObservabilityMetric { +func (i *InMemoryOCExporter) Proto(ctx context.Context) (*SelfObservabilityMetric, error) { // Hack to flush stats, see https://tinyurl.com/5hfcxzk2 view.SetReportingPeriod(time.Minute) - i.reader.ReadAndExport(i) - var data []*metricdata.Metric + i.reader.ReadAndExport(i.stackdriverExporter) + ctx, cancel := context.WithTimeout(ctx, time.Millisecond*500) + defer cancel() + + done := make(chan struct{}, 1) + go func() { + i.stackdriverExporter.Flush() + close(done) + }() select { - case <-time.NewTimer(time.Millisecond * 100).C: - return nil - case data = <-i.c: + case <-ctx.Done(): + return nil, ctx.Err() + case <-done: } - selfObsMetrics := []*SelfObservabilityMetric{} - for _, d := range data { - for _, ts := range d.TimeSeries { - labels := make(map[string]string, len(d.Descriptor.LabelKeys)) - for i := 0; i < len(d.Descriptor.LabelKeys); i++ { - labels[d.Descriptor.LabelKeys[i].Key] = ts.LabelValues[i].Value - } - - for _, p := range ts.Points { - selfObsMetrics = append(selfObsMetrics, &SelfObservabilityMetric{ - Name: d.Descriptor.Name, - Val: fmt.Sprint(p.Value), - Labels: labels, - }) - } - } - } - sort.Slice(selfObsMetrics, func(i, j int) bool { - return selfObsMetrics[i].Name < selfObsMetrics[j].Name - }) - return selfObsMetrics + return &SelfObservabilityMetric{ + CreateTimeSeriesRequests: i.testServer.CreateTimeSeriesRequests(), + CreateMetricDescriptorRequests: i.testServer.CreateMetricDescriptorRequests(), + }, + nil } // Shutdown unregisters the global OpenCensus views to reset state for the next test func (i *InMemoryOCExporter) Shutdown(ctx context.Context) error { - view.Unregister(collector.MetricViews()...) + i.stackdriverExporter.StopMetricsExporter() + err := i.stackdriverExporter.Close() + i.testServer.Shutdown() + + view.Unregister(getViews()...) + // TODO: remove this special case view.Unregister(ocgrpc.DefaultClientViews...) - return nil + + return err } // NewInMemoryOCViewExporter creates a new in memory OC exporter for testing. Be sure to defer // a call to Shutdown(). func NewInMemoryOCViewExporter() (*InMemoryOCExporter, error) { // Reset our views in case any tests ran before this - view.Unregister(collector.MetricViews()...) - view.Register(collector.MetricViews()...) + views := getViews() + view.Unregister(views...) + view.Register(views...) + + // TODO: remove this special case view.Unregister(ocgrpc.DefaultClientViews...) - // TODO: Register ocgrpc.DefaultClientViews to test them + + testServer, err := NewMetricTestServer() + if err != nil { + return nil, err + } + go testServer.Serve() + conn, err := grpc.Dial(testServer.Endpoint, grpc.WithInsecure()) + if err != nil { + return nil, err + } + clientOpts := []option.ClientOption{option.WithGRPCConn(conn)} + + stackdriverExporter, err := stackdriver.NewExporter(stackdriver.Options{ + DefaultMonitoringLabels: &stackdriver.Labels{}, + ProjectID: "myproject", + MonitoringClientOptions: clientOpts, + TraceClientOptions: clientOpts, + }) + if err != nil { + return nil, err + } return &InMemoryOCExporter{ - c: make(chan []*metricdata.Metric, 1), - reader: metricexport.NewReader(), + testServer: testServer, + stackdriverExporter: stackdriverExporter, + reader: metricexport.NewReader(), }, nil } diff --git a/exporter/collector/internal/integrationtest/metrics_test.go b/exporter/collector/internal/integrationtest/metrics_test.go index 90c7f8dd5..abbe99f1a 100644 --- a/exporter/collector/internal/integrationtest/metrics_test.go +++ b/exporter/collector/internal/integrationtest/metrics_test.go @@ -56,12 +56,15 @@ func TestMetrics(t *testing.T) { startTime, endTime, ) + + selfObsMetrics, err := inMemoryOCExporter.Proto(ctx) + require.NoError(t, err) diff := DiffProtos( &MetricExpectFixture{ CreateTimeSeriesRequests: testServer.CreateTimeSeriesRequests(), CreateMetricDescriptorRequests: testServer.CreateMetricDescriptorRequests(), CreateServiceTimeSeriesRequests: testServer.CreateServiceTimeSeriesRequests(), - SelfObservabilityMetrics: inMemoryOCExporter.Proto(), + SelfObservabilityMetrics: selfObsMetrics, }, expectFixture, ) diff --git a/exporter/collector/internal/integrationtest/testcase.go b/exporter/collector/internal/integrationtest/testcase.go index 0b45d3a49..e7d9ad053 100644 --- a/exporter/collector/internal/integrationtest/testcase.go +++ b/exporter/collector/internal/integrationtest/testcase.go @@ -174,6 +174,15 @@ func normalizeFixture(fixture *MetricExpectFixture) { fixture.GetCreateTimeSeriesRequests(), fixture.GetCreateServiceTimeSeriesRequests()..., ) + timeSeriesReqs = append( + timeSeriesReqs, + fixture.GetSelfObservabilityMetrics().GetCreateTimeSeriesRequests()..., + ) + metricDescriptorReqs := append( + fixture.GetCreateMetricDescriptorRequests(), + fixture.GetSelfObservabilityMetrics().GetCreateMetricDescriptorRequests()..., + ) + for _, req := range timeSeriesReqs { // clear project ID req.Name = "" @@ -194,7 +203,7 @@ func normalizeFixture(fixture *MetricExpectFixture) { } } - for _, req := range fixture.GetCreateMetricDescriptorRequests() { + for _, req := range metricDescriptorReqs { req.Name = "" if md := req.GetMetricDescriptor(); md != nil { md.Name = "" diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/basic_counter_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/basic_counter_metrics_expect.json index b9ba19c20..34d07b6ca 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/basic_counter_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/basic_counter_metrics_expect.json @@ -52,13 +52,51 @@ } } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "1", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/create_service_timeseries_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/create_service_timeseries_metrics_expect.json index 910b37092..9e81b00ff 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/create_service_timeseries_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/create_service_timeseries_metrics_expect.json @@ -33,13 +33,51 @@ ] } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "1", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/delta_counter_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/delta_counter_metrics_expect.json index 485e5c557..1c83be3cd 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/delta_counter_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/delta_counter_metrics_expect.json @@ -52,13 +52,51 @@ } } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "1", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/exponential_histogram_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/exponential_histogram_metrics_expect.json index 539d37ffe..1a395b805 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/exponential_histogram_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/exponential_histogram_metrics_expect.json @@ -225,13 +225,51 @@ } } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "2", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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": "2" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/gke_control_plane_metrics_agent_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/gke_control_plane_metrics_agent_metrics_expect.json index c472defe8..1b500cc75 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/gke_control_plane_metrics_agent_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/gke_control_plane_metrics_agent_metrics_expect.json @@ -1063,13 +1063,51 @@ ] } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "35", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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": "35" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/gke_metrics_agent_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/gke_metrics_agent_metrics_expect.json index 5eb7329cb..a66a6ecec 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/gke_metrics_agent_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/gke_metrics_agent_metrics_expect.json @@ -4047,13 +4047,51 @@ ] } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "143", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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": "143" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/nonmonotonic_counter_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/nonmonotonic_counter_metrics_expect.json index 75e1cf6ae..52d76b59b 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/nonmonotonic_counter_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/nonmonotonic_counter_metrics_expect.json @@ -51,13 +51,51 @@ } } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "1", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/ops_agent_host_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/ops_agent_host_metrics_expect.json index 9c3e9a99a..096e60dd7 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/ops_agent_host_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/ops_agent_host_metrics_expect.json @@ -3150,13 +3150,51 @@ ] } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "106", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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": "106" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/ops_agent_self_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/ops_agent_self_metrics_expect.json index 72670516d..3abf4c426 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/ops_agent_self_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/ops_agent_self_metrics_expect.json @@ -57,13 +57,51 @@ ] } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "2", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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": "2" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/summary_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/summary_metrics_expect.json index 5159d4700..c3b8321af 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/summary_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/summary_metrics_expect.json @@ -206,13 +206,51 @@ } } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "5", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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": "5" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/unknown_domain_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/unknown_domain_metrics_expect.json index 82551d055..f957cf515 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/unknown_domain_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/unknown_domain_metrics_expect.json @@ -52,13 +52,51 @@ } } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "1", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } } diff --git a/exporter/collector/internal/integrationtest/testdata/fixtures/workloadgoogleapis_prefix_metrics_expect.json b/exporter/collector/internal/integrationtest/testdata/fixtures/workloadgoogleapis_prefix_metrics_expect.json index b9ba19c20..34d07b6ca 100644 --- a/exporter/collector/internal/integrationtest/testdata/fixtures/workloadgoogleapis_prefix_metrics_expect.json +++ b/exporter/collector/internal/integrationtest/testdata/fixtures/workloadgoogleapis_prefix_metrics_expect.json @@ -52,13 +52,51 @@ } } ], - "selfObservabilityMetrics": [ - { - "name": "googlecloudmonitoring/point_count", - "val": "1", - "labels": { - "status": "OK" + "selfObservabilityMetrics": { + "createTimeSeriesRequests": [ + { + "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" + } + } + ] + } + ] } - } - ] + ], + "createMetricDescriptorRequests": [ + { + "metricDescriptor": { + "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" + } + } + ] + } }