Skip to content

Commit

Permalink
googlecloud: renamed stackdriver exporter to googlecloud (2 of 2) (#2713
Browse files Browse the repository at this point in the history
)

* add back deprecated stackdriverexporter which wraps googlecloudexporter

* use delegate

* Apply suggestions from code review

Co-authored-by: Punya Biswal <[email protected]>

* Address punya's comment, log deprecation warning

Co-authored-by: Punya Biswal <[email protected]>
  • Loading branch information
aabmass and punya authored Mar 19, 2021
1 parent afb4224 commit 48cbeb5
Show file tree
Hide file tree
Showing 10 changed files with 1,800 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ updates:
directory: "/exporter/splunkhecexporter"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/exporter/stackdriverexporter"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/exporter/sumologicexporter"
schedule:
Expand Down
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sentryexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/splunkhecexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/stackdriverexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/httpforwarder"
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/hostobserver"
Expand Down Expand Up @@ -151,6 +152,7 @@ func components() (component.Factories, error) {
sentryexporter.NewFactory(),
signalfxexporter.NewFactory(),
splunkhecexporter.NewFactory(),
stackdriverexporter.NewFactory(),
sumologicexporter.NewFactory(),
}
for _, exp := range factories.Exporters {
Expand Down
1 change: 1 addition & 0 deletions exporter/stackdriverexporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
33 changes: 33 additions & 0 deletions exporter/stackdriverexporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Deprecated Stackdriver Exporter

This exporter has been renamed to the [Google Cloud exporter](../googlecloudexporter/README.md).
`stackdriver` exporter configurations will continue to work for the sake of backwards compatibility.

`stackdriver` exporter supports the same configuration options as [Google Cloud
exporter](../googlecloudexporter/README.md).

# Recommendations

Please use the [Google Cloud exporter](../googlecloudexporter/README.md) or migrate to it by
changing the exporter entry in your config from `stackdriver` to `googlecloud` and updating your
pipelines to use this new key. All other configuration can rename the same. An example migration
diff might look like this:

```diff
exporters:
- stackdriver:
+ googlecloud
project: otel-starter-project
use_insecure: false

processors:
batch:

service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
- exporters: [stackdriver]
+ exporters: [googlecloud]
```
76 changes: 76 additions & 0 deletions exporter/stackdriverexporter/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2021, OpenTelemetry Authors
//
// 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
//
// http://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.

package stackdriverexporter

import (
"context"
"sync"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmodels"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter"
)

type factory struct {
component.ExporterFactory
}

const (
// The value of "type" key in configuration.
typeVal = configmodels.Type("stackdriver")
)

var once sync.Once

// NewFactory creates a factory for the stackdriver exporter
func NewFactory() component.ExporterFactory {
return &factory{ExporterFactory: googlecloudexporter.NewFactory()}
}

func logDeprecation(logger *zap.Logger) {
once.Do(func() {
logger.Warn("stackdriver exporter is deprecated. Use googlecloudexporter instead.")
})
}

func (f *factory) Type() configmodels.Type {
return typeVal
}

func (f *factory) CreateDefaultConfig() configmodels.Exporter {
cfg := f.ExporterFactory.CreateDefaultConfig()
cfg.(*googlecloudexporter.Config).TypeVal = f.Type()
return cfg
}

func (f *factory) CreateTracesExporter(
ctx context.Context,
params component.ExporterCreateParams,
cfg configmodels.Exporter,
) (component.TracesExporter, error) {
logDeprecation(params.Logger)
return f.ExporterFactory.CreateTracesExporter(ctx, params, cfg)
}

func (f *factory) CreateMetricsExporter(
ctx context.Context,
params component.ExporterCreateParams,
cfg configmodels.Exporter,
) (component.MetricsExporter, error) {
logDeprecation(params.Logger)
return f.ExporterFactory.CreateMetricsExporter(ctx, params, cfg)
}
58 changes: 58 additions & 0 deletions exporter/stackdriverexporter/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2019, OpenTelemetry Authors
//
// 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
//
// http://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.

package stackdriverexporter

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configcheck"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter"
)

func TestCreateDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
assert.NoError(t, configcheck.ValidateConfig(cfg))
}

func TestCreateExporter(t *testing.T) {
if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
t.Skip("Default credentials not set, skip creating Stackdriver exporter")
}
ctx := context.Background()
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
eCfg := cfg.(*googlecloudexporter.Config)
eCfg.ProjectID = "test"

te, err := factory.CreateTracesExporter(ctx, component.ExporterCreateParams{
Logger: zap.NewNop(),
}, eCfg)
assert.Nil(t, err)
assert.NotNil(t, te, "failed to create trace exporter")

me, err := factory.CreateMetricsExporter(ctx, component.ExporterCreateParams{
Logger: zap.NewNop(),
}, eCfg)
assert.Nil(t, err)
assert.NotNil(t, me, "failed to create metrics exporter")
}
12 changes: 12 additions & 0 deletions exporter/stackdriverexporter/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/exporter/stackdriverexporter

go 1.16

require (
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter v0.0.0-00010101000000-000000000000
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/collector v0.22.1-0.20210313012550-03904de3dd61
go.uber.org/zap v1.16.0
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter => ../googlecloudexporter
Loading

0 comments on commit 48cbeb5

Please sign in to comment.