Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit a738f4f

Browse files
authored
Prevent from attempting to create metrics with unspecified MetricKind (#305)
* Fixes errors returned when attempting to create metrics with unspecified metric kind.
1 parent f4930fe commit a738f4f

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

metrics.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ func (se *statsExporter) createMetricDescriptorFromMetric(ctx context.Context, m
261261
return err
262262
}
263263

264+
// ignore
265+
if inMD.MetricKind == googlemetricpb.MetricDescriptor_METRIC_KIND_UNSPECIFIED {
266+
return nil
267+
}
268+
264269
if err = se.createMetricDescriptor(ctx, inMD); err != nil {
265270
return err
266271
}

metrics_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ func TestMetricToCreateTimeSeriesRequest(t *testing.T) {
127127
Count: 1,
128128
Exemplar: &metricdata.Exemplar{Value: 11.9, Timestamp: startTime, Attachments: map[string]interface{}{"key": "value"}},
129129
},
130-
{}, {}, {},
130+
{},
131+
{},
132+
{},
131133
},
132134
BucketOptions: &metricdata.BucketOptions{
133135
Bounds: []float64{10, 20, 30, 40},
@@ -463,7 +465,8 @@ func TestMetricsToMonitoringMetrics_fromProtoPoint(t *testing.T) {
463465
{},
464466
{
465467
Count: 1,
466-
Exemplar: &metricdata.Exemplar{Value: 11.9, Timestamp: startTime, Attachments: map[string]interface{}{"SpanContext": spanCtx}}},
468+
Exemplar: &metricdata.Exemplar{Value: 11.9, Timestamp: startTime, Attachments: map[string]interface{}{"SpanContext": spanCtx}},
469+
},
467470
{},
468471
{},
469472
{},
@@ -945,7 +948,7 @@ func TestResourceByDescriptor(t *testing.T) {
945948
},
946949
}
947950

948-
var se = &statsExporter{
951+
se := &statsExporter{
949952
o: Options{
950953
ProjectID: "foo",
951954
ResourceByDescriptor: getResourceByDescriptor,

0 commit comments

Comments
 (0)