Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[awsproxy] Expose service name as config option #29550

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/main.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: awsproxyextension

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Expose service_name as configurable option. Previously, it was hardcoded as xray."

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

# (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: [user]
3 changes: 3 additions & 0 deletions extension/awsproxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extensions:
role_arn: ""
aws_endpoint: ""
local_mode: false
service_name: "xray"
```

### endpoint (Optional)
Expand Down Expand Up @@ -66,3 +67,5 @@ The IAM role used by this proxy when communicating with the AWS service. If non-
### aws_endpoint (Optional)
The AWS service endpoint which this proxy forwards requests to. If not set, will default to the AWS X-Ray endpoint.

### service_name (Optional)
The AWS service name which this proxy forwards requests to. If not set, will default to "xray"
1 change: 1 addition & 0 deletions extension/awsproxy/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestLoadConfig(t *testing.T) {
Region: "us-west-1",
RoleARN: "arn:aws:iam::123456789012:role/awesome_role",
AWSEndpoint: "https://another.aws.endpoint.com",
ServiceName: "es",
},
},
},
Expand Down
1 change: 1 addition & 0 deletions extension/awsproxy/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ awsproxy/1:
region: "us-west-1"
role_arn: "arn:aws:iam::123456789012:role/awesome_role"
aws_endpoint: "https://another.aws.endpoint.com"
service_name: "es"
5 changes: 5 additions & 0 deletions internal/aws/proxy/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type Config struct {
// will be called or not. Set to `true` to skip EC2 instance
// metadata check.
LocalMode bool `mapstructure:"local_mode"`

arpitjindal97 marked this conversation as resolved.
Show resolved Hide resolved
// ServiceName determines which service the requests are sent to.
// will be default to `xray`. This is mandatory for SigV4
ServiceName string `mapstructure:"service_name"`
}

func DefaultConfig() *Config {
Expand All @@ -55,5 +59,6 @@ func DefaultConfig() *Config {
Region: "",
RoleARN: "",
AWSEndpoint: "",
ServiceName: "xray",
}
}
14 changes: 8 additions & 6 deletions internal/aws/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

const (
service = "xray"
connHeader = "Connection"
)

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

awsCfg, sess, err := getAWSConfigSession(cfg, logger)
if err != nil {
return nil, err
}

awsEndPoint, err := getServiceEndpoint(awsCfg)
awsEndPoint, err := getServiceEndpoint(awsCfg, cfg.ServiceName)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -101,7 +103,7 @@ func NewServer(cfg *Config, logger *zap.Logger) (Server, error) {
}

// Sign request. signer.Sign() also repopulates the request body.
_, err = signer.Sign(req, body, service, *awsCfg.Region, time.Now())
_, err = signer.Sign(req, body, cfg.ServiceName, *awsCfg.Region, time.Now())
arpitjindal97 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
logger.Error("Unable to sign request", zap.Error(err))
}
Expand All @@ -117,13 +119,13 @@ func NewServer(cfg *Config, logger *zap.Logger) (Server, error) {

// getServiceEndpoint returns X-Ray service endpoint.
// It is guaranteed that awsCfg config instance is non-nil and the region value is non nil or non empty in awsCfg object.
// Currently the caller takes care of it.
func getServiceEndpoint(awsCfg *aws.Config) (string, error) {
// Currently, the caller takes care of it.
func getServiceEndpoint(awsCfg *aws.Config, serviceName string) (string, error) {
if isEmpty(awsCfg.Endpoint) {
if isEmpty(awsCfg.Region) {
return "", errors.New("unable to generate endpoint from region with nil value")
}
resolved, err := endpoints.DefaultResolver().EndpointFor(service, *awsCfg.Region, setResolverConfig())
resolved, err := endpoints.DefaultResolver().EndpointFor(serviceName, *awsCfg.Region, setResolverConfig())
return resolved.URL, err
}
return *awsCfg.Endpoint, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/aws/proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestCanCreateTransport(t *testing.T) {
}

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

Expand Down
2 changes: 2 additions & 0 deletions receiver/awsxrayreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestLoadConfig(t *testing.T) {
Region: "",
RoleARN: "",
AWSEndpoint: "",
ServiceName: "xray",
},
},
},
Expand All @@ -74,6 +75,7 @@ func TestLoadConfig(t *testing.T) {
RoleARN: "arn:aws:iam::123456789012:role/awesome_role",
AWSEndpoint: "https://another.aws.endpoint.com",
LocalMode: true,
ServiceName: "xray",
},
}},
}
Expand Down
Loading