Skip to content

Commit

Permalink
[extension/googleclientauth] Add GCP auth extension implementation (#…
Browse files Browse the repository at this point in the history
…32029)

**Description:**
Follow up to boilerplate PR
#31518
This adds the functions calls to actually implement the extension using
our downstream libraries.

It also enables the shutdown tests for this extension (lifecycle tests
do not seem possible for us currently)

**Link to tracking Issue:** n/a

**Testing:** downstream unit and integration tests, shutdown tests here

**Documentation:** Here and downstream READMEs
  • Loading branch information
damemi committed Apr 15, 2024
1 parent 6876ca7 commit 7608ecb
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 11 deletions.
27 changes: 27 additions & 0 deletions .chloggen/gcp-auth-extension-impl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: new_component

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: googleclientauthextension

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add implementation of Google Client Auth Extension.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32029]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
10 changes: 10 additions & 0 deletions extension/googleclientauthextension/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@

package googleclientauthextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/googleclientauthextension"

import (
"fmt"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension"
)

// Config defines configuration for the Google client auth extension.
type Config struct {
googleclientauthextension.Config `mapstructure:",squash"`
}

func (cfg *Config) Validate() error {
if err := cfg.Config.Validate(); err != nil {
return fmt.Errorf("googlecloud exporter settings are invalid :%w", err)
}
return nil
}
46 changes: 46 additions & 0 deletions extension/googleclientauthextension/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package googleclientauthextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/googleclientauthextension"

import (
"path/filepath"
"testing"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"

"github.com/open-telemetry/opentelemetry-collector-contrib/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{
Config: googleclientauthextension.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())
}
20 changes: 15 additions & 5 deletions extension/googleclientauthextension/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@ package googleclientauthextension // import "github.com/open-telemetry/opentelem
import (
"context"

"github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/extension/auth"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/googleclientauthextension/internal/metadata"
)

func NewFactory() extension.Factory {
return extension.NewFactory(
metadata.Type,
func() component.Config { return &Config{} },
func(context.Context, extension.CreateSettings, component.Config) (extension.Extension, error) {
return auth.NewClient(), nil
},
createDefaultConfig,
createExtension,
metadata.ExtensionStability,
)
}

func createExtension(ctx context.Context, set extension.CreateSettings, cfg component.Config) (component.Component, error) {
eCfg := cfg.(*Config)
return googleclientauthextension.CreateExtension(ctx, set, &eCfg.Config)
}

func createDefaultConfig() component.Config {
cfg := googleclientauthextension.CreateDefaultConfig().(*googleclientauthextension.Config)
return &Config{
Config: *cfg,
}
}
21 changes: 21 additions & 0 deletions extension/googleclientauthextension/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions extension/googleclientauthextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ go 1.21
exclude github.com/knadh/koanf v1.5.0

require (
github.com/GoogleCloudPlatform/opentelemetry-operations-go/extension/googleclientauthextension v0.46.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.98.1-0.20240412014414-62f589864e3d
go.opentelemetry.io/collector/confmap v0.98.1-0.20240412014414-62f589864e3d
go.opentelemetry.io/collector/extension v0.98.1-0.20240412014414-62f589864e3d
go.opentelemetry.io/collector/extension/auth v0.98.1-0.20240412014414-62f589864e3d
go.opentelemetry.io/otel/metric v1.25.0
go.opentelemetry.io/otel/trace v1.25.0
go.uber.org/goleak v1.3.0
)

require (
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect
github.com/knadh/koanf/v2 v2.1.1 // indirect
Expand All @@ -33,7 +38,6 @@ require (
github.com/prometheus/common v0.52.3 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.98.1-0.20240412014414-62f589864e3d // indirect
go.opentelemetry.io/collector/confmap v0.98.1-0.20240412014414-62f589864e3d // indirect
go.opentelemetry.io/collector/pdata v1.5.1-0.20240412014414-62f589864e3d // indirect
go.opentelemetry.io/otel v1.25.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.47.0 // indirect
Expand All @@ -42,8 +46,10 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
36 changes: 34 additions & 2 deletions extension/googleclientauthextension/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions extension/googleclientauthextension/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ status:
active: [dashpole, damemi, aabmass, jsuereth, punya, psx95]

tests:
skip_lifecycle: true # in development
skip_shutdown: true # in development
skip_lifecycle: true
7 changes: 7 additions & 0 deletions extension/googleclientauthextension/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
googleclientauth:
googleclientauth/customname:
project: my-project
scopes:
- "https://www.something.com/hello"
- "https://www.something.com/world"
quota_project: other-project

0 comments on commit 7608ecb

Please sign in to comment.