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

Commit

Permalink
Exemplar: move to metricdata.
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed Mar 15, 2019
1 parent 40af6c6 commit 60c842a
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 251 deletions.
37 changes: 0 additions & 37 deletions metric/metricdata/exemplar.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package metricdata

import (
"context"
"time"
)

Expand All @@ -38,40 +37,4 @@ type Exemplar struct {
}

// Attachments is a map of extra values associated with a recorded data point.
// The map should only be mutated from AttachmentExtractor functions.
type Attachments map[string]string

// AttachmentExtractor is a function capable of extracting exemplar attachments
// from the context used to record measurements.
// The map passed to the function should be mutated and returned. It will
// initially be nil: the first AttachmentExtractor that would like to add keys to the
// map is responsible for initializing it.
type AttachmentExtractor func(ctx context.Context, a Attachments) Attachments

var extractors []AttachmentExtractor

// RegisterAttachmentExtractor registers the given extractor associated with the exemplar
// type name.
//
// Extractors will be used to attempt to extract exemplars from the context
// associated with each recorded measurement.
//
// Packages that support exemplars should register their extractor functions on
// initialization.
//
// RegisterAttachmentExtractor should not be called after any measurements have
// been recorded.
func RegisterAttachmentExtractor(e AttachmentExtractor) {
extractors = append(extractors, e)
}

// AttachmentsFromContext extracts exemplars from the given context.
// Each registered AttachmentExtractor (see RegisterAttachmentExtractor) is called in an
// unspecified order to add attachments to the exemplar.
func AttachmentsFromContext(ctx context.Context) Attachments {
var a Attachments
for _, extractor := range extractors {
a = extractor(ctx, a)
}
return a
}
4 changes: 2 additions & 2 deletions stats/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package stats
import (
"context"

"go.opencensus.io/metric/metricdata"
"go.opencensus.io/stats/internal"
"go.opencensus.io/tag"
)
Expand Down Expand Up @@ -51,7 +50,8 @@ func Record(ctx context.Context, ms ...Measurement) {
if !record {
return
}
recorder(tag.FromContext(ctx), ms, metricdata.AttachmentsFromContext(ctx))
// TODO(songy23): fix attachments.
recorder(tag.FromContext(ctx), ms, map[string]string{})
}

// RecordWithTags records one or multiple measurements at once.
Expand Down
2 changes: 1 addition & 1 deletion stats/view/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func Test_View_MeasureFloat64_AggregationDistribution(t *testing.T) {
}
e := &metricdata.Exemplar{
Value: r.f,
Attachments: metricdata.AttachmentsFromContext(ctx),
Attachments: map[string]string{},
}
view.addSample(tag.FromContext(ctx), e)
}
Expand Down
24 changes: 0 additions & 24 deletions tag/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package tag

import (
"context"

"go.opencensus.io/metric/metricdata"
)

// FromContext returns the tag map stored in the context.
Expand All @@ -43,25 +41,3 @@ func NewContext(ctx context.Context, m *Map) context.Context {
type ctxKey struct{}

var mapCtxKey = ctxKey{}

func init() {
metricdata.RegisterAttachmentExtractor(extractTagsAttachments)
}

func extractTagsAttachments(ctx context.Context, a metricdata.Attachments) metricdata.Attachments {
m := FromContext(ctx)
if m == nil {
return a
}
if len(m.m) == 0 {
return a
}
if a == nil {
a = make(map[string]string)
}

for k, v := range m.m {
a[metricdata.KeyPrefixTag+k.Name()] = v
}
return a
}
44 changes: 0 additions & 44 deletions tag/context_test.go

This file was deleted.

43 changes: 0 additions & 43 deletions trace/exemplar.go

This file was deleted.

100 changes: 0 additions & 100 deletions trace/exemplar_test.go

This file was deleted.

0 comments on commit 60c842a

Please sign in to comment.