Skip to content

Commit 9a26a31

Browse files
fix(context): thread ctx through call chains missing context parameter (#825)
1 parent fe247b0 commit 9a26a31

7 files changed

Lines changed: 12 additions & 12 deletions

File tree

pkg/aws/aws.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func createAWSConfig(ctx context.Context, region, profile, roleARN string) (aws.
299299
}
300300

301301
if roleARN != "" {
302-
role, err := assumeRole(roleARN, optionsFunc)
302+
role, err := assumeRole(ctx, roleARN, optionsFunc)
303303
if err != nil {
304304
return aws.Config{}, err
305305
}
@@ -309,9 +309,9 @@ func createAWSConfig(ctx context.Context, region, profile, roleARN string) (aws.
309309
return awsconfig.LoadDefaultConfig(ctx, optionsFunc...)
310310
}
311311

312-
func assumeRole(roleARN string, options []func(*awsconfig.LoadOptions) error) (awsconfig.LoadOptionsFunc, error) {
312+
func assumeRole(ctx context.Context, roleARN string, options []func(*awsconfig.LoadOptions) error) (awsconfig.LoadOptionsFunc, error) {
313313
// Add the credentials to assume the role specified in config.RoleARN
314-
ac, err := awsconfig.LoadDefaultConfig(context.Background(), options...)
314+
ac, err := awsconfig.LoadDefaultConfig(ctx, options...)
315315
if err != nil {
316316
return nil, err
317317
}

pkg/aws/elb/elb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (c *Collector) Collect(ctx context.Context, ch chan<- prometheus.Metric) er
104104
c.logger.Info("Starting ELB collection")
105105

106106
if c.shouldScrape() {
107-
if err := c.pricingMap.refresh(c.awsRegionClientMap, c.Regions); err != nil {
107+
if err := c.pricingMap.refresh(ctx, c.awsRegionClientMap, c.Regions); err != nil {
108108
c.logger.Error("Failed to refresh pricing", "error", err)
109109
return err
110110
}

pkg/aws/elb/pricing_map.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (pm *ELBPricingMap) GetRegionPricing(region string) (*RegionPricing, error)
6464
return pricing, nil
6565
}
6666

67-
func (pm *ELBPricingMap) refresh(client map[string]client.Client, regions []ec2Types.Region) error {
67+
func (pm *ELBPricingMap) refresh(ctx context.Context, client map[string]client.Client, regions []ec2Types.Region) error {
6868
pm.logger.Info("Refreshing ELB pricing data")
6969

7070
eg := errgroup.Group{}
@@ -73,7 +73,7 @@ func (pm *ELBPricingMap) refresh(client map[string]client.Client, regions []ec2T
7373
for _, region := range regions {
7474
regionName := *region.RegionName
7575
eg.Go(func() error {
76-
pricing, err := pm.FetchRegionPricing(client[regionName], context.Background(), regionName)
76+
pricing, err := pm.FetchRegionPricing(client[regionName], ctx, regionName)
7777
if err != nil {
7878
return fmt.Errorf("failed to fetch pricing for region %s: %w", regionName, err)
7979
}

pkg/azure/aks/region_mapping_generated.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/google/networking/forwarding_rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) error {
8282
func New(ctx context.Context, config *Config, gcpClient client.Client) (*Collector, error) {
8383
logger := config.Logger.With("collector", "forwarding_rule")
8484

85-
pm, err := newPricingMap(logger, gcpClient)
85+
pm, err := newPricingMap(ctx, logger, gcpClient)
8686
if err != nil {
8787
return nil, err
8888
}

pkg/google/networking/pricing_map.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ type pricingMap struct {
6262
mu sync.RWMutex
6363
}
6464

65-
func newPricingMap(logger *slog.Logger, gcpClient client.Client) (*pricingMap, error) {
65+
func newPricingMap(ctx context.Context, logger *slog.Logger, gcpClient client.Client) (*pricingMap, error) {
6666
pm := &pricingMap{
6767
pricing: make(map[string]*pricing),
6868
logger: logger,
6969
gcpClient: gcpClient,
7070
}
7171

72-
if err := pm.populate(context.Background()); err != nil {
72+
if err := pm.populate(ctx); err != nil {
7373
return nil, err
7474
}
7575
return pm, nil

pkg/google/networking/pricing_map_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func TestNewPricingMap_PopulateSuccess(t *testing.T) {
132132

133133
gcpClient := &stubClient{skus: []*billingpb.Sku{frSku, inSku, outSku}}
134134

135-
pm, err := newPricingMap(testLogger, gcpClient)
135+
pm, err := newPricingMap(context.Background(), testLogger, gcpClient)
136136
require.NoError(t, err)
137137

138138
price, err := pm.GetCostOfForwardingRule("us-west1")
@@ -150,7 +150,7 @@ func TestNewPricingMap_PopulateSuccess(t *testing.T) {
150150
func TestNewPricingMap_ErrorNoSKUs(t *testing.T) {
151151
gcpClient := &stubClient{skus: []*billingpb.Sku{}}
152152

153-
pm, err := newPricingMap(testLogger, gcpClient)
153+
pm, err := newPricingMap(context.Background(), testLogger, gcpClient)
154154
require.Nil(t, pm)
155155
require.Error(t, err)
156156
require.ErrorIs(t, err, ErrNoSKUsFoundForNetworkingService)

0 commit comments

Comments
 (0)