From d2a1f1a7e16b5417dd7f6456adb30118786f09d6 Mon Sep 17 00:00:00 2001 From: Mike Dame Date: Mon, 29 Apr 2024 17:45:23 +0000 Subject: [PATCH 1/2] Remove unneeded Auth Extension files --- extension/googleclientauthextension/README.md | 10 ---- .../googleclientauthextension/config_test.go | 57 ------------------- .../googleclientauthextension/factory.go | 12 ---- .../googleclientauthextension/factory_test.go | 21 +++++-- extension/googleclientauthextension/go.mod | 2 +- .../internal/metadata/status.go | 27 --------- .../testdata/config.yaml | 7 --- 7 files changed, 17 insertions(+), 119 deletions(-) delete mode 100644 extension/googleclientauthextension/config_test.go delete mode 100644 extension/googleclientauthextension/internal/metadata/status.go delete mode 100644 extension/googleclientauthextension/testdata/config.yaml diff --git a/extension/googleclientauthextension/README.md b/extension/googleclientauthextension/README.md index a4e8b7714..53f8f6c40 100644 --- a/extension/googleclientauthextension/README.md +++ b/extension/googleclientauthextension/README.md @@ -41,13 +41,3 @@ Following are the configuration fields: - **project** - The Google Cloud Project telemetry is sent to if the gcp.project.id resource attribute is not set. If unspecified, this is determined using application default credentials. - [**scopes**](https://datatracker.ietf.org/doc/html/rfc6749#section-3.3) - The oauth 2.0 scopes requested by the extension. - [**quota_project**](https://cloud.google.com/apis/docs/system-parameters) - The project for quota and billing purposes. The caller must have serviceusage.services.use permission on the project. - -## Building into a Collector - -This extension is not included in any collector distributions today. To build a collector with this component, add the following to your collector builder configuration: - -```yaml -extensions: - - import: github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension - gomod: github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension v0.43.0 -``` diff --git a/extension/googleclientauthextension/config_test.go b/extension/googleclientauthextension/config_test.go deleted file mode 100644 index 364493dae..000000000 --- a/extension/googleclientauthextension/config_test.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2023 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 -// -// 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 googleclientauthextension // import "github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension" - -import ( - "path/filepath" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/confmap/confmaptest" - - "github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension/internal/metadata" -) - -func TestLoadConfig(t *testing.T) { - cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) - require.NoError(t, err) - factory := NewFactory() - cfg := factory.CreateDefaultConfig() - - sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) - require.NoError(t, err) - require.NoError(t, component.UnmarshalConfig(sub, cfg)) - - assert.Equal(t, cfg.(*Config), factory.CreateDefaultConfig().(*Config)) - - sub, err = cm.Sub(component.NewIDWithName(metadata.Type, "customname").String()) - require.NoError(t, err) - require.NoError(t, component.UnmarshalConfig(sub, cfg)) - - assert.Equal(t, - &Config{ - Project: "my-project", - Scopes: []string{"https://www.something.com/hello", "https://www.something.com/world"}, - QuotaProject: "other-project", - }, - cfg, - ) -} - -func TestValidate(t *testing.T) { - assert.NoError(t, NewFactory().CreateDefaultConfig().(*Config).Validate()) -} diff --git a/extension/googleclientauthextension/factory.go b/extension/googleclientauthextension/factory.go index 773ed1351..bcff89135 100644 --- a/extension/googleclientauthextension/factory.go +++ b/extension/googleclientauthextension/factory.go @@ -23,20 +23,8 @@ import ( "go.opentelemetry.io/collector/extension" "golang.org/x/oauth2/google" "google.golang.org/grpc/credentials/oauth" - - "github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension/internal/metadata" ) -// NewFactory creates a factory for the GCP Auth extension. -func NewFactory() extension.Factory { - return extension.NewFactory( - metadata.Type, - CreateDefaultConfig, - CreateExtension, - metadata.ExtensionStability, - ) -} - func CreateExtension(ctx context.Context, set extension.CreateSettings, cfg component.Config) (extension.Extension, error) { config := cfg.(*Config) ca := &clientAuthenticator{ diff --git a/extension/googleclientauthextension/factory_test.go b/extension/googleclientauthextension/factory_test.go index f49268972..07435908a 100644 --- a/extension/googleclientauthextension/factory_test.go +++ b/extension/googleclientauthextension/factory_test.go @@ -19,32 +19,43 @@ import ( "testing" "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/extension" ) +// newFactory creates a factory for the GCP Auth extension. +func newFactory() extension.Factory { + return extension.NewFactory( + component.MustNewType("googleclientauth"), + CreateDefaultConfig, + CreateExtension, + component.StabilityLevelAlpha, + ) +} + func TestCreateDefaultConfig(t *testing.T) { - factory := NewFactory() + factory := newFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } func TestNewFactory(t *testing.T) { - f := NewFactory() + f := newFactory() assert.NotNil(t, f) } func TestCreateExtension(t *testing.T) { t.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "testdata/fake_creds.json") - ext, err := NewFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) + ext, err := newFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) assert.NotNil(t, ext) assert.NoError(t, err) } func TestStart(t *testing.T) { t.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "testdata/fake_creds.json") - ext, err := NewFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) + ext, err := newFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) assert.NotNil(t, ext) assert.NoError(t, err) err = ext.Start(context.Background(), nil) @@ -53,7 +64,7 @@ func TestStart(t *testing.T) { func TestStart_WithError(t *testing.T) { t.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "testdata/foo.json") - ext, err := NewFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) + ext, err := newFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) assert.NotNil(t, ext) assert.NoError(t, err) err = ext.Start(context.Background(), nil) diff --git a/extension/googleclientauthextension/go.mod b/extension/googleclientauthextension/go.mod index 36075183e..5a176b5b3 100644 --- a/extension/googleclientauthextension/go.mod +++ b/extension/googleclientauthextension/go.mod @@ -5,7 +5,6 @@ go 1.21 require ( github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.99.0 - go.opentelemetry.io/collector/confmap v0.99.0 go.opentelemetry.io/collector/extension v0.94.0 golang.org/x/oauth2 v0.18.0 google.golang.org/grpc v1.63.2 @@ -33,6 +32,7 @@ require ( github.com/prometheus/common v0.52.3 // indirect github.com/prometheus/procfs v0.12.0 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.99.0 // indirect + go.opentelemetry.io/collector/confmap v0.99.0 // indirect go.opentelemetry.io/collector/pdata v1.6.0 // indirect go.opentelemetry.io/otel v1.25.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.47.0 // indirect diff --git a/extension/googleclientauthextension/internal/metadata/status.go b/extension/googleclientauthextension/internal/metadata/status.go deleted file mode 100644 index 20ff7ac7a..000000000 --- a/extension/googleclientauthextension/internal/metadata/status.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2023 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 -// -// 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 metadata - -import ( - "go.opentelemetry.io/collector/component" -) - -var ( - Type = component.MustNewType("googleclientauth") -) - -const ( - ExtensionStability = component.StabilityLevelAlpha -) diff --git a/extension/googleclientauthextension/testdata/config.yaml b/extension/googleclientauthextension/testdata/config.yaml deleted file mode 100644 index c9c0cdb6d..000000000 --- a/extension/googleclientauthextension/testdata/config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -googleclientauth: -googleclientauth/customname: - project: my-project - scopes: - - "https://www.something.com/hello" - - "https://www.something.com/world" - quota_project: other-project From c600631eb8e94181368ec2d0ece184d5b3a422d5 Mon Sep 17 00:00:00 2001 From: Mike Dame Date: Tue, 30 Apr 2024 14:23:39 +0000 Subject: [PATCH 2/2] feedback --- .../googleclientauthextension/factory_test.go | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/extension/googleclientauthextension/factory_test.go b/extension/googleclientauthextension/factory_test.go index 07435908a..3481ea378 100644 --- a/extension/googleclientauthextension/factory_test.go +++ b/extension/googleclientauthextension/factory_test.go @@ -19,43 +19,26 @@ import ( "testing" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/extension" ) -// newFactory creates a factory for the GCP Auth extension. -func newFactory() extension.Factory { - return extension.NewFactory( - component.MustNewType("googleclientauth"), - CreateDefaultConfig, - CreateExtension, - component.StabilityLevelAlpha, - ) -} - func TestCreateDefaultConfig(t *testing.T) { - factory := newFactory() - cfg := factory.CreateDefaultConfig() + cfg := CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } -func TestNewFactory(t *testing.T) { - f := newFactory() - assert.NotNil(t, f) -} - func TestCreateExtension(t *testing.T) { t.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "testdata/fake_creds.json") - ext, err := newFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) + ext, err := CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) assert.NotNil(t, ext) assert.NoError(t, err) } func TestStart(t *testing.T) { t.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "testdata/fake_creds.json") - ext, err := newFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) + ext, err := CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) assert.NotNil(t, ext) assert.NoError(t, err) err = ext.Start(context.Background(), nil) @@ -64,7 +47,7 @@ func TestStart(t *testing.T) { func TestStart_WithError(t *testing.T) { t.Setenv("GOOGLE_APPLICATION_CREDENTIALS", "testdata/foo.json") - ext, err := newFactory().CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) + ext, err := CreateExtension(context.Background(), extension.CreateSettings{}, CreateDefaultConfig()) assert.NotNil(t, ext) assert.NoError(t, err) err = ext.Start(context.Background(), nil)