Skip to content

Commit

Permalink
[extension/awsproxy] Reuse awsutil session logic. (amazon-contributin…
Browse files Browse the repository at this point in the history
  • Loading branch information
jefchien authored Mar 1, 2024
1 parent 282b1a2 commit be26c77
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 790 deletions.
7 changes: 5 additions & 2 deletions extension/awsproxy/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil v0.89.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/config/configopaque v0.89.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.89.0 // indirect
Expand All @@ -49,12 +50,14 @@ require (

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil => ./../../internal/aws/awsutil

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/proxy => ./../../internal/aws/proxy

replace github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws => ../../override/aws

retract (
v0.76.2
v0.76.1
v0.65.0
)

replace github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws => ../../override/aws
1 change: 1 addition & 0 deletions extension/awsproxy/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/aws/awsutil/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func GetAWSConfigSession(logger *zap.Logger, cn ConnAttr, cfg *AWSSessionSetting
case cfg.Region != "":
awsRegion = cfg.Region
logger.Debug("Fetch region from commandline/config file", zap.String("region", awsRegion))
case !cfg.NoVerifySSL:
case !cfg.LocalMode:
var es *session.Session
es, err = GetDefaultSession(logger, cfg)
if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions internal/aws/proxy/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ package proxy // import "github.com/open-telemetry/opentelemetry-collector-contr
import (
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configtls"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
)

const (
idleConnTimeout = 30
remoteProxyMaxIdleConnsPerHost = 2
)

// Config is the configuration for the local TCP proxy server.
Expand Down Expand Up @@ -38,6 +45,16 @@ type Config struct {
// will be called or not. Set to `true` to skip EC2 instance
// metadata check.
LocalMode bool `mapstructure:"local_mode"`

// Change the default profile for shared creds file
Profile string `mapstructure:"profile"`

// Change the default shared creds file location
SharedCredentialsFile []string `mapstructure:"shared_credentials_file"`

// Add a custom certificates file
CertificateFilePath string `mapstructure:"certificate_file_path"`

// How many times should we retry imds v2
IMDSRetries int `mapstructure:"imds_retries"`
}
Expand All @@ -57,3 +74,19 @@ func DefaultConfig() *Config {
AWSEndpoint: "",
}
}

func (cfg *Config) toSessionConfig() *awsutil.AWSSessionSettings {
sessionSettings := awsutil.CreateDefaultSessionConfig()
sessionSettings.CertificateFilePath = cfg.CertificateFilePath
sessionSettings.Endpoint = cfg.AWSEndpoint
sessionSettings.IMDSRetries = cfg.IMDSRetries
sessionSettings.LocalMode = cfg.LocalMode
sessionSettings.MaxRetries = remoteProxyMaxIdleConnsPerHost
sessionSettings.Profile = cfg.Profile
sessionSettings.ProxyAddress = cfg.ProxyAddress
sessionSettings.Region = cfg.Region
sessionSettings.RequestTimeoutSeconds = idleConnTimeout
sessionSettings.RoleARN = cfg.RoleARN
sessionSettings.SharedCredentialsFile = cfg.SharedCredentialsFile
return &sessionSettings
}
289 changes: 0 additions & 289 deletions internal/aws/proxy/conn.go

This file was deleted.

Loading

0 comments on commit be26c77

Please sign in to comment.