mirror of
https://github.com/golang/go
synced 2024-11-18 16:24:42 -07:00
internal/telemetry: remove the concept of a Tagger
The Tagger interface allowed for specifying a key in a tag list and having the value be aquired from the context automatically. It was almost never used, and the alternative (using the key to get the value) is not that much more long winded, so it was not holding it's own weight from a complexity persective alone but the performance cost of having to use a list of interface rather than a list of tags was very large. See the benchstat improvements below for the difference it makes to both speed and memory usage, especially in the no exporter case. name old time/op new time/op delta Baseline-8 341ns ± 2% 342ns ± 1% ~ (p=0.139 n=19+18) LoggingNoExporter-8 2.46µs ± 5% 1.97µs ± 3% -19.88% (p=0.000 n=19+20) Logging-8 13.3µs ± 2% 12.8µs ± 2% -3.42% (p=0.000 n=17+20) LoggingStdlib-8 5.39µs ± 6% 5.34µs ± 3% ~ (p=0.692 n=20+19) name old alloc/op new alloc/op delta Baseline-8 80.0B ± 0% 80.0B ± 0% ~ (all equal) LoggingNoExporter-8 728B ± 0% 440B ± 0% -39.56% (p=0.000 n=20+20) Logging-8 2.75kB ± 0% 2.46kB ± 0% -10.53% (p=0.000 n=17+20) LoggingStdlib-8 568B ± 0% 568B ± 0% ~ (all equal) name old allocs/op new allocs/op delta Baseline-8 5.00 ± 0% 5.00 ± 0% ~ (all equal) LoggingNoExporter-8 32.0 ± 0% 23.0 ± 0% -28.12% (p=0.000 n=20+20) Logging-8 88.0 ± 0% 79.0 ± 0% -10.23% (p=0.000 n=20+20) LoggingStdlib-8 28.0 ± 0% 28.0 ± 0% ~ (all equal) Change-Id: Ic203ad0c5de7451348976b999a0d038ac532dc39 Reviewed-on: https://go-review.googlesource.com/c/tools/+/221737 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
parent
ae19ec7143
commit
a1c56757aa
@ -203,7 +203,7 @@ func (s *Server) publishReports(ctx context.Context, snapshot source.Snapshot, r
|
|||||||
Version: key.id.Version,
|
Version: key.id.Version,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
if ctx.Err() == nil {
|
if ctx.Err() == nil {
|
||||||
log.Error(ctx, "publishReports: failed to deliver diagnostic", err, telemetry.File)
|
log.Error(ctx, "publishReports: failed to deliver diagnostic", err, telemetry.File.Tag(ctx))
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/tools/internal/telemetry"
|
"golang.org/x/tools/internal/telemetry"
|
||||||
"golang.org/x/tools/internal/telemetry/export"
|
"golang.org/x/tools/internal/telemetry/export"
|
||||||
"golang.org/x/tools/internal/telemetry/tag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event telemetry.Event
|
type Event telemetry.Event
|
||||||
@ -27,18 +26,18 @@ func With(ctx context.Context, tags ...telemetry.Tag) {
|
|||||||
|
|
||||||
// Print takes a message and a tag list and combines them into a single tag
|
// Print takes a message and a tag list and combines them into a single tag
|
||||||
// list before delivering them to the loggers.
|
// list before delivering them to the loggers.
|
||||||
func Print(ctx context.Context, message string, tags ...tag.Tagger) {
|
func Print(ctx context.Context, message string, tags ...telemetry.Tag) {
|
||||||
export.Log(ctx, telemetry.Event{
|
export.Log(ctx, telemetry.Event{
|
||||||
At: time.Now(),
|
At: time.Now(),
|
||||||
Message: message,
|
Message: message,
|
||||||
Tags: tag.Tags(ctx, tags...),
|
Tags: tags,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error takes a message and a tag list and combines them into a single tag
|
// Error takes a message and a tag list and combines them into a single tag
|
||||||
// list before delivering them to the loggers. It captures the error in the
|
// list before delivering them to the loggers. It captures the error in the
|
||||||
// delivered event.
|
// delivered event.
|
||||||
func Error(ctx context.Context, message string, err error, tags ...tag.Tagger) {
|
func Error(ctx context.Context, message string, err error, tags ...telemetry.Tag) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = errorString(message)
|
err = errorString(message)
|
||||||
message = ""
|
message = ""
|
||||||
@ -47,7 +46,7 @@ func Error(ctx context.Context, message string, err error, tags ...tag.Tagger) {
|
|||||||
At: time.Now(),
|
At: time.Now(),
|
||||||
Message: message,
|
Message: message,
|
||||||
Error: err,
|
Error: err,
|
||||||
Tags: tag.Tags(ctx, tags...),
|
Tags: tags,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
package telemetry
|
package telemetry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,12 +25,6 @@ func (t Tag) Format(f fmt.State, r rune) {
|
|||||||
fmt.Fprintf(f, `%v="%v"`, t.Key, t.Value)
|
fmt.Fprintf(f, `%v="%v"`, t.Key, t.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tag returns the tag unmodified.
|
|
||||||
// It makes Key conform to the Tagger interface.
|
|
||||||
func (t Tag) Tag(ctx context.Context) Tag {
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get will get a single key's value from the list.
|
// Get will get a single key's value from the list.
|
||||||
func (l TagList) Get(k interface{}) interface{} {
|
func (l TagList) Get(k interface{}) interface{} {
|
||||||
for _, t := range l {
|
for _, t := range l {
|
||||||
|
@ -18,14 +18,6 @@ import (
|
|||||||
//TODO: Do we need to do something more efficient than just store tags
|
//TODO: Do we need to do something more efficient than just store tags
|
||||||
//TODO: directly on the context?
|
//TODO: directly on the context?
|
||||||
|
|
||||||
// Tagger is the interface to something that returns a Tag given a context.
|
|
||||||
// Both Tag itself and Key support this interface, allowing methods that can
|
|
||||||
// take either (and other implementations as well)
|
|
||||||
type Tagger interface {
|
|
||||||
// Tag returns a Tag potentially using information from the Context.
|
|
||||||
Tag(context.Context) telemetry.Tag
|
|
||||||
}
|
|
||||||
|
|
||||||
// With is roughly equivalent to context.WithValue except that it also notifies
|
// With is roughly equivalent to context.WithValue except that it also notifies
|
||||||
// registered observers.
|
// registered observers.
|
||||||
// Unlike WithValue, it takes a list of tags so that you can set many values
|
// Unlike WithValue, it takes a list of tags so that you can set many values
|
||||||
@ -48,12 +40,3 @@ func Get(ctx context.Context, keys ...interface{}) telemetry.TagList {
|
|||||||
}
|
}
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tags collects a list of tags for the taggers from the context.
|
|
||||||
func Tags(ctx context.Context, taggers ...Tagger) telemetry.TagList {
|
|
||||||
tags := make(telemetry.TagList, len(taggers))
|
|
||||||
for i, t := range taggers {
|
|
||||||
tags[i] = t.Tag(ctx)
|
|
||||||
}
|
|
||||||
return tags
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user