Skip to content

Commit

Permalink
fix(s3exporter/config-validation): endpoint should contain region and…
Browse files Browse the repository at this point in the history
… S3 bucket (open-telemetry#32815)

**Description:**

Discussion:
open-telemetry#32766.

Configuration logic:

- An endpoint is provided, and Region still needs to be provided (as per
the AWS SDK Go config, even though the region can be included in the
endpoint itself). The S3 bucket name is optional.
- An endpoint is not provided, thus region **and** S3 bucket name should
be provided (return an error for each if one of those 2 isn't)

**Link to tracking Issue:** open-telemetry#32774
  • Loading branch information
dabcoder committed Jun 11, 2024
1 parent ce6f8a3 commit 8cf80e7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11 deletions.
27 changes: 27 additions & 0 deletions .chloggen/awss3exporter_config_endpoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: awss3exporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: endpoint should contain the S3 bucket

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32774]

# (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.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
2 changes: 1 addition & 1 deletion exporter/awss3exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The following exporter configuration parameters are supported.
| `marshaler` | marshaler used to produce output data | `otlp_json` |
| `encoding` | Encoding extension to use to marshal data. Overrides the `marshaler` configuration option if set. | |
| `encoding_file_extension` | file format extension suffix when using the `encoding` configuration option. May be left empty for no suffix to be appended. | |
| `endpoint` | overrides the endpoint used by the exporter instead of constructing it from `region` and `s3_bucket` | |
| `endpoint` | (REST API endpoint) overrides the endpoint used by the exporter instead of constructing it from `region` and `s3_bucket` | |
| `s3_force_path_style` | [set this to `true` to force the request to use path-style addressing](http:https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html) | false |
| `disable_ssl` | set this to `true` to disable SSL when sending requests | false |
| `compression` | should the file be compressed | none |
Expand Down
4 changes: 2 additions & 2 deletions exporter/awss3exporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (c *Config) Validate() error {
if c.S3Uploader.Region == "" {
errs = multierr.Append(errs, errors.New("region is required"))
}
if c.S3Uploader.S3Bucket == "" {
errs = multierr.Append(errs, errors.New("bucket is required"))
if c.S3Uploader.S3Bucket == "" && c.S3Uploader.Endpoint == "" {
errs = multierr.Append(errs, errors.New("bucket or endpoint is required"))
}
compression := c.S3Uploader.Compression
if compression.IsCompressed() {
Expand Down
39 changes: 31 additions & 8 deletions exporter/awss3exporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,24 @@ func TestConfig_Validate(t *testing.T) {
errExpected error
}{
{
name: "valid",
// endpoint overrides region and bucket name.
name: "valid with endpoint and region",
config: func() *Config {
c := createDefaultConfig().(*Config)
c.S3Uploader.Endpoint = "http:https://example.com"
c.S3Uploader.Region = "foo"
return c
}(),
errExpected: nil,
},
{
// Endpoint will be built from bucket and region.
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html
name: "valid with S3Bucket and region",
config: func() *Config {
c := createDefaultConfig().(*Config)
c.S3Uploader.Region = "foo"
c.S3Uploader.S3Bucket = "bar"
c.S3Uploader.Endpoint = "http:https://example.com"
return c
}(),
errExpected: nil,
Expand All @@ -124,32 +136,43 @@ func TestConfig_Validate(t *testing.T) {
config: func() *Config {
c := createDefaultConfig().(*Config)
c.S3Uploader.Region = ""
c.S3Uploader.S3Bucket = ""
c.S3Uploader.Endpoint = ""
return c
}(),
errExpected: multierr.Append(errors.New("region is required"),
errors.New("bucket is required")),
errors.New("bucket or endpoint is required")),
},
{
name: "endpoint and region",
name: "region only",
config: func() *Config {
c := createDefaultConfig().(*Config)
c.S3Uploader.Endpoint = "http:https://example.com"
c.S3Uploader.Region = "foo"
c.S3Uploader.S3Bucket = ""
return c
}(),
errExpected: errors.New("bucket is required"),
errExpected: errors.New("bucket or endpoint is required"),
},
{
name: "endpoint and bucket",
name: "bucket only",
config: func() *Config {
c := createDefaultConfig().(*Config)
c.S3Uploader.Endpoint = "http:https://example.com"
c.S3Uploader.S3Bucket = "foo"
c.S3Uploader.Region = ""
return c
}(),
errExpected: errors.New("region is required"),
},
{
name: "endpoint only",
config: func() *Config {
c := createDefaultConfig().(*Config)
c.S3Uploader.Endpoint = "http:https://example.com"
c.S3Uploader.Region = ""
return c
}(),
errExpected: errors.New("region is required"),
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 8cf80e7

Please sign in to comment.