Skip to content

Commit

Permalink
[extension/sigv4authextension] Add support for endpoint based names f…
Browse files Browse the repository at this point in the history
…or logs and traces

Adds support for default endpoint based service name and region detection for AWS CloudWatchLogs and Traces endpoints
  • Loading branch information
schannag authored Dec 13, 2024
1 parent 5f7ac0a commit 370601e
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions extension/sigv4authextension/signingroundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,33 @@ func (si *signingRoundTripper) inferServiceAndRegion(r *http.Request) (service s
service = si.service
region = si.region

h := r.Host
if strings.HasPrefix(h, "aps-workspaces") {
if service == "" {
service = "aps"
}
rest := h[strings.Index(h, ".")+1:]
if region == "" {
region = rest[0:strings.Index(rest, ".")]
}
} else if strings.HasPrefix(h, "search-") {
if service == "" {
service = "es"
}
rest := h[strings.Index(h, ".")+1:]
if region == "" {
region = rest[0:strings.Index(rest, ".")]
}
host := r.Host
switch {
case strings.HasPrefix(host, "aps-workspaces"):
service, region = extractServiceAndRegion(service, region, host, "aps")
case strings.HasPrefix(host, "search-"):
service, region = extractServiceAndRegion(service, region, host, "es")
case strings.HasPrefix(host, "logs"):
service, region = extractServiceAndRegion(service, region, host, "logs")
case strings.HasPrefix(host, "xray"):
service, region = extractServiceAndRegion(service, region, host, "xray")
}

if service == "" || region == "" {
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.")
}

return service, region
}

func extractServiceAndRegion(service, region, host, defaultService string) (string, string) {
if service == "" {
service = defaultService
}
rest := host[strings.Index(host, ".")+1:]
if region == "" {
region = rest[0:strings.Index(rest, ".")]
}
return service, region
}

Expand Down

0 comments on commit 370601e

Please sign in to comment.