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

Commit

Permalink
Use a stronger type for []stats.Measurement in Record
Browse files Browse the repository at this point in the history
  • Loading branch information
evankanderson committed Feb 14, 2020
1 parent 4bd9e42 commit 6003f86
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 1 addition & 3 deletions stats/internal/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
package internal

import (
"go.opencensus.io/stats"
"go.opencensus.io/tag"
)

// DefaultRecorder will be called for each Record call.
var DefaultRecorder func(tags *tag.Map, measurement interface{}, attachments map[string]interface{})

// SubscriptionReporter reports when a view subscribed with a measure.
var SubscriptionReporter func(measure string)
7 changes: 5 additions & 2 deletions stats/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ func init() {
}
}

// DefaultRecorder will be called for each Record call.
var DefaultRecorder func(tags *tag.Map, measurement []Measurement, attachments map[string]interface{})

// Recorder provides an interface for exporting measurement information from
// the static Record method by using the WithRecorder option.
type Recorder interface {
// Record records a set of measurements associated with the given tags and attachments.
// The second argument is a `[]Measurement`.
Record(*tag.Map, interface{}, map[string]interface{})
Record(*tag.Map, []Measurement, map[string]interface{})
}

type recordOptions struct {
Expand Down Expand Up @@ -109,7 +112,7 @@ func RecordWithOptions(ctx context.Context, ros ...Options) error {
if len(o.measurements) == 0 {
return nil
}
recorder := internal.DefaultRecorder
recorder := DefaultRecorder
if o.recorder != nil {
recorder = o.recorder.Record
}
Expand Down
9 changes: 4 additions & 5 deletions stats/view/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import (
"go.opencensus.io/metric/metricdata"
"go.opencensus.io/metric/metricproducer"
"go.opencensus.io/stats"
"go.opencensus.io/stats/internal"
"go.opencensus.io/tag"
)

func init() {
defaultWorker = NewMeter().(*worker)
go defaultWorker.start()
internal.DefaultRecorder = record
stats.DefaultRecorder = record
}

type measureRef struct {
Expand Down Expand Up @@ -188,15 +187,15 @@ func (w *worker) RetrieveData(viewName string) ([]*Row, error) {
return resp.rows, resp.err
}

func record(tags *tag.Map, ms interface{}, attachments map[string]interface{}) {
func record(tags *tag.Map, ms []stats.Measurement, attachments map[string]interface{}) {
defaultWorker.Record(tags, ms, attachments)
}

// Record records a set of measurements ms associated with the given tags and attachments.
func (w *worker) Record(tags *tag.Map, ms interface{}, attachments map[string]interface{}) {
func (w *worker) Record(tags *tag.Map, ms []stats.Measurement, attachments map[string]interface{}) {
req := &recordReq{
tm: tags,
ms: ms.([]stats.Measurement),
ms: ms,
attachments: attachments,
t: time.Now(),
}
Expand Down

0 comments on commit 6003f86

Please sign in to comment.