-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
aws s3 exporter second PR, implementation #10000
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Validating CODEOWNERS rules …
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
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
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,51 @@ | ||
# AWS S3 Exporter for OpenTelemetry Collector | ||
|
||
| Status | | | ||
| ------------------------ |-----------------------| | ||
| Stability | [in development] | | ||
| Supported pipeline types | traces, logs | | ||
| Distributions | [contrib] | | ||
|
||
## Schema supported | ||
This exporter targets to support proto/json and proto/binary format | ||
|
||
## Exporter Configuration | ||
|
||
The following exporter configuration parameters are supported. | ||
|
||
| Name | Description | Default | | ||
| :--------------------- | :--------------------------------------------------------------------------------- | ------- | | ||
| `region` | AWS region. | | | ||
| `s3_bucket` | S3 bucket | | | ||
| `s3_prefix` | prefix for the S3 key (root directory inside bucket). | | | ||
| `s3_partition` | time granularity of S3 key: hour or minute |"minute" | | ||
| `file_prefix` | file prefix defined by user | | | ||
| `marshaler_name` | marshaler used to produce output data otlp_json or otlp_proto | | | ||
|
||
# Example Configuration | ||
|
||
Following example configuration defines to store output in 'eu-central' region and bucket named 'databucket'. | ||
|
||
```yaml | ||
exporters: | ||
awss3: | ||
s3uploader: | ||
region: 'eu-central-1' | ||
s3_bucket: 'databucket' | ||
s3_prefix: 'metric' | ||
s3_partition: 'minute' | ||
``` | ||
|
||
Logs and traces will be stored inside 'databucket' in the following path format. | ||
|
||
```console | ||
metric/year=XXXX/month=XX/day=XX/hour=XX/minute=XX | ||
``` | ||
|
||
## AWS Credential Configuration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About AWS Credentials config, i think need more example |
||
|
||
This exporter follows default credential resolution for the | ||
[aws-sdk-go](https://docs.aws.amazon.com/sdk-for-go/api/index.html). | ||
|
||
Follow the [guidelines](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html) for the | ||
credential configuration. |
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,45 @@ | ||
// Copyright 2022 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 awss3exporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awss3exporter" | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/config" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// S3UploaderConfig contains aws s3 uploader related config to controls things | ||
// like bucket, prefix, batching, connections, retries, etc. | ||
type S3UploaderConfig struct { | ||
Region string `mapstructure:"region"` | ||
S3Bucket string `mapstructure:"s3_bucket"` | ||
S3Prefix string `mapstructure:"s3_prefix"` | ||
S3Partition string `mapstructure:"s3_partition"` | ||
FilePrefix string `mapstructure:"file_prefix"` | ||
} | ||
|
||
// Config contains the main configuration options for the awskinesis exporter | ||
type Config struct { | ||
config.ExporterSettings `mapstructure:",squash"` | ||
|
||
S3Uploader S3UploaderConfig `mapstructure:"s3uploader"` | ||
MarshalerName string `mapstructure:"marshaler_name"` | ||
|
||
// ResourceToTelemetrySettings is the option for converting resource attrihutes to telemetry attributes. | ||
// "Enabled" - A boolean field to enable/disable this option. Default is `false`. | ||
// If enabled, all the resource attributes will be converted to metric labels by default. | ||
// exporterhelper.ResourceToTelemetrySettings `mapstructure:"resource_to_telemetry_conversion"` | ||
|
||
logger *zap.Logger | ||
} |
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,81 @@ | ||
// Copyright 2021 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 | ||
// | ||
// shttp://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 awss3exporter | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/service/servicetest" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
factories, err := componenttest.NopFactories() | ||
assert.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
factories.Exporters[typeStr] = factory | ||
cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "default.yaml"), factories) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
e := cfg.Exporters[config.NewComponentID(typeStr)] | ||
|
||
assert.Equal(t, e, | ||
&Config{ | ||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), | ||
|
||
S3Uploader: S3UploaderConfig{ | ||
Region: "us-east-1", | ||
S3Partition: "minute", | ||
}, | ||
MarshalerName: "otlp_json", | ||
}, | ||
) | ||
} | ||
|
||
func TestConfig(t *testing.T) { | ||
factories, err := componenttest.NopFactories() | ||
assert.Nil(t, err) | ||
|
||
factory := NewFactory() | ||
factories.Exporters[factory.Type()] = factory | ||
cfg, err := servicetest.LoadConfigAndValidate( | ||
filepath.Join("testdata", "config.yaml"), factories) | ||
|
||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
e := cfg.Exporters[config.NewComponentID(typeStr)] | ||
|
||
assert.Equal(t, e, | ||
&Config{ | ||
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), | ||
|
||
S3Uploader: S3UploaderConfig{ | ||
Region: "us-east-1", | ||
S3Bucket: "foo", | ||
S3Prefix: "bar", | ||
S3Partition: "minute", | ||
}, | ||
MarshalerName: "otlp_json", | ||
}, | ||
) | ||
} |
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,21 @@ | ||
// Copyright 2022 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 awss3exporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awss3exporter" | ||
|
||
import "context" | ||
|
||
type DataWriter interface { | ||
WriteBuffer(ctx context.Context, buf []byte, config *Config, metadata string, format string) error | ||
} |
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,98 @@ | ||
// Copyright 2021 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 awss3exporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awss3exporter" | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type S3Exporter struct { | ||
config config.Exporter | ||
dataWriter DataWriter | ||
logger *zap.Logger | ||
marshaler Marshaler | ||
} | ||
|
||
func NewS3Exporter(config config.Exporter, | ||
params component.ExporterCreateSettings) (*S3Exporter, error) { | ||
|
||
if config == nil { | ||
return nil, errors.New("s3 exporter config is nil") | ||
} | ||
|
||
logger := params.Logger | ||
expConfig := config.(*Config) | ||
expConfig.logger = logger | ||
|
||
validateConfig := expConfig.Validate() | ||
|
||
if validateConfig != nil { | ||
return nil, validateConfig | ||
} | ||
|
||
marshaler, err := NewMarshaler(expConfig.MarshalerName, logger) | ||
if err != nil { | ||
return nil, errors.New("unknown marshaler") | ||
} | ||
|
||
s3Exporter := &S3Exporter{ | ||
config: config, | ||
dataWriter: &S3Writer{}, | ||
logger: logger, | ||
marshaler: marshaler, | ||
} | ||
return s3Exporter, nil | ||
} | ||
|
||
func (e *S3Exporter) Capabilities() consumer.Capabilities { | ||
return consumer.Capabilities{MutatesData: false} | ||
} | ||
|
||
func (e *S3Exporter) Start(ctx context.Context, host component.Host) error { | ||
return nil | ||
} | ||
|
||
func (e *S3Exporter) ConsumeLogs(ctx context.Context, logs plog.Logs) error { | ||
buf, err := e.marshaler.MarshalLogs(logs) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
expConfig := e.config.(*Config) | ||
|
||
return e.dataWriter.WriteBuffer(ctx, buf, expConfig, "logs", e.marshaler.Format()) | ||
} | ||
|
||
func (e *S3Exporter) ConsumeTraces(ctx context.Context, traces ptrace.Traces) error { | ||
buf, err := e.marshaler.MarshalTraces(traces) | ||
if err != nil { | ||
return err | ||
} | ||
expConfig := e.config.(*Config) | ||
|
||
return e.dataWriter.WriteBuffer(ctx, buf, expConfig, "traces", e.marshaler.Format()) | ||
} | ||
|
||
func (e *S3Exporter) Shutdown(context.Context) error { | ||
return nil | ||
} |
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,59 @@ | ||
// Copyright 2022 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 awss3exporter | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.uber.org/zap" | ||
) | ||
|
||
var testLogs = []byte(`{"resourceLogs":[{"resource":{"attributes":[{"key":"_sourceCategory","value":{"stringValue":"logfile"}},{"key":"_sourceHost","value":{"stringValue":"host"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"observedTimeUnixNano":"1654257420681895000","body":{"stringValue":"2022-06-03 13:57:00.62739 +0200 CEST m=+14.018296742 log entry14"},"attributes":[{"key":"log.file.path_resolved","value":{"stringValue":"logwriter/data.log"}}],"traceId":"","spanId":""}]}],"schemaUrl":"https://opentelemetry.io/schemas/1.6.1"}]}`) | ||
|
||
type TestWriter struct { | ||
t *testing.T | ||
} | ||
|
||
func (testWriter *TestWriter) WriteBuffer(ctx context.Context, buf []byte, config *Config, metadata string, format string) error { | ||
assert.Equal(testWriter.t, testLogs, buf) | ||
return nil | ||
} | ||
|
||
func getTestLogs(tb testing.TB) plog.Logs { | ||
logsMarshaler := plog.NewJSONUnmarshaler() | ||
logs, err := logsMarshaler.UnmarshalLogs(testLogs) | ||
assert.NoError(tb, err, "Can't unmarshal testing logs data -> %s", err) | ||
return logs | ||
} | ||
|
||
func getLogExporter(t *testing.T) *S3Exporter { | ||
marshaler, _ := NewMarshaler("otlp_json", zap.NewNop()) | ||
exporter := &S3Exporter{ | ||
config: createDefaultConfig(), | ||
dataWriter: &TestWriter{t}, | ||
logger: zap.NewNop(), | ||
marshaler: marshaler, | ||
} | ||
return exporter | ||
} | ||
|
||
func TestLog(t *testing.T) { | ||
logs := getTestLogs(t) | ||
exporter := getLogExporter(t) | ||
assert.NoError(t, exporter.ConsumeLogs(context.Background(), logs)) | ||
} |
Oops, something went wrong.
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.
I think some discussion (or example) on partitioning could be helpful here
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.
right, will add it