1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-25 22:41:46 +02:00

[metrics] standardize/simplify export pipeline setup (#395)

* Introduce simplified export pipeline setup for stdout

* Standardize dogstatsd,stdout,prometheus calling.

* Creates NewRawExporter, NewExportPipeline, InstallNewPipeline methods.
* Uses Options rather than Config throughout for options.

* fix merge conflicts.

Co-authored-by: Liz Fong-Jones <elizabeth@ctyalcove.org>
This commit is contained in:
Matej Gera
2020-01-02 19:41:21 +01:00
committed by Joshua MacDonald
parent 5eb457a119
commit 067aa9e142
14 changed files with 220 additions and 111 deletions

View File

@@ -17,7 +17,6 @@ package main
import (
"context"
"log"
"time"
"go.opentelemetry.io/otel/api/distributedcontext"
"go.opentelemetry.io/otel/api/global"
@@ -26,10 +25,7 @@ import (
"go.opentelemetry.io/otel/api/trace"
metricstdout "go.opentelemetry.io/otel/exporter/metric/stdout"
tracestdout "go.opentelemetry.io/otel/exporter/trace/stdout"
metricsdk "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/batcher/defaultkeys"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
@@ -57,19 +53,13 @@ func initTracer() {
}
func initMeter() *push.Controller {
selector := simple.NewWithExactMeasure()
exporter, err := metricstdout.New(metricstdout.Options{
pusher, err := metricstdout.InstallNewPipeline(metricstdout.Options{
Quantiles: []float64{0.5, 0.9, 0.99},
PrettyPrint: false,
})
if err != nil {
log.Panicf("failed to initialize metric stdout exporter %v", err)
}
batcher := defaultkeys.New(selector, metricsdk.NewDefaultLabelEncoder(), true)
pusher := push.New(batcher, exporter, time.Second)
pusher.Start()
global.SetMeterProvider(pusher)
return pusher
}

View File

@@ -24,10 +24,7 @@ import (
"go.opentelemetry.io/otel/api/key"
"go.opentelemetry.io/otel/api/metric"
"go.opentelemetry.io/otel/exporter/metric/prometheus"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/batcher/defaultkeys"
"go.opentelemetry.io/otel/sdk/metric/controller/push"
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
)
var (
@@ -37,29 +34,15 @@ var (
)
func initMeter() *push.Controller {
selector := simple.NewWithExactMeasure()
exporter, err := prometheus.NewExporter(prometheus.Options{})
pusher, hf, err := prometheus.InstallNewPipeline(prometheus.Options{})
if err != nil {
log.Panicf("failed to initialize metric stdout exporter %v", err)
log.Panicf("failed to initialize prometheus exporter %v", err)
}
// Prometheus needs to use a stateful batcher since counters (and histogram since they are a collection of Counters)
// are cumulative (i.e., monotonically increasing values) and should not be resetted after each export.
//
// Prometheus uses this approach to be resilient to scrape failures.
// If a Prometheus server tries to scrape metrics from a host and fails for some reason,
// it could try again on the next scrape and no data would be lost, only resolution.
//
// Gauges (or LastValues) and Summaries are an exception to this and have different behaviors.
batcher := defaultkeys.New(selector, sdkmetric.NewDefaultLabelEncoder(), true)
pusher := push.New(batcher, exporter, time.Second)
pusher.Start()
http.HandleFunc("/", hf)
go func() {
_ = http.ListenAndServe(":2222", exporter)
_ = http.ListenAndServe(":2222", nil)
}()
global.SetMeterProvider(pusher)
return pusher
}