forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storage Extension 1/N (open-telemetry#2883)
* WIP - Add storage extension framework * Cleaned up initial implmenetation. Still much to do * Remove extraneous dependency * go tidy * rm gopls from go.mod * Fix typo in TODO * Finish thought in readme * Document storage.Extension, fix doc issues * Run make gendependabot and make gotidy * Use core nop pattern, add context to methods, clean up comments
- Loading branch information
1 parent
94ef22b
commit 5a21a73
Showing
8 changed files
with
1,573 additions
and
0 deletions.
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,41 @@ | ||
// 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 "context" | ||
|
||
type nopClient struct{} | ||
|
||
var nopClientInstance Client = &nopClient{} | ||
|
||
// NewNopClient returns a nop client | ||
func NewNopClient() Client { | ||
return nopClientInstance | ||
} | ||
|
||
// Get does nothing, and returns nil, nil | ||
func (c nopClient) Get(context.Context, string) ([]byte, error) { | ||
return nil, nil // no result, but no problem | ||
} | ||
|
||
// Set does nothing and returns nil | ||
func (c nopClient) Set(context.Context, string, []byte) error { | ||
return nil // no problem | ||
} | ||
|
||
// Delete does nothing and returns nil | ||
func (c nopClient) Delete(context.Context, 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,49 @@ | ||
// 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 ( | ||
"context" | ||
|
||
"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 will create a client for use by the specified component. | ||
// The component can use the client to manage state | ||
// TODO change parameters to new config.ComponentID | ||
// https://github.com/open-telemetry/opentelemetry-collector/pull/2869 | ||
GetClient(context.Context, component.Kind, configmodels.NamedEntity) (Client, error) | ||
} | ||
|
||
// Client is the interface that storage clients must implement | ||
// All methods should return error only if a problem occurred | ||
type Client interface { | ||
|
||
// Get will retrieve data from storage that corresponds to the | ||
// specified key. It should return nil, nil if not found | ||
Get(context.Context, string) ([]byte, error) | ||
|
||
// Set will store data. The data can be retrieved by the same | ||
// component after a process restart, using the same key | ||
Set(context.Context, string, []byte) error | ||
|
||
// Delete will delete data associated with the specified key | ||
Delete(context.Context, string) error | ||
} |