1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:14:46 -07:00

internal/telemetry: remove Flush method from exporter

It is never invoked anyway, and it provices no useful benefit while complicating
the implementation, as it is the only non context aware method.

Change-Id: Id5a99439fedafdf4d71285e36103b4854cf3635a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/221540
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
Ian Cottrell 2020-02-28 14:08:49 -05:00
parent a628ca32eb
commit 71482053b8
5 changed files with 11 additions and 31 deletions

View File

@ -49,7 +49,7 @@ type Instance struct {
LogWriter io.Writer
ocagent export.Exporter
ocagent *ocagent.Exporter
prometheus *prometheus.Exporter
rpcs *rpcs
traces *traces
@ -540,12 +540,6 @@ func (i *Instance) Metric(ctx context.Context, data telemetry.MetricData) {
}
}
func (i *Instance) Flush() {
if i.ocagent != nil {
i.ocagent.Flush()
}
}
type dataFunc func(*http.Request) interface{}
func render(tmpl *template.Template, fun dataFunc) func(http.ResponseWriter, *http.Request) {

View File

@ -26,8 +26,6 @@ type Exporter interface {
Log(context.Context, telemetry.Event)
Metric(context.Context, telemetry.MetricData)
Flush()
}
var (
@ -107,12 +105,3 @@ func Metric(ctx context.Context, data telemetry.MetricData) {
}
exporter.Metric(ctx, data)
}
func Flush() {
exporterMu.Lock()
defer exporterMu.Unlock()
if exporter == nil {
return
}
exporter.Flush()
}

View File

@ -34,4 +34,3 @@ func (w *logWriter) Log(ctx context.Context, event telemetry.Event) {
fmt.Fprintf(w.writer, "%v\n", event)
}
func (w *logWriter) Metric(context.Context, telemetry.MetricData) {}
func (w *logWriter) Flush() {}

View File

@ -19,7 +19,6 @@ import (
"time"
"golang.org/x/tools/internal/telemetry"
"golang.org/x/tools/internal/telemetry/export"
"golang.org/x/tools/internal/telemetry/export/ocagent/wire"
"golang.org/x/tools/internal/telemetry/tag"
)
@ -43,7 +42,7 @@ func Discover() *Config {
}
}
type exporter struct {
type Exporter struct {
mu sync.Mutex
config Config
spans []*telemetry.Span
@ -53,11 +52,11 @@ type exporter struct {
// Connect creates a process specific exporter with the specified
// serviceName and the address of the ocagent to which it will upload
// its telemetry.
func Connect(config *Config) export.Exporter {
func Connect(config *Config) *Exporter {
if config == nil || config.Address == "off" {
return nil
}
exporter := &exporter{config: *config}
exporter := &Exporter{config: *config}
if exporter.config.Start.IsZero() {
exporter.config.Start = time.Now()
}
@ -85,23 +84,23 @@ func Connect(config *Config) export.Exporter {
return exporter
}
func (e *exporter) StartSpan(ctx context.Context, span *telemetry.Span) {}
func (e *Exporter) StartSpan(ctx context.Context, span *telemetry.Span) {}
func (e *exporter) FinishSpan(ctx context.Context, span *telemetry.Span) {
func (e *Exporter) FinishSpan(ctx context.Context, span *telemetry.Span) {
e.mu.Lock()
defer e.mu.Unlock()
e.spans = append(e.spans, span)
}
func (e *exporter) Log(context.Context, telemetry.Event) {}
func (e *Exporter) Log(context.Context, telemetry.Event) {}
func (e *exporter) Metric(ctx context.Context, data telemetry.MetricData) {
func (e *Exporter) Metric(ctx context.Context, data telemetry.MetricData) {
e.mu.Lock()
defer e.mu.Unlock()
e.metrics = append(e.metrics, data)
}
func (e *exporter) Flush() {
func (e *Exporter) Flush() {
e.mu.Lock()
defer e.mu.Unlock()
spans := make([]*wire.Span, len(e.spans))
@ -149,7 +148,7 @@ func (cfg *Config) buildNode() *wire.Node {
}
}
func (e *exporter) send(endpoint string, message interface{}) {
func (e *Exporter) send(endpoint string, message interface{}) {
blob, err := json.Marshal(message)
if err != nil {
errorInExport("ocagent failed to marshal message for %v: %v", endpoint, err)

View File

@ -17,13 +17,12 @@ import (
"time"
"golang.org/x/tools/internal/telemetry"
"golang.org/x/tools/internal/telemetry/export"
"golang.org/x/tools/internal/telemetry/export/ocagent"
"golang.org/x/tools/internal/telemetry/tag"
)
var (
exporter export.Exporter
exporter *ocagent.Exporter
sent fakeSender
start time.Time
at time.Time