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

Remove exemplar for now. #53

Merged
merged 2 commits into from
Mar 20, 2019
Merged
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
30 changes: 6 additions & 24 deletions transform_stats_to_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"errors"
"time"

"go.opencensus.io/metric/metricdata"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
Expand Down Expand Up @@ -203,9 +202,10 @@ func rowToPoint(v *view.View, row *view.Row, endTimestamp *timestamp.Timestamp,
case *view.DistributionData:
pt.Value = &metricspb.Point_DistributionValue{
DistributionValue: &metricspb.DistributionValue{
Count: data.Count,
Sum: float64(data.Count) * data.Mean, // because Mean := Sum/Count
Buckets: bucketsToProtoBuckets(data.CountPerBucket, data.ExemplarsPerBucket),
Count: data.Count,
Sum: float64(data.Count) * data.Mean, // because Mean := Sum/Count
// TODO: Add Exemplar
Buckets: bucketsToProtoBuckets(data.CountPerBucket),
BucketOptions: &metricspb.DistributionValue_BucketOptions{
Type: &metricspb.DistributionValue_BucketOptions_Explicit_{
Explicit: &metricspb.DistributionValue_BucketOptions_Explicit{
Expand Down Expand Up @@ -236,31 +236,13 @@ func setPointValue(pt *metricspb.Point, value float64, mType measureType) {
}
}

// countPerBucket and exemplars are of the same length in well formed data,
// otherwise ensure that even if exemplars are non-existent that we always
// insert counts and create distribution value buckets.
func bucketsToProtoBuckets(countPerBucket []int64, exemplars []*metricdata.Exemplar) []*metricspb.DistributionValue_Bucket {
func bucketsToProtoBuckets(countPerBucket []int64) []*metricspb.DistributionValue_Bucket {
distBuckets := make([]*metricspb.DistributionValue_Bucket, len(countPerBucket))
for i := 0; i < len(countPerBucket); i++ {
count := countPerBucket[i]

var exmplr *metricdata.Exemplar
if i < len(exemplars) {
exmplr = exemplars[i]
}

var protoExemplar *metricspb.DistributionValue_Exemplar
if exmplr != nil {
protoExemplar = &metricspb.DistributionValue_Exemplar{
Value: exmplr.Value,
Timestamp: timeToTimestamp(exmplr.Timestamp),
Attachments: exmplr.Attachments,
}
}

distBuckets[i] = &metricspb.DistributionValue_Bucket{
Count: count,
Exemplar: protoExemplar,
Count: count,
}
}

Expand Down