From 242ff20cf0c627018876e63a28badaacb7038a8a Mon Sep 17 00:00:00 2001 From: Punya Biswal Date: Thu, 27 Jan 2022 12:23:58 -0500 Subject: [PATCH] Revert "Add SkipCMD to Go metric exporter (#284)" (#293) This reverts commit 24420159f1b4bc16579462847eae74b00227b534. --- exporter/metric/metric.go | 4 --- exporter/metric/metric_test.go | 65 ---------------------------------- exporter/metric/option.go | 10 ------ 3 files changed, 79 deletions(-) diff --git a/exporter/metric/metric.go b/exporter/metric/metric.go index c71ef0cd4..686dae919 100644 --- a/exporter/metric/metric.go +++ b/exporter/metric/metric.go @@ -194,10 +194,6 @@ func (me *metricExporter) ExportMetrics(ctx context.Context, res *resource.Resou // exportMetricDescriptor create MetricDescriptor from the record // if the descriptor is not registered in Cloud Monitoring yet. func (me *metricExporter) exportMetricDescriptor(ctx context.Context, res *resource.Resource, ilr export.InstrumentationLibraryReader) error { - if me.o.SkipCreateMetricDescriptor { - return nil - } - mds := make(map[key]*googlemetricpb.MetricDescriptor) aggError := ilr.ForEach(func(library instrumentation.Library, reader export.Reader) error { return reader.ForEach(aggregation.CumulativeTemporalitySelector(), func(r export.Record) error { diff --git a/exporter/metric/metric_test.go b/exporter/metric/metric_test.go index f2b8319cc..239179a0c 100644 --- a/exporter/metric/metric_test.go +++ b/exporter/metric/metric_test.go @@ -618,68 +618,3 @@ func TestExportMetricsWithUserAgent(t *testing.T) { // User agent checking happens above in parallel to this flow. } - -func TestSkipCreateMetricDescriptor(t *testing.T) { - server := grpc.NewServer() - t.Cleanup(server.Stop) - - // Channel to record any CMD calls - ch := make(chan struct{}, 1) - - m := mock{ - createTimeSeries: func(ctx context.Context, r *monitoringpb.CreateTimeSeriesRequest) (*emptypb.Empty, error) { - return &emptypb.Empty{}, nil - }, - createMetricDescriptor: func(ctx context.Context, req *monitoringpb.CreateMetricDescriptorRequest) (*googlemetricpb.MetricDescriptor, error) { - select { - case ch <- struct{}{}: - default: - } - return req.MetricDescriptor, nil - }, - } - monitoringpb.RegisterMetricServiceServer(server, &m) - - lis, err := net.Listen("tcp", "127.0.0.1:0") - require.NoError(t, err) - go server.Serve(lis) - - clientOpts := []option.ClientOption{ - option.WithEndpoint(lis.Addr().String()), - option.WithoutAuthentication(), - option.WithGRPCDialOption(grpc.WithInsecure()), - } - res := &resource.Resource{} - aggSel := processortest.AggregatorSelector() - proc := processor.NewFactory(aggSel, aggregation.CumulativeTemporalitySelector()) - ctx := context.Background() - - opts := []Option{ - WithProjectID("PROJECT_ID_NOT_REAL"), - WithMonitoringClientOptions(clientOpts...), - WithMetricDescriptorTypeFormatter(formatter), - WithSkipCreateMetricDescriptor(), - } - - exporter, err := NewRawExporter(opts...) - if err != nil { - t.Errorf("Error occurred when creating exporter: %v", err) - } - cont := controller.New(proc, - controller.WithExporter(exporter), - controller.WithResource(res), - ) - - assert.NoError(t, cont.Start(ctx)) - meter := cont.Meter("test") - - counter := metric.Must(meter).NewInt64Counter("name.lastvalue") - - counter.Add(ctx, 1) - require.NoError(t, cont.Stop(ctx)) - - close(ch) - for range ch { - t.Error("CreateMetricDescriptor was called despite WithSkipCreateMetricDescriptor() option") - } -} diff --git a/exporter/metric/option.go b/exporter/metric/option.go index 74b0c1d91..6061db410 100644 --- a/exporter/metric/option.go +++ b/exporter/metric/option.go @@ -63,9 +63,6 @@ type options struct { // By default, the format string is "custom.googleapis.com/opentelemetry/[metric name]". MetricDescriptorTypeFormatter func(*sdkapi.Descriptor) string - // SkipCreateMetricDescriptor determines whether to skip exporting metric descriptors. - SkipCreateMetricDescriptor bool - // onError is the hook to be called when there is an error uploading the metric data. // If no custom hook is set, errors are logged. Optional. // @@ -118,10 +115,3 @@ func WithOnError(f func(error)) func(o *options) { o.onError = f } } - -// WithSkipCreateMetricDescriptor disables making CreateMetricDescriptor calls. -func WithSkipCreateMetricDescriptor() func(o *options) { - return func(o *options) { - o.SkipCreateMetricDescriptor = true - } -}