mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
lib/promscrape/discovery/ec2: properly handle custom endpoint
option in ec2_sd_configs
This option was ignored since d289ecded1
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1287
This commit is contained in:
parent
bc254cb497
commit
1005d5a186
5 changed files with 25 additions and 15 deletions
|
@ -56,10 +56,12 @@ var (
|
||||||
|
|
||||||
awsUseSigv4 = flagutil.NewArrayBool("remoteWrite.aws.useSigv4", "Enables SigV4 request signing for the corresponding -remoteWrite.url. "+
|
awsUseSigv4 = flagutil.NewArrayBool("remoteWrite.aws.useSigv4", "Enables SigV4 request signing for the corresponding -remoteWrite.url. "+
|
||||||
"It is expected that other -remoteWrite.aws.* command-line flags are set if sigv4 request signing is enabled")
|
"It is expected that other -remoteWrite.aws.* command-line flags are set if sigv4 request signing is enabled")
|
||||||
awsRegion = flagutil.NewArray("remoteWrite.aws.region", "Optional AWS region to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
awsEC2Endpoint = flagutil.NewArray("remoteWrite.aws.ec2Endpoint", "Optional AWS EC2 API endpoint to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
||||||
awsRoleARN = flagutil.NewArray("remoteWrite.aws.roleARN", "Optional AWS roleARN to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
awsSTSEndpoint = flagutil.NewArray("remoteWrite.aws.stsEndpoint", "Optional AWS STS API endpoint to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
||||||
awsAccessKey = flagutil.NewArray("remoteWrite.aws.accessKey", "Optional AWS AccessKey to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
awsRegion = flagutil.NewArray("remoteWrite.aws.region", "Optional AWS region to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
||||||
awsService = flagutil.NewArray("remoteWrite.aws.service", "Optional AWS Service to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set. "+
|
awsRoleARN = flagutil.NewArray("remoteWrite.aws.roleARN", "Optional AWS roleARN to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
||||||
|
awsAccessKey = flagutil.NewArray("remoteWrite.aws.accessKey", "Optional AWS AccessKey to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
||||||
|
awsService = flagutil.NewArray("remoteWrite.aws.service", "Optional AWS Service to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set. "+
|
||||||
"Defaults to \"aps\"")
|
"Defaults to \"aps\"")
|
||||||
awsSecretKey = flagutil.NewArray("remoteWrite.aws.secretKey", "Optional AWS SecretKey to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
awsSecretKey = flagutil.NewArray("remoteWrite.aws.secretKey", "Optional AWS SecretKey to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set")
|
||||||
)
|
)
|
||||||
|
@ -231,12 +233,14 @@ func getAWSAPIConfig(argIdx int) (*awsapi.Config, error) {
|
||||||
if !awsUseSigv4.GetOptionalArg(argIdx) {
|
if !awsUseSigv4.GetOptionalArg(argIdx) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
ec2Endpoint := awsEC2Endpoint.GetOptionalArg(argIdx)
|
||||||
|
stsEndpoint := awsSTSEndpoint.GetOptionalArg(argIdx)
|
||||||
region := awsRegion.GetOptionalArg(argIdx)
|
region := awsRegion.GetOptionalArg(argIdx)
|
||||||
roleARN := awsRoleARN.GetOptionalArg(argIdx)
|
roleARN := awsRoleARN.GetOptionalArg(argIdx)
|
||||||
accessKey := awsAccessKey.GetOptionalArg(argIdx)
|
accessKey := awsAccessKey.GetOptionalArg(argIdx)
|
||||||
secretKey := awsSecretKey.GetOptionalArg(argIdx)
|
secretKey := awsSecretKey.GetOptionalArg(argIdx)
|
||||||
service := awsService.GetOptionalArg(argIdx)
|
service := awsService.GetOptionalArg(argIdx)
|
||||||
cfg, err := awsapi.NewConfig(region, roleARN, accessKey, secretKey, service)
|
cfg, err := awsapi.NewConfig(ec2Endpoint, stsEndpoint, region, roleARN, accessKey, secretKey, service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
|
||||||
## v1.79.x long-time support release (LTS)
|
## v1.79.x long-time support release (LTS)
|
||||||
|
|
||||||
* BUGFIX: [VictoriaMetrics cluster](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html): fix potential panic in [multi-level cluster setup](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#multi-level-cluster-setup) when top-level `vmselect` is configured with `-replicationFactor` bigger than 1. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2961).
|
* BUGFIX: [VictoriaMetrics cluster](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html): fix potential panic in [multi-level cluster setup](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#multi-level-cluster-setup) when top-level `vmselect` is configured with `-replicationFactor` bigger than 1. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2961).
|
||||||
|
* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly handle custom `endpoint` value in [ec2_sd_configs](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ec2_sd_config). It was ignored since [v1.77.0](https://docs.victoriametrics.com/CHANGELOG.html#v1770) because of a bug in the implementation of [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1287).
|
||||||
|
|
||||||
|
|
||||||
## [v1.79.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.79.1)
|
## [v1.79.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.79.1)
|
||||||
|
|
|
@ -43,8 +43,8 @@ type credentials struct {
|
||||||
Expiration time.Time
|
Expiration time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfig returns new AWS Config.
|
// NewConfig returns new AWS Config from the given args.
|
||||||
func NewConfig(region, roleARN, accessKey, secretKey, service string) (*Config, error) {
|
func NewConfig(ec2Endpoint, stsEndpoint, region, roleARN, accessKey, secretKey, service string) (*Config, error) {
|
||||||
cfg := &Config{
|
cfg := &Config{
|
||||||
client: http.DefaultClient,
|
client: http.DefaultClient,
|
||||||
region: region,
|
region: region,
|
||||||
|
@ -65,8 +65,8 @@ func NewConfig(region, roleARN, accessKey, secretKey, service string) (*Config,
|
||||||
}
|
}
|
||||||
cfg.region = r
|
cfg.region = r
|
||||||
}
|
}
|
||||||
cfg.ec2Endpoint = buildAPIEndpoint(cfg.ec2Endpoint, cfg.region, "ec2")
|
cfg.ec2Endpoint = buildAPIEndpoint(ec2Endpoint, cfg.region, "ec2")
|
||||||
cfg.stsEndpoint = buildAPIEndpoint(cfg.stsEndpoint, cfg.region, "sts")
|
cfg.stsEndpoint = buildAPIEndpoint(stsEndpoint, cfg.region, "sts")
|
||||||
if cfg.roleARN == "" {
|
if cfg.roleARN == "" {
|
||||||
cfg.roleARN = os.Getenv("AWS_ROLE_ARN")
|
cfg.roleARN = os.Getenv("AWS_ROLE_ARN")
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,11 @@ func newAPIConfig(sdc *SDConfig) (*apiConfig, error) {
|
||||||
if sdc.Port != nil {
|
if sdc.Port != nil {
|
||||||
port = *sdc.Port
|
port = *sdc.Port
|
||||||
}
|
}
|
||||||
awsCfg, err := awsapi.NewConfig(sdc.Region, sdc.RoleARN, sdc.AccessKey, sdc.SecretKey.String(), "ec2")
|
stsEndpoint := sdc.STSEndpoint
|
||||||
|
if stsEndpoint == "" {
|
||||||
|
stsEndpoint = sdc.Endpoint
|
||||||
|
}
|
||||||
|
awsCfg, err := awsapi.NewConfig(sdc.Endpoint, stsEndpoint, sdc.Region, sdc.RoleARN, sdc.AccessKey, sdc.SecretKey.String(), "ec2")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,13 @@ var SDCheckInterval = flag.Duration("promscrape.ec2SDCheckInterval", time.Minute
|
||||||
//
|
//
|
||||||
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ec2_sd_config
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#ec2_sd_config
|
||||||
type SDConfig struct {
|
type SDConfig struct {
|
||||||
Region string `yaml:"region,omitempty"`
|
Region string `yaml:"region,omitempty"`
|
||||||
Endpoint string `yaml:"endpoint,omitempty"`
|
Endpoint string `yaml:"endpoint,omitempty"`
|
||||||
AccessKey string `yaml:"access_key,omitempty"`
|
STSEndpoint string `yaml:"sts_endpoint,omitempty"`
|
||||||
SecretKey *promauth.Secret `yaml:"secret_key,omitempty"`
|
AccessKey string `yaml:"access_key,omitempty"`
|
||||||
|
SecretKey *promauth.Secret `yaml:"secret_key,omitempty"`
|
||||||
// TODO add support for Profile, not working atm
|
// TODO add support for Profile, not working atm
|
||||||
Profile string `yaml:"profile,omitempty"`
|
// Profile string `yaml:"profile,omitempty"`
|
||||||
RoleARN string `yaml:"role_arn,omitempty"`
|
RoleARN string `yaml:"role_arn,omitempty"`
|
||||||
// RefreshInterval time.Duration `yaml:"refresh_interval"`
|
// RefreshInterval time.Duration `yaml:"refresh_interval"`
|
||||||
// refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option.
|
// refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option.
|
||||||
|
|
Loading…
Reference in a new issue