Merge pull request #117959 from humblec/openconsensus

opencensus update to v0.24.0
This commit is contained in:
Kubernetes Prow Robot 2023-05-12 21:25:36 -07:00 committed by GitHub
commit d8f60a1e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 92 additions and 35 deletions

2
go.mod
View File

@ -221,7 +221,7 @@ require (
go.etcd.io/etcd/pkg/v3 v3.5.8 // indirect go.etcd.io/etcd/pkg/v3 v3.5.8 // indirect
go.etcd.io/etcd/raft/v3 v3.5.8 // indirect go.etcd.io/etcd/raft/v3 v3.5.8 // indirect
go.etcd.io/etcd/server/v3 v3.5.8 // indirect go.etcd.io/etcd/server/v3 v3.5.8 // indirect
go.opencensus.io v0.23.0 // indirect go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 // indirect

3
go.sum
View File

@ -713,8 +713,9 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.35.0 h1:KQjX0qQ8H21oBUAvFp4ZLKJMMLIluONvSPDAFIGmX58= go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.35.0 h1:KQjX0qQ8H21oBUAvFp4ZLKJMMLIluONvSPDAFIGmX58=
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.35.0/go.mod h1:DQYkU9srMFqLUTVA/7/WlRHdnYDB7wyMMlle2ktMjfI= go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.35.0/go.mod h1:DQYkU9srMFqLUTVA/7/WlRHdnYDB7wyMMlle2ktMjfI=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 h1:xFSRQBbXF6VvYRf2lqMJXxoB72XI1K/azav8TekHHSw= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 h1:xFSRQBbXF6VvYRf2lqMJXxoB72XI1K/azav8TekHHSw=

View File

@ -71,7 +71,7 @@ require (
github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
go.opencensus.io v0.23.0 // indirect go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.9.0 // indirect golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect golang.org/x/term v0.7.0 // indirect

View File

@ -359,8 +359,9 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

8
vendor/go.opencensus.io/Makefile generated vendored
View File

@ -91,7 +91,7 @@ embedmd:
.PHONY: install-tools .PHONY: install-tools
install-tools: install-tools:
go get -u golang.org/x/lint/golint go install golang.org/x/lint/golint@latest
go get -u golang.org/x/tools/cmd/cover go install golang.org/x/tools/cmd/cover@latest
go get -u golang.org/x/tools/cmd/goimports go install golang.org/x/tools/cmd/goimports@latest
go get -u github.com/rakyll/embedmd go install github.com/rakyll/embedmd@latest

View File

@ -17,5 +17,5 @@ package opencensus // import "go.opencensus.io"
// Version is the current release version of OpenCensus in use. // Version is the current release version of OpenCensus in use.
func Version() string { func Version() string {
return "0.23.0" return "0.24.0"
} }

View File

@ -31,14 +31,14 @@ import (
// Handler is an http.Handler wrapper to instrument your HTTP server with // Handler is an http.Handler wrapper to instrument your HTTP server with
// OpenCensus. It supports both stats and tracing. // OpenCensus. It supports both stats and tracing.
// //
// Tracing // # Tracing
// //
// This handler is aware of the incoming request's span, reading it from request // This handler is aware of the incoming request's span, reading it from request
// headers as configured using the Propagation field. // headers as configured using the Propagation field.
// The extracted span can be accessed from the incoming request's // The extracted span can be accessed from the incoming request's
// context. // context.
// //
// span := trace.FromContext(r.Context()) // span := trace.FromContext(r.Context())
// //
// The server span will be automatically ended at the end of ServeHTTP. // The server span will be automatically ended at the end of ServeHTTP.
type Handler struct { type Handler struct {
@ -224,7 +224,9 @@ func (t *trackingResponseWriter) WriteHeader(statusCode int) {
} }
// wrappedResponseWriter returns a wrapped version of the original // wrappedResponseWriter returns a wrapped version of the original
// ResponseWriter and only implements the same combination of additional //
// ResponseWriter and only implements the same combination of additional
//
// interfaces as the original. // interfaces as the original.
// This implementation is based on https://github.com/felixge/httpsnoop. // This implementation is based on https://github.com/felixge/httpsnoop.
func (t *trackingResponseWriter) wrappedResponseWriter() http.ResponseWriter { func (t *trackingResponseWriter) wrappedResponseWriter() http.ResponseWriter {

View File

@ -19,7 +19,7 @@ Package stats contains support for OpenCensus stats recording.
OpenCensus allows users to create typed measures, record measurements, OpenCensus allows users to create typed measures, record measurements,
aggregate the collected data, and export the aggregated data. aggregate the collected data, and export the aggregated data.
Measures # Measures
A measure represents a type of data point to be tracked and recorded. A measure represents a type of data point to be tracked and recorded.
For example, latency, request Mb/s, and response Mb/s are measures For example, latency, request Mb/s, and response Mb/s are measures
@ -33,7 +33,7 @@ Libraries can define and export measures. Application authors can then
create views and collect and break down measures by the tags they are create views and collect and break down measures by the tags they are
interested in. interested in.
Recording measurements # Recording measurements
Measurement is a data point to be collected for a measure. For example, Measurement is a data point to be collected for a measure. For example,
for a latency (ms) measure, 100 is a measurement that represents a 100ms for a latency (ms) measure, 100 is a measurement that represents a 100ms
@ -49,7 +49,7 @@ Libraries can always record measurements, and applications can later decide
on which measurements they want to collect by registering views. This allows on which measurements they want to collect by registering views. This allows
libraries to turn on the instrumentation by default. libraries to turn on the instrumentation by default.
Exemplars # Exemplars
For a given recorded measurement, the associated exemplar is a diagnostic map For a given recorded measurement, the associated exemplar is a diagnostic map
that gives more information about the measurement. that gives more information about the measurement.
@ -64,6 +64,5 @@ then the trace span will be added to the exemplar associated with the measuremen
When exported to a supporting back end, you should be able to easily navigate When exported to a supporting back end, you should be able to easily navigate
to example traces that fell into each bucket in the Distribution. to example traces that fell into each bucket in the Distribution.
*/ */
package stats // import "go.opencensus.io/stats" package stats // import "go.opencensus.io/stats"

View File

@ -21,5 +21,11 @@ import (
// DefaultRecorder will be called for each Record call. // DefaultRecorder will be called for each Record call.
var DefaultRecorder func(tags *tag.Map, measurement interface{}, attachments map[string]interface{}) var DefaultRecorder func(tags *tag.Map, measurement interface{}, attachments map[string]interface{})
// MeasurementRecorder will be called for each Record call. This is the same as DefaultRecorder but
// avoids interface{} conversion.
// This will be a func(tags *tag.Map, measurement []Measurement, attachments map[string]interface{}) type,
// but is interface{} here to avoid import loops
var MeasurementRecorder interface{}
// SubscriptionReporter reports when a view subscribed with a measure. // SubscriptionReporter reports when a view subscribed with a measure.
var SubscriptionReporter func(measure string) var SubscriptionReporter func(measure string)

View File

@ -86,10 +86,29 @@ func createRecordOption(ros ...Options) *recordOptions {
return o return o
} }
type measurementRecorder = func(tags *tag.Map, measurement []Measurement, attachments map[string]interface{})
// Record records one or multiple measurements with the same context at once. // Record records one or multiple measurements with the same context at once.
// If there are any tags in the context, measurements will be tagged with them. // If there are any tags in the context, measurements will be tagged with them.
func Record(ctx context.Context, ms ...Measurement) { func Record(ctx context.Context, ms ...Measurement) {
RecordWithOptions(ctx, WithMeasurements(ms...)) // Record behaves the same as RecordWithOptions, but because we do not have to handle generic functionality
// (RecordOptions) we can reduce some allocations to speed up this hot path
if len(ms) == 0 {
return
}
recorder := internal.MeasurementRecorder.(measurementRecorder)
record := false
for _, m := range ms {
if m.desc.subscribed() {
record = true
break
}
}
if !record {
return
}
recorder(tag.FromContext(ctx), ms, nil)
return
} }
// RecordWithTags records one or multiple measurements at once. // RecordWithTags records one or multiple measurements at once.

View File

@ -90,9 +90,9 @@ func Sum() *Aggregation {
// //
// If len(bounds) >= 2 then the boundaries for bucket index i are: // If len(bounds) >= 2 then the boundaries for bucket index i are:
// //
// [-infinity, bounds[i]) for i = 0 // [-infinity, bounds[i]) for i = 0
// [bounds[i-1], bounds[i]) for 0 < i < length // [bounds[i-1], bounds[i]) for 0 < i < length
// [bounds[i-1], +infinity) for i = length // [bounds[i-1], +infinity) for i = length
// //
// If len(bounds) is 0 then there is no histogram associated with the // If len(bounds) is 0 then there is no histogram associated with the
// distribution. There will be a single bucket with boundaries // distribution. There will be a single bucket with boundaries

View File

@ -59,8 +59,15 @@ func (c *collector) clearRows() {
// encodeWithKeys encodes the map by using values // encodeWithKeys encodes the map by using values
// only associated with the keys provided. // only associated with the keys provided.
func encodeWithKeys(m *tag.Map, keys []tag.Key) []byte { func encodeWithKeys(m *tag.Map, keys []tag.Key) []byte {
// Compute the buffer length we will need ahead of time to avoid resizing later
reqLen := 0
for _, k := range keys {
s, _ := m.Value(k)
// We will store each key + its length
reqLen += len(s) + 1
}
vb := &tagencoding.Values{ vb := &tagencoding.Values{
Buffer: make([]byte, len(keys)), Buffer: make([]byte, reqLen),
} }
for _, k := range keys { for _, k := range keys {
v, _ := m.Value(k) v, _ := m.Value(k)

View File

@ -34,7 +34,7 @@
// Libraries can define views but it is recommended that in most cases registering // Libraries can define views but it is recommended that in most cases registering
// views be left up to applications. // views be left up to applications.
// //
// Exporting // # Exporting
// //
// Collected and aggregated data can be exported to a metric collection // Collected and aggregated data can be exported to a metric collection
// backend by registering its exporter. // backend by registering its exporter.

View File

@ -33,6 +33,7 @@ func init() {
defaultWorker = NewMeter().(*worker) defaultWorker = NewMeter().(*worker)
go defaultWorker.start() go defaultWorker.start()
internal.DefaultRecorder = record internal.DefaultRecorder = record
internal.MeasurementRecorder = recordMeasurement
} }
type measureRef struct { type measureRef struct {
@ -199,11 +200,21 @@ func record(tags *tag.Map, ms interface{}, attachments map[string]interface{}) {
defaultWorker.Record(tags, ms, attachments) defaultWorker.Record(tags, ms, attachments)
} }
func recordMeasurement(tags *tag.Map, ms []stats.Measurement, attachments map[string]interface{}) {
defaultWorker.recordMeasurement(tags, ms, attachments)
}
// Record records a set of measurements ms associated with the given tags and 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 interface{}, attachments map[string]interface{}) {
w.recordMeasurement(tags, ms.([]stats.Measurement), attachments)
}
// recordMeasurement records a set of measurements ms associated with the given tags and attachments.
// This is the same as Record but without an interface{} type to avoid allocations
func (w *worker) recordMeasurement(tags *tag.Map, ms []stats.Measurement, attachments map[string]interface{}) {
req := &recordReq{ req := &recordReq{
tm: tags, tm: tags,
ms: ms.([]stats.Measurement), ms: ms,
attachments: attachments, attachments: attachments,
t: time.Now(), t: time.Now(),
} }
@ -221,6 +232,11 @@ func SetReportingPeriod(d time.Duration) {
defaultWorker.SetReportingPeriod(d) defaultWorker.SetReportingPeriod(d)
} }
// Stop stops the default worker.
func Stop() {
defaultWorker.Stop()
}
// SetReportingPeriod sets the interval between reporting aggregated views in // SetReportingPeriod sets the interval between reporting aggregated views in
// the program. If duration is less than or equal to zero, it enables the // the program. If duration is less than or equal to zero, it enables the
// default behavior. // default behavior.
@ -281,7 +297,7 @@ func (w *worker) start() {
case <-w.quit: case <-w.quit:
w.timer.Stop() w.timer.Stop()
close(w.c) close(w.c)
w.done <- true close(w.done)
return return
} }
} }
@ -290,8 +306,11 @@ func (w *worker) start() {
func (w *worker) Stop() { func (w *worker) Stop() {
prodMgr := metricproducer.GlobalManager() prodMgr := metricproducer.GlobalManager()
prodMgr.DeleteProducer(w) prodMgr.DeleteProducer(w)
select {
w.quit <- true case <-w.quit:
default:
close(w.quit)
}
<-w.done <-w.done
} }

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build go1.9
// +build go1.9 // +build go1.9
package tag package tag

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build !go1.9
// +build !go1.9 // +build !go1.9
package tag package tag

13
vendor/go.opencensus.io/trace/doc.go generated vendored
View File

@ -18,24 +18,23 @@ Package trace contains support for OpenCensus distributed tracing.
The following assumes a basic familiarity with OpenCensus concepts. The following assumes a basic familiarity with OpenCensus concepts.
See http://opencensus.io See http://opencensus.io
# Exporting Traces
Exporting Traces
To export collected tracing data, register at least one exporter. You can use To export collected tracing data, register at least one exporter. You can use
one of the provided exporters or write your own. one of the provided exporters or write your own.
trace.RegisterExporter(exporter) trace.RegisterExporter(exporter)
By default, traces will be sampled relatively rarely. To change the sampling By default, traces will be sampled relatively rarely. To change the sampling
frequency for your entire program, call ApplyConfig. Use a ProbabilitySampler frequency for your entire program, call ApplyConfig. Use a ProbabilitySampler
to sample a subset of traces, or use AlwaysSample to collect a trace on every run: to sample a subset of traces, or use AlwaysSample to collect a trace on every run:
trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})
Be careful about using trace.AlwaysSample in a production application with Be careful about using trace.AlwaysSample in a production application with
significant traffic: a new trace will be started and exported for every request. significant traffic: a new trace will be started and exported for every request.
Adding Spans to a Trace # Adding Spans to a Trace
A trace consists of a tree of spans. In Go, the current span is carried in a A trace consists of a tree of spans. In Go, the current span is carried in a
context.Context. context.Context.
@ -44,8 +43,8 @@ It is common to want to capture all the activity of a function call in a span. F
this to work, the function must take a context.Context as a parameter. Add these two this to work, the function must take a context.Context as a parameter. Add these two
lines to the top of the function: lines to the top of the function:
ctx, span := trace.StartSpan(ctx, "example.com/Run") ctx, span := trace.StartSpan(ctx, "example.com/Run")
defer span.End() defer span.End()
StartSpan will create a new top-level span if the context StartSpan will create a new top-level span if the context
doesn't contain another span, otherwise it will create a child span. doesn't contain another span, otherwise it will create a child span.

View File

@ -44,7 +44,7 @@ func (lm lruMap) len() int {
} }
func (lm lruMap) keys() []interface{} { func (lm lruMap) keys() []interface{} {
keys := make([]interface{}, len(lm.cacheKeys)) keys := make([]interface{}, 0, len(lm.cacheKeys))
for k := range lm.cacheKeys { for k := range lm.cacheKeys {
keys = append(keys, k) keys = append(keys, k)
} }

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build go1.11
// +build go1.11 // +build go1.11
package trace package trace

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build !go1.11
// +build !go1.11 // +build !go1.11
package trace package trace

2
vendor/modules.txt vendored
View File

@ -823,7 +823,7 @@ go.etcd.io/etcd/server/v3/proxy/grpcproxy/adapter
go.etcd.io/etcd/server/v3/verify go.etcd.io/etcd/server/v3/verify
go.etcd.io/etcd/server/v3/wal go.etcd.io/etcd/server/v3/wal
go.etcd.io/etcd/server/v3/wal/walpb go.etcd.io/etcd/server/v3/wal/walpb
# go.opencensus.io v0.23.0 # go.opencensus.io v0.24.0
## explicit; go 1.13 ## explicit; go 1.13
go.opencensus.io go.opencensus.io
go.opencensus.io/internal go.opencensus.io/internal