Skip to content

Commit 58aaa64

Browse files
authored
[extension/sigv4authextension] Add support for endpoint based names for logs and traces (#36828)
#### Description Adds support for default endpoint based service name and region detection for AWS CloudWatchLogs and Traces endpoints #### Link to tracking issue Fixes #### Testing * Added unit tests
1 parent f21f718 commit 58aaa64

File tree

4 files changed

+70
-18
lines changed

4 files changed

+70
-18
lines changed
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: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: sigv4authextension
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Add support for endpoint based names for logs and traces"
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: [36828]
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: []

extension/sigv4authextension/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The configuration fields are as follows:
2626
* Note that an attempt will be made to obtain a valid region from the endpoint of the service you are exporting to
2727
* [List of AWS regions](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html)
2828
* `service`: **Optional**. The AWS service for AWS Sigv4
29-
* Note that an attempt will be made to obtain a valid service from the endpoint of the service you are exporting to
29+
* Note for supported services an attempt will be made to obtain a valid service from the endpoint of the service you are exporting to. Supported services include - workspaces, es, logs and traces.
3030

3131

3232
```yaml

extension/sigv4authextension/signingroundtripper.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,28 +114,33 @@ func (si *signingRoundTripper) inferServiceAndRegion(r *http.Request) (service s
114114
service = si.service
115115
region = si.region
116116

117-
h := r.Host
118-
if strings.HasPrefix(h, "aps-workspaces") {
119-
if service == "" {
120-
service = "aps"
121-
}
122-
rest := h[strings.Index(h, ".")+1:]
123-
if region == "" {
124-
region = rest[0:strings.Index(rest, ".")]
125-
}
126-
} else if strings.HasPrefix(h, "search-") {
127-
if service == "" {
128-
service = "es"
129-
}
130-
rest := h[strings.Index(h, ".")+1:]
131-
if region == "" {
132-
region = rest[0:strings.Index(rest, ".")]
133-
}
117+
host := r.Host
118+
switch {
119+
case strings.HasPrefix(host, "aps-workspaces"):
120+
service, region = extractServiceAndRegion(service, region, host, "aps")
121+
case strings.HasPrefix(host, "search-"):
122+
service, region = extractServiceAndRegion(service, region, host, "es")
123+
case strings.HasPrefix(host, "logs"):
124+
service, region = extractServiceAndRegion(service, region, host, "logs")
125+
case strings.HasPrefix(host, "xray"):
126+
service, region = extractServiceAndRegion(service, region, host, "xray")
134127
}
135128

136129
if service == "" || region == "" {
137130
si.logger.Warn("Unable to infer region and/or service from the URL. Please provide values for region and/or service in the collector configuration.")
138131
}
132+
133+
return service, region
134+
}
135+
136+
func extractServiceAndRegion(service, region, host, defaultService string) (string, string) {
137+
if service == "" {
138+
service = defaultService
139+
}
140+
rest := host[strings.Index(host, ".")+1:]
141+
if region == "" {
142+
region = rest[0:strings.Index(rest, ".")]
143+
}
139144
return service, region
140145
}
141146

extension/sigv4authextension/signingroundtripper_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ func TestInferServiceAndRegion(t *testing.T) {
110110
req5, err := http.NewRequest(http.MethodGet, "https://aps-workspaces.us-east-1.amazonaws.com/workspaces/ws-XXX/api/v1/remote_write", nil)
111111
assert.NoError(t, err)
112112

113+
req6, err := http.NewRequest(http.MethodGet, "https://logs.us-east-1.amazonaws.com/v1/logs", nil)
114+
assert.NoError(t, err)
115+
116+
req7, err := http.NewRequest(http.MethodGet, "https://xray.us-east-1.amazonaws.com/v1/traces", nil)
117+
assert.NoError(t, err)
118+
113119
tests := []struct {
114120
name string
115121
request *http.Request
@@ -152,6 +158,20 @@ func TestInferServiceAndRegion(t *testing.T) {
152158
"service",
153159
"region",
154160
},
161+
{
162+
"logs_service_and_region_match_with_no_config",
163+
req6,
164+
createDefaultConfig().(*Config),
165+
"logs",
166+
"us-east-1",
167+
},
168+
{
169+
"xray_service_and_region_match_with_no_config",
170+
req7,
171+
createDefaultConfig().(*Config),
172+
"xray",
173+
"us-east-1",
174+
},
155175
}
156176

157177
// run tests

0 commit comments

Comments
 (0)