Skip to content

Conversation

@Pokom
Copy link
Contributor

@Pokom Pokom commented Oct 6, 2025

Following a similar path as limits to pull cost attribution labels for
tenants. Adds a new internal library cals/cals.go that provides an
interface that wraps the TenantProvider client. Updates all of the
wiring from Updated => Scraper to pass along the new cal client.

Starts the process of using the library in scraper.go, which right now
finds the cost attribution labels for a specific tenant. Returns an
empty slice if nothing is found.

This will be dependent upon the API changes being released to get cost
attribution labels defined at the tenant level.

My goal is to have a follow up PR that updates the telemeter bits to track executions by cost attribution labels.

@Pokom Pokom force-pushed the feat/pull-cost-attribution-labels-from-tenant branch from ee3f691 to 3c4d581 Compare October 22, 2025 18:24
Pokom added 5 commits October 23, 2025 15:27
Following a similar path as limits to pull cost attribution labels for
tenants. Adds a new internal library `cals/tenant.go` that provides an
interface that wraps the `TenantProvider` client. Updates all of the
wiring from Updated => Scraper to pass along the new cal client.

Starts the process of using the library in `scraper.go`, which right now
finds the cost attribution labels for a specific tenant. Returns an
empty slice if nothing is found.

This will be dependant upon the API changes being released to get cost
attribution labels defined at the tenant level.
Add a `testCalTenants` interface to mock out the cost attribution label
servce. This fixes the tests that were failing on the latest commits to
main.
It didn't quite feel right to call the package `cals` but then refer to
everything as tenants. This change makes it such that everything is
cals, and that the provider is a TenantProvider. I believe this clearly
communicates what the cals package is meant for.
@Pokom Pokom force-pushed the feat/pull-cost-attribution-labels-from-tenant branch from 785ebb1 to 10208df Compare October 23, 2025 19:28
@Pokom Pokom marked this pull request as ready for review October 23, 2025 19:29
@Pokom Pokom requested a review from a team as a code owner October 23, 2025 19:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for pulling cost attribution labels from tenant configuration. The implementation introduces a new cals package that wraps the TenantProvider client to fetch cost attribution labels at the tenant level, following a similar pattern to the existing limits functionality.

Key changes:

  • New cals package with CostAttributionLabels client for fetching tenant-specific cost attribution labels
  • Updated scraper to retrieve and log cost attribution labels during check execution
  • Wiring changes throughout the codebase to pass the new CAL client from main through to scrapers

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/cals/cals.go New package implementing TenantProvider wrapper for cost attribution labels
internal/cals/cals_test.go Unit tests for the new cost attribution labels functionality
cmd/synthetic-monitoring-agent/main.go Initializes and passes CAL client to the updater
internal/checks/checks.go Wires CAL client through updater to scrapers
internal/checks/checks_test.go Updates test scraper factory signature
internal/scraper/scraper.go Integrates CAL client, retrieves and logs labels during scraping
internal/scraper/scraper_test.go Adds test mock for CAL interface

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Pokom added 2 commits October 23, 2025 15:37
I must have taken the wrong change when rebasing. This caused issues
with linters as gocyclo may have been removed
@Pokom Pokom changed the title Feat/pull cost attribution labels from tenant feat: Pull cost attribution labels for tenant Oct 23, 2025
Copy link
Contributor

@The-9880 The-9880 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nits, LGTM!

labelsLimiter LabelsLimiter,
telemeter *telemetry.Telemeter,
secretStore *secrets.TenantSecrets,
costAttributionLabels *cals.CostAttributionLabels,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the interface here as well:

Suggested change
costAttributionLabels *cals.CostAttributionLabels,
costAttributionLabels TenantCals,

labelsLimiter LabelsLimiter,
telemeter *telemetry.Telemeter,
secretStore *secrets.TenantSecrets,
cals *cals.CostAttributionLabels,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the interface here as well:

Suggested change
cals *cals.CostAttributionLabels,
cals TenantCals,

tcal := NewCostAttributionLabels(testcase.tenantProvider)
cals, err := tcal.CostAttributionLabels(context.Background(), 1)
if testcase.expectError {
require.NotNil(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're interested in a typed assertion here, you could define the following error in cals.go:

var (
    ErrTenantProvider := errors.New("fetching tenant data")
)

And update the CostAttributionLabels(...) method to wrap the tenant provider error:

if err != nil {
	return nil, fmt.Errorf("%w: %v", ErrTenantProvider, err)
}

Which you could assert for here like so:

if testcase.expectError {
	require.ErrorIs(t, err, TenantProviderError)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants