Skip to content

Commit

Permalink
implement MetricExporter
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencl1013 committed Jul 17, 2020
1 parent 6d9d8d8 commit 5432bae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 2 additions & 4 deletions exporter/stackdriverexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configerror"
"go.opentelemetry.io/collector/config/configmodels"
//"go.uber.org/zap"
)
Expand Down Expand Up @@ -61,7 +60,6 @@ func (f *Factory) CreateMetricsExporter(
_ context.Context,
_ component.ExporterCreateParams,
cfg configmodels.Exporter) (component.MetricsExporter, error) {
// eCfg := cfg.(*Config)
// return newStackdriverMetricsExporter(eCfg)
return nil, configerror.ErrDataTypeIsNotSupported
eCfg := cfg.(*Config)
return newStackdriverMetricsExporter(eCfg)
}
20 changes: 17 additions & 3 deletions exporter/stackdriverexporter/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.opentelemetry.io/collector/component/componenterror"
"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/consumer/pdatautil"
"go.opentelemetry.io/collector/exporter/exporterhelper"
export "go.opentelemetry.io/otel/sdk/export/trace"
"google.golang.org/api/option"
Expand Down Expand Up @@ -86,16 +87,16 @@ func newStackdriverTraceExporter(cfg *Config) (component.TraceExporter, error) {
exporterhelper.WithShutdown(tExp.Shutdown))
}

func newStackdriverMetricsExporter(cfg *Config) (component.MetricsExporterOld, error) {
func newStackdriverMetricsExporter(cfg *Config) (component.MetricsExporter, error) {
sde, serr := newStackdriverExporter(cfg)
if serr != nil {
return nil, fmt.Errorf("cannot configure Stackdriver metric exporter: %v", serr)
}
mExp := &stackdriverExporter{exporter: sde}

return exporterhelper.NewMetricsExporterOld(
return exporterhelper.NewMetricsExporter(
cfg,
mExp.pushMetricsData,
mExp.pushMetrics,
exporterhelper.WithShutdown(mExp.Shutdown))
}

Expand Down Expand Up @@ -145,6 +146,19 @@ func (se *stackdriverExporter) pushMetricsData(ctx context.Context, md consumerd
return se.exporter.PushMetricsProto(ctx, md.Node, md.Resource, md.Metrics)
}

func (se *stackdriverExporter) pushMetrics(ctx context.Context, m pdata.Metrics) (int, error) {
mds := pdatautil.MetricsToMetricsData(m)
dropped := 0
for _, md := range mds {
d, err := se.pushMetricsData(ctx, md)
dropped += d
if err != nil {
return dropped, err
}
}
return dropped, nil
}

// pushTraceData is a wrapper method on StackdriverExporter.PushTraceSpans
func (se *stackdriverExporter) pushTraceData(ctx context.Context, td consumerdata.TraceData) (int, error) {
var errs []error
Expand Down

0 comments on commit 5432bae

Please sign in to comment.