Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
aabmass committed Dec 3, 2021
1 parent 5c3dd54 commit e352050
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
19 changes: 16 additions & 3 deletions exporter/collector/googlecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ type traceExporter struct {
// metricsExporter is a wrapper struct of OC stackdriver exporter
type metricsExporter struct {
mexporter *stackdriver.Exporter

// The metrics exporter pdata to forward implemented requests to. Once implementation is
// complete, the wrapped metricsExporterPdata will completely replace metricsExporter.
googleCloudExporterPdata component.MetricsExporter
}

func (te *traceExporter) Shutdown(ctx context.Context) error {
return te.texporter.Shutdown(ctx)
}

func (me *metricsExporter) Shutdown(context.Context) error {
func (me *metricsExporter) Shutdown(ctx context.Context) error {
me.mexporter.Flush()
me.mexporter.StopMetricsExporter()
return me.mexporter.Close()
if err := me.mexporter.Close(); err != nil {
return err
}
return me.googleCloudExporterPdata.Shutdown(ctx)
}

func setVersionInUserAgent(cfg *Config, version string) {
Expand Down Expand Up @@ -167,12 +174,18 @@ func newGoogleCloudMetricsExporter(cfg *Config, set component.ExporterCreateSett
if serr != nil {
return nil, fmt.Errorf("cannot configure Google Cloud metric exporter: %w", serr)
}
mExp := &metricsExporter{mexporter: sde}

googleCloudExporterPdata, err := newGoogleCloudMetricsExporterPdata(cfg, set)
if err != nil {
return nil, err
}
mExp := &metricsExporter{mexporter: sde, googleCloudExporterPdata: googleCloudExporterPdata}

return exporterhelper.NewMetricsExporter(
cfg,
set,
mExp.pushMetrics,
exporterhelper.WithStart(mExp.googleCloudExporterPdata.Start),
exporterhelper.WithShutdown(mExp.Shutdown),
// Disable exporterhelper Timeout, since we are using a custom mechanism
// within exporter itself
Expand Down
57 changes: 57 additions & 0 deletions exporter/collector/metricsexporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This file contains the rewritten googlecloud metrics exporter which no longer takes
// dependency on the OpenCensus stackdriver exporter.

package collector

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/model/pdata"
)

// metricsExporterPdata is a rewritten GCM exporter that uses pdata directly
type metricsExporterPdata struct {
cfg *Config
}

func (me *metricsExporterPdata) Shutdown(context.Context) error {
return nil
}

func newGoogleCloudMetricsExporterPdata(cfg *Config, set component.ExporterCreateSettings) (component.MetricsExporter, error) {
setVersionInUserAgent(cfg, set.BuildInfo.Version)

mExp := &metricsExporterPdata{
cfg: cfg,
}

return exporterhelper.NewMetricsExporter(
cfg,
set,
mExp.pushMetrics,
exporterhelper.WithShutdown(mExp.Shutdown),
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: defaultTimeout}),
exporterhelper.WithQueue(cfg.QueueSettings),
exporterhelper.WithRetry(cfg.RetrySettings))
}

// pushMetrics calls StackdriverExporter.PushMetricsProto on each element of the given metrics
func (me *metricsExporterPdata) pushMetrics(ctx context.Context, m pdata.Metrics) error {
return nil
}

0 comments on commit e352050

Please sign in to comment.