github.com/grafana/synthetic-monitoring-agent@v0.64.2/internal/cals/cals.go (about) 1 package cals 2 3 import ( 4 "context" 5 "errors" 6 "fmt" 7 8 "github.com/grafana/synthetic-monitoring-agent/internal/model" 9 sm "github.com/grafana/synthetic-monitoring-agent/pkg/pb/synthetic_monitoring" 10 ) 11 12 var ( 13 ErrTenantProvider = errors.New("fetching tenant data") 14 ) 15 16 type TenantProvider interface { 17 GetTenant(context.Context, *sm.TenantInfo) (*sm.Tenant, error) 18 } 19 20 // CostAttributionLabels has a TenantProvider that pulls data about a specific tenant 21 type CostAttributionLabels struct { 22 provider TenantProvider 23 } 24 25 // NewCostAttributionLabels is a helper method to create a NewCostAttributionLabels provider 26 func NewCostAttributionLabels(provider TenantProvider) *CostAttributionLabels { 27 return &CostAttributionLabels{ 28 provider: provider, 29 } 30 } 31 32 // CostAttributionLabels will call TenantProvider.GetTenant to search for a specific tenant and returns Tenant.CostAttributionLabels 33 func (tcal CostAttributionLabels) CostAttributionLabels(ctx context.Context, tenantID model.GlobalID) ([]string, error) { 34 tenant, err := tcal.provider.GetTenant(ctx, &sm.TenantInfo{ 35 Id: int64(tenantID), 36 }) 37 if err != nil { 38 return nil, fmt.Errorf("%w: %v", ErrTenantProvider, err) 39 } 40 41 return tenant.CostAttributionLabels, nil 42 }