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

Commit

Permalink
Small cleanup of the return values (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdandrutu authored Aug 29, 2019
1 parent 9762c69 commit 270bb39
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions metrics_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"go.opencensus.io/stats"
"go.opencensus.io/trace"

"cloud.google.com/go/monitoring/apiv3"
monitoring "cloud.google.com/go/monitoring/apiv3"
distributionpb "google.golang.org/genproto/googleapis/api/distribution"
labelpb "google.golang.org/genproto/googleapis/api/label"
googlemetricpb "google.golang.org/genproto/googleapis/api/metric"
Expand Down Expand Up @@ -665,23 +665,20 @@ func fromProtoPoint(startTime *timestamp.Timestamp, pt *metricspb.Point) (*monit
return nil, err
}

mpt := &monitoringpb.Point{
return &monitoringpb.Point{
Value: mptv,
Interval: &monitoringpb.TimeInterval{
StartTime: startTime,
EndTime: pt.Timestamp,
},
}
return mpt, nil
}, nil
}

func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) {
if value == nil {
return nil, nil
}

var err error
var tval *monitoringpb.TypedValue
switch v := value.(type) {
default:
// All the other types are not yet handled.
Expand All @@ -697,21 +694,21 @@ func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) {
// TODO: Add conversion from SummaryValue when
// https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver/issues/66
// has been figured out.
err = fmt.Errorf("protoToMetricPoint: unknown Data type: %T", value)
return nil, fmt.Errorf("protoToMetricPoint: unknown Data type: %T", value)

case *metricspb.Point_Int64Value:
tval = &monitoringpb.TypedValue{
return &monitoringpb.TypedValue{
Value: &monitoringpb.TypedValue_Int64Value{
Int64Value: v.Int64Value,
},
}
}, nil

case *metricspb.Point_DoubleValue:
tval = &monitoringpb.TypedValue{
return &monitoringpb.TypedValue{
Value: &monitoringpb.TypedValue_DoubleValue{
DoubleValue: v.DoubleValue,
},
}
}, nil

case *metricspb.Point_DistributionValue:
dv := v.DistributionValue
Expand Down Expand Up @@ -749,10 +746,8 @@ func protoToMetricPoint(value interface{}) (*monitoringpb.TypedValue, error) {
mv.DistributionValue.BucketCounts = addZeroBucketCountOnCondition(insertZeroBound, bucketCounts(dv.Buckets)...)

}
tval = &monitoringpb.TypedValue{Value: mv}
return &monitoringpb.TypedValue{Value: mv}, nil
}

return tval, err
}

func bucketCounts(buckets []*metricspb.DistributionValue_Bucket) []int64 {
Expand Down

0 comments on commit 270bb39

Please sign in to comment.