Skip to content

Commit

Permalink
[pkg/stanza] Use storage extension only if specified
Browse files Browse the repository at this point in the history
Previous behavior allowed stanza-based receivers to automatically
detect and use a storage extension. This implicit behavior was not
clear and precluded the abilty to choose one of multiple storage
extensions. This change adds a 'storage' field to stanza-based
receivers and requires the user to name the extension that should
be used.
  • Loading branch information
djaglowski committed Aug 22, 2022
1 parent b3e9863 commit 8c3a416
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
3 changes: 1 addition & 2 deletions pkg/stanza/adapter/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"context"
"testing"

"go.opentelemetry.io/collector/config"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer/consumertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/storagetest"
Expand Down
23 changes: 21 additions & 2 deletions receiver/otlpjsonfilereceiver/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ package otlpjsonfilereceiver // import "github.com/open-telemetry/opentelemetry-

import (
"context"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/extension/experimental/storage"
"go.opentelemetry.io/collector/obsreport"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer"
)

Expand Down Expand Up @@ -65,7 +66,7 @@ type receiver struct {
}

func (f *receiver) Start(ctx context.Context, host component.Host) error {
storageClient, err := adapter.GetStorageClient(ctx, f.id, component.KindReceiver, host)
storageClient, err := f.storageClient(ctx, host)
if err != nil {
return err
}
Expand All @@ -76,6 +77,24 @@ func (f *receiver) Shutdown(ctx context.Context) error {
return f.input.Stop()
}

func (f *receiver) storageClient(ctx context.Context, host component.Host) (storage.Client, error) {
if f.storageID == nil {
return storage.NewNopClient(), nil
}

extension, ok := host.GetExtensions()[*f.storageID]
if !ok {
return nil, fmt.Errorf("storage extension '%s' not found", f.storageID)
}

storageExtension, ok := extension.(storage.Extension)
if !ok {
return nil, fmt.Errorf("non-storage extension '%s' found", f.storageID)
}

return storageExtension.GetClient(ctx, component.KindReceiver, f.id, "")
}

func createLogsReceiver(_ context.Context, settings component.ReceiverCreateSettings, configuration config.Receiver, logs consumer.Logs) (component.LogsReceiver, error) {
logsUnmarshaler := plog.NewJSONUnmarshaler()
obsrecv := obsreport.NewReceiver(obsreport.ReceiverSettings{
Expand Down
2 changes: 0 additions & 2 deletions receiver/otlpjsonfilereceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ require (
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
gonum.org/v1/gonum v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
4 changes: 0 additions & 4 deletions receiver/otlpjsonfilereceiver/go.sum

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

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ component: pkg/stanza
note: Update function and struct names in keyvalue parser

# One or more tracking issues related to the change
issues: []
issues: [13418]

# (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.
Expand Down

0 comments on commit 8c3a416

Please sign in to comment.