From f8e3dea19012ccf05965d10255789eec33c2ebcf Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Thu, 23 Aug 2018 22:51:21 +0100 Subject: Update deps --- vendor/go.opencensus.io/stats/measure.go | 28 +++++++--- vendor/go.opencensus.io/stats/measure_float64.go | 8 +-- vendor/go.opencensus.io/stats/measure_int64.go | 8 +-- vendor/go.opencensus.io/stats/view/collector.go | 5 +- vendor/go.opencensus.io/stats/view/export.go | 3 ++ vendor/go.opencensus.io/stats/view/view.go | 6 +-- vendor/go.opencensus.io/stats/view/worker.go | 62 +++++++++------------- .../go.opencensus.io/stats/view/worker_commands.go | 9 ++-- 8 files changed, 71 insertions(+), 58 deletions(-) (limited to 'vendor/go.opencensus.io/stats') diff --git a/vendor/go.opencensus.io/stats/measure.go b/vendor/go.opencensus.io/stats/measure.go index aa555c2..7b4b49c 100644 --- a/vendor/go.opencensus.io/stats/measure.go +++ b/vendor/go.opencensus.io/stats/measure.go @@ -20,19 +20,31 @@ import ( "sync/atomic" ) -// Measure represents a type of metric to be tracked and recorded. -// For example, latency, request Mb/s, and response Mb/s are measures +// Measure represents a single numeric value to be tracked and recorded. +// For example, latency, request bytes, and response bytes could be measures // to collect from a server. // -// Each measure needs to be registered before being used. -// Measure constructors such as Int64 and -// Float64 automatically registers the measure -// by the given name. -// Each registered measure needs to be unique by name. -// Measures also have a description and a unit. +// Measures by themselves have no outside effects. In order to be exported, +// the measure needs to be used in a View. If no Views are defined over a +// measure, there is very little cost in recording it. type Measure interface { + // Name returns the name of this measure. + // + // Measure names are globally unique (among all libraries linked into your program). + // We recommend prefixing the measure name with a domain name relevant to your + // project or application. + // + // Measure names are never sent over the wire or exported to backends. + // They are only used to create Views. Name() string + + // Description returns the human-readable description of this measure. Description() string + + // Unit returns the units for the values this measure takes on. + // + // Units are encoded according to the case-sensitive abbreviations from the + // Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html Unit() string } diff --git a/vendor/go.opencensus.io/stats/measure_float64.go b/vendor/go.opencensus.io/stats/measure_float64.go index 8de6b52..da4b5a8 100644 --- a/vendor/go.opencensus.io/stats/measure_float64.go +++ b/vendor/go.opencensus.io/stats/measure_float64.go @@ -15,7 +15,7 @@ package stats -// Float64Measure is a measure of type float64. +// Float64Measure is a measure for float64 values. type Float64Measure struct { md *measureDescriptor } @@ -44,8 +44,10 @@ func (m *Float64Measure) M(v float64) Measurement { return Measurement{m: m, v: v} } -// Float64 creates a new measure of type Float64Measure. -// It never returns an error. +// Float64 creates a new measure for float64 values. +// +// See the documentation for interface Measure for more guidance on the +// parameters of this function. func Float64(name, description, unit string) *Float64Measure { mi := registerMeasureHandle(name, description, unit) return &Float64Measure{mi} diff --git a/vendor/go.opencensus.io/stats/measure_int64.go b/vendor/go.opencensus.io/stats/measure_int64.go index b6fd25f..5fedaad 100644 --- a/vendor/go.opencensus.io/stats/measure_int64.go +++ b/vendor/go.opencensus.io/stats/measure_int64.go @@ -15,7 +15,7 @@ package stats -// Int64Measure is a measure of type int64. +// Int64Measure is a measure for int64 values. type Int64Measure struct { md *measureDescriptor } @@ -44,8 +44,10 @@ func (m *Int64Measure) M(v int64) Measurement { return Measurement{m: m, v: float64(v)} } -// Int64 creates a new measure of type Int64Measure. -// It never returns an error. +// Int64 creates a new measure for int64 values. +// +// See the documentation for interface Measure for more guidance on the +// parameters of this function. func Int64(name, description, unit string) *Int64Measure { mi := registerMeasureHandle(name, description, unit) return &Int64Measure{mi} diff --git a/vendor/go.opencensus.io/stats/view/collector.go b/vendor/go.opencensus.io/stats/view/collector.go index 863a5b6..250395d 100644 --- a/vendor/go.opencensus.io/stats/view/collector.go +++ b/vendor/go.opencensus.io/stats/view/collector.go @@ -40,11 +40,12 @@ func (c *collector) addSample(s string, v float64) { aggregator.addSample(v) } +// collectRows returns a snapshot of the collected Row values. func (c *collector) collectedRows(keys []tag.Key) []*Row { - var rows []*Row + rows := make([]*Row, 0, len(c.signatures)) for sig, aggregator := range c.signatures { tags := decodeTags([]byte(sig), keys) - row := &Row{tags, aggregator} + row := &Row{Tags: tags, Data: aggregator.clone()} rows = append(rows, row) } return rows diff --git a/vendor/go.opencensus.io/stats/view/export.go b/vendor/go.opencensus.io/stats/view/export.go index ffd0d1a..7cb5971 100644 --- a/vendor/go.opencensus.io/stats/view/export.go +++ b/vendor/go.opencensus.io/stats/view/export.go @@ -27,6 +27,9 @@ var ( // Exporter takes a significant amount of time to // process a Data, that work should be done on another goroutine. // +// It is safe to assume that ExportView will not be called concurrently from +// multiple goroutines. +// // The Data should not be modified. type Exporter interface { ExportView(viewData *Data) diff --git a/vendor/go.opencensus.io/stats/view/view.go b/vendor/go.opencensus.io/stats/view/view.go index 87bf5d4..22323e2 100644 --- a/vendor/go.opencensus.io/stats/view/view.go +++ b/vendor/go.opencensus.io/stats/view/view.go @@ -29,7 +29,7 @@ import ( ) // View allows users to aggregate the recorded stats.Measurements. -// Views need to be passed to the Subscribe function to be before data will be +// Views need to be passed to the Register function to be before data will be // collected and sent to Exporters. type View struct { Name string // Name of View. Must be unique. If unset, will default to the name of the Measure. @@ -71,10 +71,10 @@ func (v *View) same(other *View) bool { // defaults for Name and Description and sorting the TagKeys func (v *View) canonicalize() error { if v.Measure == nil { - return fmt.Errorf("cannot subscribe view %q: measure not set", v.Name) + return fmt.Errorf("cannot register view %q: measure not set", v.Name) } if v.Aggregation == nil { - return fmt.Errorf("cannot subscribe view %q: aggregation not set", v.Name) + return fmt.Errorf("cannot register view %q: aggregation not set", v.Name) } if v.Name == "" { v.Name = v.Measure.Name() diff --git a/vendor/go.opencensus.io/stats/view/worker.go b/vendor/go.opencensus.io/stats/view/worker.go index ba9d7fc..fef7bf5 100644 --- a/vendor/go.opencensus.io/stats/view/worker.go +++ b/vendor/go.opencensus.io/stats/view/worker.go @@ -49,8 +49,8 @@ var defaultWorker *worker var defaultReportingDuration = 10 * time.Second -// Find returns a subscribed view associated with this name. -// If no subscribed view is found, nil is returned. +// Find returns a registered view associated with this name. +// If no registered view is found, nil is returned. func Find(name string) (v *View) { req := &getViewByNameReq{ name: name, @@ -62,7 +62,7 @@ func Find(name string) (v *View) { } // Register begins collecting data for the given views. -// Once a view is subscribed, it reports data to the registered exporters. +// Once a view is registered, it reports data to the registered exporters. func Register(views ...*View) error { for _, v := range views { if err := v.canonicalize(); err != nil { @@ -181,7 +181,7 @@ func (w *worker) tryRegisterView(v *View) (*viewInternal, error) { } if x, ok := w.views[vi.view.Name]; ok { if !x.view.same(vi.view) { - return nil, fmt.Errorf("cannot subscribe view %q; a different view with the same name is already subscribed", v.Name) + return nil, fmt.Errorf("cannot register view %q; a different view with the same name is already registered", v.Name) } // the view is already registered so there is nothing to do and the @@ -194,40 +194,30 @@ func (w *worker) tryRegisterView(v *View) (*viewInternal, error) { return vi, nil } -func (w *worker) reportUsage(now time.Time) { - for _, v := range w.views { - if !v.isSubscribed() { - continue - } - rows := v.collectedRows() - _, ok := w.startTimes[v] - if !ok { - w.startTimes[v] = now - } - // Make sure collector is never going - // to mutate the exported data. - rows = deepCopyRowData(rows) - viewData := &Data{ - View: v.view, - Start: w.startTimes[v], - End: time.Now(), - Rows: rows, - } - exportersMu.Lock() - for e := range exporters { - e.ExportView(viewData) - } - exportersMu.Unlock() +func (w *worker) reportView(v *viewInternal, now time.Time) { + if !v.isSubscribed() { + return } + rows := v.collectedRows() + _, ok := w.startTimes[v] + if !ok { + w.startTimes[v] = now + } + viewData := &Data{ + View: v.view, + Start: w.startTimes[v], + End: time.Now(), + Rows: rows, + } + exportersMu.Lock() + for e := range exporters { + e.ExportView(viewData) + } + exportersMu.Unlock() } -func deepCopyRowData(rows []*Row) []*Row { - newRows := make([]*Row, 0, len(rows)) - for _, r := range rows { - newRows = append(newRows, &Row{ - Data: r.Data.clone(), - Tags: r.Tags, - }) +func (w *worker) reportUsage(now time.Time) { + for _, v := range w.views { + w.reportView(v, now) } - return newRows } diff --git a/vendor/go.opencensus.io/stats/view/worker_commands.go b/vendor/go.opencensus.io/stats/view/worker_commands.go index ef79ec3..06c3c54 100644 --- a/vendor/go.opencensus.io/stats/view/worker_commands.go +++ b/vendor/go.opencensus.io/stats/view/worker_commands.go @@ -73,7 +73,7 @@ func (cmd *registerViewReq) handleCommand(w *worker) { } } -// unregisterFromViewReq is the command to unsubscribe to a view. Has no +// unregisterFromViewReq is the command to unregister to a view. Has no // impact on the data collection for client that are pulling data from the // library. type unregisterFromViewReq struct { @@ -88,6 +88,9 @@ func (cmd *unregisterFromViewReq) handleCommand(w *worker) { continue } + // Report pending data for this view before removing it. + w.reportView(vi, time.Now()) + vi.unsubscribe() if !vi.isSubscribed() { // this was the last subscription and view is not collecting anymore. @@ -143,7 +146,7 @@ type recordReq struct { func (cmd *recordReq) handleCommand(w *worker) { for _, m := range cmd.ms { - if (m == stats.Measurement{}) { // not subscribed + if (m == stats.Measurement{}) { // not registered continue } ref := w.getMeasureRef(m.Measure().Name()) @@ -154,7 +157,7 @@ func (cmd *recordReq) handleCommand(w *worker) { } // setReportingPeriodReq is the command to modify the duration between -// reporting the collected data to the subscribed clients. +// reporting the collected data to the registered clients. type setReportingPeriodReq struct { d time.Duration c chan bool -- cgit v1.2.3