Skip to content

Commit ae8fde2

Browse files
[awsproxy] Expose service name as config option (#29550)
awsproxy extension can be used as proxy to any service not just xray. The service name variable was hardcoded to "xray". This PR exposes it to be configurable in the config.yaml Appropriate README of the extension has been updated to reflect the addition of new option Signed-off-by: Arpit Agarwal <[email protected]>
1 parent b6e3d49 commit ae8fde2

File tree

8 files changed

+48
-7
lines changed

8 files changed

+48
-7
lines changed

.chloggen/main.yaml

+27
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: awsproxyextension
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Expose service_name as configurable option. Previously, it was hardcoded as xray."
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: [29550]
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: [user]

extension/awsproxy/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ extensions:
3535
role_arn: ""
3636
aws_endpoint: ""
3737
local_mode: false
38+
service_name: "xray"
3839
```
3940
4041
### endpoint (Optional)
@@ -66,3 +67,5 @@ The IAM role used by this proxy when communicating with the AWS service. If non-
6667
### aws_endpoint (Optional)
6768
The AWS service endpoint which this proxy forwards requests to. If not set, will default to the AWS X-Ray endpoint.
6869

70+
### service_name (Optional)
71+
The AWS service name which this proxy forwards requests to. If not set, will default to "xray"

extension/awsproxy/config_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestLoadConfig(t *testing.T) {
4444
Region: "us-west-1",
4545
RoleARN: "arn:aws:iam::123456789012:role/awesome_role",
4646
AWSEndpoint: "https://another.aws.endpoint.com",
47+
ServiceName: "es",
4748
},
4849
},
4950
},

extension/awsproxy/testdata/config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ awsproxy/1:
88
region: "us-west-1"
99
role_arn: "arn:aws:iam::123456789012:role/awesome_role"
1010
aws_endpoint: "https://another.aws.endpoint.com"
11+
service_name: "es"

internal/aws/proxy/cfg.go

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ type Config struct {
4040
// will be called or not. Set to `true` to skip EC2 instance
4141
// metadata check.
4242
LocalMode bool `mapstructure:"local_mode"`
43+
44+
// ServiceName determines which service the requests are sent to.
45+
// will be default to `xray`. This is mandatory for SigV4
46+
ServiceName string `mapstructure:"service_name"`
4347
}
4448

4549
func DefaultConfig() *Config {
@@ -55,5 +59,6 @@ func DefaultConfig() *Config {
5559
Region: "",
5660
RoleARN: "",
5761
AWSEndpoint: "",
62+
ServiceName: "xray",
5863
}
5964
}

internal/aws/proxy/server.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
)
2626

2727
const (
28-
service = "xray"
2928
connHeader = "Connection"
3029
)
3130

@@ -45,13 +44,16 @@ func NewServer(cfg *Config, logger *zap.Logger) (Server, error) {
4544
if cfg.ProxyAddress != "" {
4645
logger.Debug("Using remote proxy", zap.String("address", cfg.ProxyAddress))
4746
}
47+
if cfg.ServiceName == "" {
48+
cfg.ServiceName = "xray"
49+
}
4850

4951
awsCfg, sess, err := getAWSConfigSession(cfg, logger)
5052
if err != nil {
5153
return nil, err
5254
}
5355

54-
awsEndPoint, err := getServiceEndpoint(awsCfg)
56+
awsEndPoint, err := getServiceEndpoint(awsCfg, cfg.ServiceName)
5557
if err != nil {
5658
return nil, err
5759
}
@@ -101,7 +103,7 @@ func NewServer(cfg *Config, logger *zap.Logger) (Server, error) {
101103
}
102104

103105
// Sign request. signer.Sign() also repopulates the request body.
104-
_, err = signer.Sign(req, body, service, *awsCfg.Region, time.Now())
106+
_, err = signer.Sign(req, body, cfg.ServiceName, *awsCfg.Region, time.Now())
105107
if err != nil {
106108
logger.Error("Unable to sign request", zap.Error(err))
107109
}
@@ -117,13 +119,13 @@ func NewServer(cfg *Config, logger *zap.Logger) (Server, error) {
117119

118120
// getServiceEndpoint returns X-Ray service endpoint.
119121
// It is guaranteed that awsCfg config instance is non-nil and the region value is non nil or non empty in awsCfg object.
120-
// Currently the caller takes care of it.
121-
func getServiceEndpoint(awsCfg *aws.Config) (string, error) {
122+
// Currently, the caller takes care of it.
123+
func getServiceEndpoint(awsCfg *aws.Config, serviceName string) (string, error) {
122124
if isEmpty(awsCfg.Endpoint) {
123125
if isEmpty(awsCfg.Region) {
124126
return "", errors.New("unable to generate endpoint from region with nil value")
125127
}
126-
resolved, err := endpoints.DefaultResolver().EndpointFor(service, *awsCfg.Region, setResolverConfig())
128+
resolved, err := endpoints.DefaultResolver().EndpointFor(serviceName, *awsCfg.Region, setResolverConfig())
127129
return resolved.URL, err
128130
}
129131
return *awsCfg.Endpoint, nil

internal/aws/proxy/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func TestCanCreateTransport(t *testing.T) {
241241
}
242242

243243
func TestGetServiceEndpointInvalidAWSConfig(t *testing.T) {
244-
_, err := getServiceEndpoint(&aws.Config{})
244+
_, err := getServiceEndpoint(&aws.Config{}, "")
245245
assert.EqualError(t, err, "unable to generate endpoint from region with nil value")
246246
}
247247

receiver/awsxrayreceiver/config_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestLoadConfig(t *testing.T) {
5151
Region: "",
5252
RoleARN: "",
5353
AWSEndpoint: "",
54+
ServiceName: "xray",
5455
},
5556
},
5657
},
@@ -74,6 +75,7 @@ func TestLoadConfig(t *testing.T) {
7475
RoleARN: "arn:aws:iam::123456789012:role/awesome_role",
7576
AWSEndpoint: "https://another.aws.endpoint.com",
7677
LocalMode: true,
78+
ServiceName: "xray",
7779
},
7880
}},
7981
}

0 commit comments

Comments
 (0)