Skip to content

Commit 1c120df

Browse files
[confmap/provider/s3] Switch to NewFactory (#32742)
**Description:** Follows open-telemetry/opentelemetry-collector#9516. This doesn't introduce any functional changes, just uses the new API. --------- Co-authored-by: Evan Bradley <[email protected]> Co-authored-by: Antoine Toulme <[email protected]>
1 parent ed4adf7 commit 1c120df

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

.chloggen/s3provider-factory.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: confmap/provider/s3
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate `s3provider.New` in favor of `s3provider.NewFactory`
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [32742]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [api]

confmap/provider/s3provider/provider.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ type provider struct {
3333
client s3Client
3434
}
3535

36+
// NewFactory returns a new confmap.ProviderFactory that creates a confmap.Provider
37+
// which reads configuration from a file obtained from an s3 bucket.
38+
//
39+
// This Provider supports "s3" scheme, and can be called with a "uri" that follows:
40+
//
41+
// s3-uri : s3://[BUCKET].s3.[REGION].amazonaws.com/[KEY]
42+
//
43+
// One example for s3-uri be like: s3://doc-example-bucket.s3.us-west-2.amazonaws.com/photos/puppy.jpg
44+
// References: https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html
45+
//
46+
// Examples:
47+
// `s3://DOC-EXAMPLE-BUCKET.s3.us-west-2.amazonaws.com/photos/puppy.jpg` - (unix, windows)
48+
func NewFactory() confmap.ProviderFactory {
49+
return confmap.NewProviderFactory(newWithSettings)
50+
}
51+
52+
func newWithSettings(_ confmap.ProviderSettings) confmap.Provider {
53+
return &provider{client: nil}
54+
}
55+
3656
// New returns a new confmap.Provider that reads the configuration from a file.
3757
//
3858
// This Provider supports "s3" scheme, and can be called with a "uri" that follows:
@@ -44,6 +64,8 @@ type provider struct {
4464
//
4565
// Examples:
4666
// `s3://DOC-EXAMPLE-BUCKET.s3.us-west-2.amazonaws.com/photos/puppy.jpg` - (unix, windows)
67+
//
68+
// Deprecated: [v0.100.0] Use NewFactory() instead.
4769
func New() confmap.Provider {
4870
return &provider{client: nil}
4971
}

confmap/provider/s3provider/provider_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,9 @@ func TestScheme(t *testing.T) {
125125
assert.Equal(t, "s3", fp.Scheme())
126126
require.NoError(t, fp.Shutdown(context.Background()))
127127
}
128+
129+
func TestFactory(t *testing.T) {
130+
p := NewFactory().Create(confmap.ProviderSettings{})
131+
_, ok := p.(*provider)
132+
require.True(t, ok)
133+
}

0 commit comments

Comments
 (0)