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

Set MetricKind and ValueType when sending TimeSeries #182

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions metrics_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func (se *statsExporter) protoMetricToTimeSeries(ctx context.Context, node *comm
}
metricType, _ := se.metricTypeFromProto(metricName)
metricLabelKeys := metric.GetMetricDescriptor().GetLabelKeys()
metricKind, _ := protoMetricDescriptorTypeToMetricKind(metric)
metricKind, valueType := protoMetricDescriptorTypeToMetricKind(metric)

timeSeries := make([]*monitoringpb.TimeSeries, 0, len(metric.Timeseries))
for _, protoTimeSeries := range metric.Timeseries {
Expand All @@ -474,8 +474,10 @@ func (se *statsExporter) protoMetricToTimeSeries(ctx context.Context, node *comm
Type: metricType,
Labels: labels,
},
Resource: mappedRsc,
Points: sdPoints,
MetricKind: metricKind,
ValueType: valueType,
Resource: mappedRsc,
Points: sdPoints,
})
}

Expand Down
10 changes: 9 additions & 1 deletion metrics_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"
"testing"

"cloud.google.com/go/monitoring/apiv3"
monitoring "cloud.google.com/go/monitoring/apiv3"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
"github.com/golang/protobuf/ptypes/timestamp"
distributionpb "google.golang.org/genproto/googleapis/api/distribution"
Expand Down Expand Up @@ -103,6 +103,8 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
Resource: &monitoredrespb.MonitoredResource{
Type: "global",
},
MetricKind: googlemetricpb.MetricDescriptor_CUMULATIVE,
ValueType: googlemetricpb.MetricDescriptor_DISTRIBUTION,
Points: []*monitoringpb.Point{
{
Interval: &monitoringpb.TimeInterval{
Expand Down Expand Up @@ -187,6 +189,7 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
Name: "with_container_resource",
Description: "This is a test",
Unit: "By",
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
},
Resource: &resourcepb.Resource{
Type: resourcekeys.ContainerType,
Expand Down Expand Up @@ -234,6 +237,8 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
"container_name": "container-name1",
},
},
MetricKind: googlemetricpb.MetricDescriptor_CUMULATIVE,
ValueType: googlemetricpb.MetricDescriptor_INT64,
Points: []*monitoringpb.Point{
{
Interval: &monitoringpb.TimeInterval{
Expand All @@ -258,6 +263,7 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
Name: "with_gce_resource",
Description: "This is a test",
Unit: "By",
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
},
Resource: &resourcepb.Resource{
Type: resourcekeys.CloudType,
Expand Down Expand Up @@ -300,6 +306,8 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
"zone": "zone1",
},
},
MetricKind: googlemetricpb.MetricDescriptor_CUMULATIVE,
ValueType: googlemetricpb.MetricDescriptor_INT64,
Points: []*monitoringpb.Point{
{
Interval: &monitoringpb.TimeInterval{
Expand Down
2 changes: 1 addition & 1 deletion metrics_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func cmpResource(got, want *monitoredrespb.MonitoredResource) string {
}

func cmpTSReqs(got, want []*monitoringpb.CreateTimeSeriesRequest) string {
return cmp.Diff(got, want, cmpopts.IgnoreUnexported(monitoringpb.CreateTimeSeriesRequest{}))
return cmp.Diff(got, want, cmpopts.IgnoreUnexported(monitoringpb.CreateTimeSeriesRequest{}), cmpopts.IgnoreTypes(googlemetricpb.MetricDescriptor_METRIC_KIND_UNSPECIFIED, googlemetricpb.MetricDescriptor_VALUE_TYPE_UNSPECIFIED))
}

func cmpMD(got, want *googlemetricpb.MetricDescriptor) string {
Expand Down