Skip to content
Draft
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
25 changes: 3 additions & 22 deletions cmd/yace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import (
"golang.org/x/sync/semaphore"

exporter "github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg"
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/clients"
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/clients/cloudwatch"
v1 "github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/clients/v1"
v2 "github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/clients/v2"
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/config"
)

Expand Down Expand Up @@ -267,20 +266,11 @@ func startScraper(c *cli.Context) error {
featureFlags := c.StringSlice(enableFeatureFlag)
s := NewScraper(featureFlags)

var cache cachingFactory
cache, err = v2.NewFactory(logger, jobsCfg, fips)
cache, err := clients.NewFactory(logger, jobsCfg, fips)
if err != nil {
return fmt.Errorf("failed to construct aws sdk v2 client cache: %w", err)
}

// Switch to v1 SDK if feature flag is enabled
for _, featureFlag := range featureFlags {
if featureFlag == config.AwsSdkV1 {
cache = v1.NewFactory(logger, jobsCfg, fips)
logger.Info("Using aws sdk v1")
}
}

ctx, cancelRunningScrape := context.WithCancel(context.Background())
go s.decoupled(ctx, logger, jobsCfg, cache)

Expand Down Expand Up @@ -325,21 +315,12 @@ func startScraper(c *cli.Context) error {
}

logger.Info("Reset clients cache")
var cache cachingFactory
cache, err = v2.NewFactory(logger, newJobsCfg, fips)
cache, err := clients.NewFactory(logger, newJobsCfg, fips)
if err != nil {
logger.Error("Failed to construct aws sdk v2 client cache", "err", err, "path", configFile)
return
}

// Switch to v1 SDK if feature flag is enabled
for _, featureFlag := range featureFlags {
if featureFlag == config.AwsSdkV1 {
cache = v1.NewFactory(logger, newJobsCfg, fips)
logger.Info("Using aws sdk v1")
}
}

cancelRunningScrape()
ctx, cancelRunningScrape = context.WithCancel(context.Background())
go s.decoupled(ctx, logger, newJobsCfg, cache)
Expand Down
6 changes: 0 additions & 6 deletions docs/feature_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ List of features or changes that are disabled by default since they are breaking

You can enable them using the `-enable-feature` flag with a comma separated list of features. They may be enabled by default in future versions.

## AWS SDK v1

`-enable-feature=aws-sdk-v1`

Uses the v1 version of the aws sdk for go for backward compatibility. By default, YACE now uses AWS SDK v2 which was released in Jan 2021 and comes with large performance gains.

## Always return info metrics

`-enable-feature=always-return-info-metrics`
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ github.com/grafana/regexp v0.0.0-20240607082908-2cb410fa05da h1:BML5sNe+bw2uO8t8
github.com/grafana/regexp v0.0.0-20240607082908-2cb410fa05da/go.mod h1:+JKpmjMGhpgPL+rXZ5nsZieVzvarn86asRlBg4uNGnk=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down Expand Up @@ -129,7 +127,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
54 changes: 48 additions & 6 deletions pkg/clients/account/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,54 @@
// limitations under the License.
package account

import "context"
import (
"context"
"errors"
"log/slog"

type Client interface {
// GetAccount returns the AWS account ID for the configured authenticated client.
GetAccount(ctx context.Context) (string, error)
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/sts"
)

// GetAccountAlias returns the account alias if there's one set, otherwise an empty string.
GetAccountAlias(ctx context.Context) (string, error)
type client struct {
logger *slog.Logger
stsClient *sts.Client
iamClient *iam.Client
}

func NewClient(logger *slog.Logger, stsClient *sts.Client, iamClient *iam.Client) Client {
return &client{
logger: logger,
stsClient: stsClient,
iamClient: iamClient,
}
}

func (c client) GetAccount(ctx context.Context) (string, error) {
result, err := c.stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
if err != nil {
return "", err
}
if result.Account == nil {
return "", errors.New("aws sts GetCallerIdentityWithContext returned no account")
}
return *result.Account, nil
}

func (c client) GetAccountAlias(ctx context.Context) (string, error) {
acctAliasOut, err := c.iamClient.ListAccountAliases(ctx, &iam.ListAccountAliasesInput{})
if err != nil {
return "", err
}

possibleAccountAlias := ""

// Since a single account can only have one alias, and an authenticated SDK session corresponds to a single account,
// the output can have at most one alias.
// https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListAccountAliases.html
if len(acctAliasOut.AccountAliases) > 0 {
possibleAccountAlias = acctAliasOut.AccountAliases[0]
}

return possibleAccountAlias, nil
}
23 changes: 23 additions & 0 deletions pkg/clients/account/iface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package account

import "context"

type Client interface {
// GetAccount returns the AWS account ID for the configured authenticated client.
GetAccount(ctx context.Context) (string, error)

// GetAccountAlias returns the account alias if there's one set, otherwise an empty string.
GetAccountAlias(ctx context.Context) (string, error)
}
69 changes: 0 additions & 69 deletions pkg/clients/account/v1/client.go

This file was deleted.

67 changes: 0 additions & 67 deletions pkg/clients/account/v2/client.go

This file was deleted.

Loading
Loading