-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storage Extension 1/N #2883
Merged
Merged
Storage Extension 1/N #2883
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ddff698
WIP - Add storage extension framework
djaglowski b0aaf77
Cleaned up initial implmenetation. Still much to do
djaglowski e62fd1b
Remove extraneous dependency
djaglowski 9e60d3f
go tidy
djaglowski 5fe5512
rm gopls from go.mod
djaglowski 807a63b
Fix typo in TODO
djaglowski dec72c0
Finish thought in readme
djaglowski 7721ff9
Document storage.Extension, fix doc issues
djaglowski caa0efd
Merge branch 'main' into storage-extension-1
djaglowski 8b9850a
Merge branch 'main' into storage-extension-1
djaglowski 392c1a0
Run make gendependabot and make gotidy
djaglowski 06f524f
Use core nop pattern, add context to methods, clean up comments
djaglowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Storage | ||
|
||
A storage extension persists state beyond the collector process. Other components can request a storage client from the storage extension and use it to manage state. | ||
|
||
The `storage.Extension` interface extends `component.Extension` by adding the following method: | ||
``` | ||
GetClient(component.Kind, configmodels.NamedEntity) (Client, error) | ||
``` | ||
|
||
The `storage.Client` interface contains the following methods: | ||
``` | ||
Get(string) ([]byte, error) | ||
Set(string, []byte) error | ||
Delete(string) error | ||
``` | ||
Note: All methods should return error only if a problem occurred. (For example, if a file is no longer accessible, or if a remote service is unavailable.) | ||
|
||
# TODO Sample code | ||
- Document component expectations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/stretchr/testify v1.7.0 | ||
go.etcd.io/bbolt v1.3.3 | ||
go.opentelemetry.io/collector v0.23.0 | ||
go.uber.org/zap v1.16.0 | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright The 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 storage | ||
|
||
type NopClient struct{} | ||
|
||
func (c NopClient) Get(string) ([]byte, error) { | ||
return nil, nil // no result, but no problem | ||
} | ||
|
||
func (c NopClient) Set(string, []byte) error { | ||
return nil // no problem | ||
} | ||
|
||
func (c NopClient) Delete(string) error { | ||
return nil // no problem | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright The 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 storage | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config/configmodels" | ||
) | ||
|
||
// Extension is the interface that storage extensions must implement | ||
type Extension interface { | ||
component.Extension | ||
GetClient(component.Kind, configmodels.NamedEntity) (Client, error) | ||
djaglowski marked this conversation as resolved.
Show resolved
Hide resolved
djaglowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Client is the interface that storage clients must implement | ||
// All methods should return error only if a problem occurred | ||
type Client interface { | ||
Get(string) ([]byte, error) // returns nil, nil if not found | ||
djaglowski marked this conversation as resolved.
Show resolved
Hide resolved
djaglowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Set(string, []byte) error | ||
Delete(string) error | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the model we have in core. and provide a
func NewNopClient() Client
and avoid exposing the new struct.May also want to have this in a
storagetest
package, can be done later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this to follow the pattern established in core. However, I have a question about potentially keeping
NewNopClient
available.One of the expectations is that components that make use of a storage extension should seamlessly handle the situation where no storage extension is configured. My intention with introducing this
nopClient
was to provide an easy way for components to fulfill this expectation. Consider:Do you think this is a useful pattern? I suppose components can implement their own
nopClient
if necessary, but I thought it might be helpful to include.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see in practice how this will be used in few examples, probably we should make sure we re-evaluate this after couple of PRs that uses it.