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

Commit

Permalink
Set MetricKind and ValueType when sending TimeSeries (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed Aug 29, 2019
1 parent ffafe44 commit 9762c69
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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

0 comments on commit 9762c69

Please sign in to comment.