-
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.
Merge pull request #1 from keyval-dev/add-s3-exporter
add s3 exporter
- Loading branch information
Showing
17 changed files
with
923 additions
and
40 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,2 @@ | ||
# AWS S3 Exporter | ||
This exporter supports sending trace and metric data to AWS S3. |
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 @@ | ||
package awss3exporter | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
) | ||
|
||
type AWSS3UploadConfig struct { | ||
S3Bucket string `mapstructure:"bucket"` | ||
S3Region string `mapstructure:"region"` | ||
S3Prefix string `mapstructure:"prefix"` | ||
S3Partition string `mapstructure:"partition"` | ||
FilePrefix string `mapstructure:"file_prefix"` | ||
} | ||
|
||
// Config contains the main configuration options for the aws s3 exporter | ||
type Config struct { | ||
AWSS3UploadConfig AWSS3UploadConfig `mapstructure:"settings"` | ||
MarshalerName string `mapstructure:"marshaler_name"` | ||
|
||
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,7 @@ | ||
package 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,79 @@ | ||
package awss3exporter | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
"go.opentelemetry.io/collector/exporter" | ||
|
||
"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 | ||
dataWriter DataWriter | ||
logger *zap.Logger | ||
marshaler Marshaler | ||
} | ||
|
||
func NewS3Exporter(cfg *Config, | ||
params exporter.CreateSettings) (*S3Exporter, error) { | ||
|
||
if cfg == nil { | ||
return nil, errors.New("s3 exporter config is nil") | ||
} | ||
|
||
logger := params.Logger | ||
expConfig := cfg | ||
expConfig.logger = logger | ||
|
||
s3Config, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(cfg.AWSS3UploadConfig.S3Region)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
s3Client := s3.NewFromConfig(s3Config) | ||
|
||
marshaler, err := NewMarshaler(expConfig.MarshalerName, logger) | ||
if err != nil { | ||
return nil, errors.New("unknown marshaler") | ||
} | ||
|
||
s3Exporter := &S3Exporter{ | ||
config: expConfig, | ||
dataWriter: &S3Writer{ | ||
s3Client: s3Client, | ||
}, | ||
logger: logger, | ||
marshaler: marshaler, | ||
} | ||
|
||
return s3Exporter, nil | ||
} | ||
|
||
func (e *S3Exporter) Capabilities() consumer.Capabilities { | ||
return consumer.Capabilities{MutatesData: false} | ||
} | ||
|
||
func (e *S3Exporter) ConsumeLogs(ctx context.Context, logs plog.Logs) error { | ||
buf, err := e.marshaler.MarshalLogs(logs) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return e.dataWriter.WriteBuffer(ctx, buf, e.config, "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 | ||
} | ||
|
||
return e.dataWriter.WriteBuffer(ctx, buf, e.config, "traces", e.marshaler.Format()) | ||
} |
Oops, something went wrong.