Skip to content
Open
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ As a quick start, the following IAM policy can be used to grant the all permissi
"apigateway:GET",
"aps:ListWorkspaces",
"autoscaling:DescribeAutoScalingGroups",
"bedrock:ListInferenceProfiles",
"bedrock:ListTagsForResource",
"dms:DescribeReplicationInstances",
"dms:DescribeReplicationTasks",
"ec2:DescribeTransitGatewayAttachments",
Expand Down Expand Up @@ -211,6 +213,13 @@ This permission is required to discover resources for the AWS/AutoScaling namesp
"autoscaling:DescribeAutoScalingGroups"
```

These permissions are required to discover resources (application inference profiles) and their
tags for the AWS/Bedrock namespace
```json
"bedrock:ListInferenceProfiles",
"bedrock:ListTagsForResource"
```

These permissions are required to discover resources for the AWS/DMS namespace
```json
"dms:DescribeReplicationInstances",
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module github.com/prometheus-community/yet-another-cloudwatch-exporter
go 1.25.0

require (
github.com/aws/aws-sdk-go-v2 v1.42.1
github.com/aws/aws-sdk-go-v2 v1.43.3
github.com/aws/aws-sdk-go-v2/config v1.32.30
github.com/aws/aws-sdk-go-v2/credentials v1.19.29
github.com/aws/aws-sdk-go-v2/service/amp v1.45.2
github.com/aws/aws-sdk-go-v2/service/apigateway v1.41.1
github.com/aws/aws-sdk-go-v2/service/apigatewayv2 v1.36.1
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.69.1
github.com/aws/aws-sdk-go-v2/service/bedrock v1.66.3
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.63.1
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.65.1
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.60.1
Expand All @@ -22,7 +23,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/shield v1.36.1
github.com/aws/aws-sdk-go-v2/service/storagegateway v1.45.2
github.com/aws/aws-sdk-go-v2/service/sts v1.44.1
github.com/aws/smithy-go v1.27.4
github.com/aws/smithy-go v1.27.6
github.com/grafana/regexp v0.0.0-20250905093917-f7b3be9d1853
github.com/prometheus/client_golang v1.23.2
github.com/prometheus/client_model v0.6.2
Expand All @@ -41,8 +42,8 @@ require (
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.31 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.12.7 // indirect
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjH
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b h1:mimo19zliBX/vSQ6PWWSL9lK8qwHozUj03+zLoEB8O0=
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs=
github.com/aws/aws-sdk-go-v2 v1.42.1 h1:9eOTgu1z/dVtYpNZ3/8/XbbaX0x/BqE3HUzAzs6K0ek=
github.com/aws/aws-sdk-go-v2 v1.42.1/go.mod h1:5pKeft2eJj+gElQ38Jqg4ibCqh+/AK33/0X3hip7IjM=
github.com/aws/aws-sdk-go-v2 v1.43.3 h1:XJIcfv8uDs2ukdQsoAC8/Ebu1ejxwzlayl2ZsiFns2A=
github.com/aws/aws-sdk-go-v2 v1.43.3/go.mod h1:70vwSy16txshwG+g55WkpgPKDIByzHI8ccBsOteo3bQ=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14 h1:3IZY0XAJquT3aHzbkHfPzy4ACPcEjVG0x87KOwtpqGY=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14/go.mod h1:zwM6veDkhGgQFqkBy+uT28AAYpLu+uFMlPl+rCg/73E=
github.com/aws/aws-sdk-go-v2/config v1.32.30 h1:XwsEzpTJfQYJbFicz/QMLwAZdyeNVVoOEkbF7R3gPJk=
Expand All @@ -12,10 +12,10 @@ github.com/aws/aws-sdk-go-v2/credentials v1.19.29 h1:WHZGssHH887cO0ox07SIQZsFx3M
github.com/aws/aws-sdk-go-v2/credentials v1.19.29/go.mod h1:Mhl0xR6zjguiuj00XRx2wMx22sAltk7oya39sT7fdg8=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.30 h1:/hi1JADLEW9YYryEz1w4GQu0EtP23pP553Cf9KgsDV4=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.30/go.mod h1:/3AOgy4K17Dm4ucMZVC/MJkzy5kmfKUcINRHZyo0koQ=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.30 h1:xM/Is9cKMHa8Jj8zkvWhvrFkZsXJV9E+BB4g0HW0duQ=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.30/go.mod h1:WueJeNDZvK1fMYEWJIkcivBfEzUkTpBhzlrUKKY8EuA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.30 h1:jn46zC9LdsVR/ZpMIJqMqb8hHv31BlLx3ulVqNspUOk=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.30/go.mod h1:1hTMsAgbdS/AtUi4bw8+gUuh1pceo+eXRLfpSuSQj3M=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.34 h1:vuIfjzoeqhQMGJyOBU3t0ZEjn2jrN8Bbg1N4CgjzM5Q=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.34/go.mod h1:hP28cN4CPJLZHirdQPrZR50JcLN4ApRJP2tzG8cRlhY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.34 h1:9faHsnqxJ1vDvB4wMZy/ajIDyz5QhllQjjc72RJpXAw=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.34/go.mod h1:Yp6nIyejpa23nzlB/LhT63KTla9Jdi06nv/HH/OkAH8=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.31 h1:3GUprIsfmGcC5SACIyB0e7E0BM1O1b3Erl5CePYIAeQ=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.31/go.mod h1:7PuV1yl5e2xnUbm+RqvVg5i2iBM8EyijZNoI9wsOoOc=
github.com/aws/aws-sdk-go-v2/service/amp v1.45.2 h1:KerxNN65th2ZTKf+wltZgiHOQ9KO2gcEtrpVHrpJ9pY=
Expand All @@ -26,6 +26,8 @@ github.com/aws/aws-sdk-go-v2/service/apigatewayv2 v1.36.1 h1:nkSb00GdOiHUpl07Bd4
github.com/aws/aws-sdk-go-v2/service/apigatewayv2 v1.36.1/go.mod h1:3GU3RMoNjUKXg6GDelv+7bIiJGqk6JXUTmMlvc6+SrU=
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.69.1 h1:r3nQYmQYCFjEYAvHGw1HPTu1AkSZVqkWHehdIJnSiZw=
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.69.1/go.mod h1:sN7IK8djnxCOQDGVhOvUlIA83i1wIA5jYnzr2TlY9a8=
github.com/aws/aws-sdk-go-v2/service/bedrock v1.66.3 h1:XipaRLJ12/xg+Q2m9K4OkjOrySZuI61HU7bJFVamcNw=
github.com/aws/aws-sdk-go-v2/service/bedrock v1.66.3/go.mod h1:T46juyeeEVRrIMNFhe3P7h7B8bbROERSebRlwPE+K8Q=
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.63.1 h1:KmShXFvPzgolFsYnnDErV+Sj1/orgDaf4tbz+9N+d78=
github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.63.1/go.mod h1:lipiF9DI3EmTTkEn2sgLug3iEO1dXM50FDFooey6vYU=
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.65.1 h1:WdQFYjLnugfTSJ3fpzrSvefUYcXZyjZeqR0DuDRxK/Q=
Expand Down Expand Up @@ -62,8 +64,8 @@ github.com/aws/aws-sdk-go-v2/service/storagegateway v1.45.2 h1:WXZ/I7Q2H6abDIuGR
github.com/aws/aws-sdk-go-v2/service/storagegateway v1.45.2/go.mod h1:MaL+I3CJyElQoPUXT697xCJhZxxVfvQXfHNvB0bz2p0=
github.com/aws/aws-sdk-go-v2/service/sts v1.44.1 h1:RvfHDg+xvAeZ+5741vUEjpOVtYSIm93W2zhx10Xtydw=
github.com/aws/aws-sdk-go-v2/service/sts v1.44.1/go.mod h1:9gdl4RrflIdpDb2TlXshWgR1F9TeCkvqDx77Vpr4Z/Q=
github.com/aws/smithy-go v1.27.4 h1:JQcphmBN4f0q/sPqXqROIItRNV/hy10cgu7CsFy616M=
github.com/aws/smithy-go v1.27.4/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/aws/smithy-go v1.27.6 h1:0zjT8jgK3jbrTT7JJ3EE6JsMhX8JTrZ+f1sEndYDXrA=
github.com/aws/smithy-go v1.27.6/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down
16 changes: 16 additions & 0 deletions pkg/clients/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/apigateway"
"github.com/aws/aws-sdk-go-v2/service/apigatewayv2"
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
"github.com/aws/aws-sdk-go-v2/service/bedrock"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
"github.com/aws/aws-sdk-go-v2/service/ec2"
Expand Down Expand Up @@ -203,6 +204,7 @@ func (c *CachingFactory) GetTaggingClient(region string, role model.Role, concur
c.createPrometheusClient(c.clients[role][region].awsConfig),
c.createStorageGatewayClient(c.clients[role][region].awsConfig),
c.createShieldClient(c.clients[role][region].awsConfig),
c.createBedrockClient(c.clients[role][region].awsConfig),
)
return tagging.NewLimitedConcurrencyClient(client, concurrencyLimit)
}
Expand Down Expand Up @@ -432,6 +434,20 @@ func (c *CachingFactory) createShieldClient(awsConfig *aws.Config) *shield.Clien
})
}

func (c *CachingFactory) createBedrockClient(assumedConfig *aws.Config) *bedrock.Client {
return bedrock.NewFromConfig(*assumedConfig, func(options *bedrock.Options) {
if c.logger != nil && c.logger.Enabled(context.Background(), slog.LevelDebug) {
options.ClientLogMode = aws.LogRequestWithBody | aws.LogResponseWithBody
}
if c.endpointURLOverride != "" {
options.BaseEndpoint = aws.String(c.endpointURLOverride)
}
if c.fipsEnabled {
options.EndpointOptions.UseFIPSEndpoint = aws.FIPSEndpointStateEnabled
}
})
}

func createStsOptions(stsRegion string, isDebugLoggingEnabled bool, endpointURLOverride string, fipsEnabled bool) func(*sts.Options) {
return func(options *sts.Options) {
if stsRegion != "" {
Expand Down
22 changes: 22 additions & 0 deletions pkg/clients/tagging/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/apigateway"
"github.com/aws/aws-sdk-go-v2/service/apigatewayv2"
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
"github.com/aws/aws-sdk-go-v2/service/bedrock"
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi"
Expand Down Expand Up @@ -141,6 +142,27 @@ func (a prometheusClientAdapter) ListWorkspaces(ctx context.Context, params *amp
return a.listWorkspaces(ctx, params, optFns...)
}

// bedrockClientAdapter wraps *bedrock.Client via closures.
type bedrockClientAdapter struct {
listInferenceProfiles func(ctx context.Context, params *bedrock.ListInferenceProfilesInput, optFns ...func(*bedrock.Options)) (*bedrock.ListInferenceProfilesOutput, error)
listTagsForResource func(ctx context.Context, params *bedrock.ListTagsForResourceInput, optFns ...func(*bedrock.Options)) (*bedrock.ListTagsForResourceOutput, error)
}

func newBedrockClientAdapter(c *bedrock.Client) bedrockClientAdapter {
return bedrockClientAdapter{
listInferenceProfiles: c.ListInferenceProfiles,
listTagsForResource: c.ListTagsForResource,
}
}

func (a bedrockClientAdapter) ListInferenceProfiles(ctx context.Context, params *bedrock.ListInferenceProfilesInput, optFns ...func(*bedrock.Options)) (*bedrock.ListInferenceProfilesOutput, error) {
return a.listInferenceProfiles(ctx, params, optFns...)
}

func (a bedrockClientAdapter) ListTagsForResource(ctx context.Context, params *bedrock.ListTagsForResourceInput, optFns ...func(*bedrock.Options)) (*bedrock.ListTagsForResourceOutput, error) {
return a.listTagsForResource(ctx, params, optFns...)
}

// storageGatewayClientAdapter wraps *storagegateway.Client via closures.
type storageGatewayClientAdapter struct {
listGateways func(ctx context.Context, params *storagegateway.ListGatewaysInput, optFns ...func(*storagegateway.Options)) (*storagegateway.ListGatewaysOutput, error)
Expand Down
5 changes: 5 additions & 0 deletions pkg/clients/tagging/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/apigateway"
"github.com/aws/aws-sdk-go-v2/service/apigatewayv2"
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
"github.com/aws/aws-sdk-go-v2/service/bedrock"
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi"
Expand All @@ -48,6 +49,7 @@ var (
_ amp.ListWorkspacesAPIClient = prometheusClientAdapter{}
_ storagegateway.ListGatewaysAPIClient = storageGatewayClientAdapter{}
_ shield.ListProtectionsAPIClient = shieldClientAdapter{}
_ bedrock.ListInferenceProfilesAPIClient = bedrockClientAdapter{}
)

type Client interface {
Expand All @@ -68,6 +70,7 @@ type client struct {
prometheusSvcAPI prometheusClientAdapter
storageGatewayAPI storageGatewayClientAdapter
shieldAPI shieldClientAdapter
bedrockAPI bedrockClientAdapter
}

func NewClient(
Expand All @@ -82,6 +85,7 @@ func NewClient(
prometheusClient *amp.Client,
storageGatewayAPI *storagegateway.Client,
shieldAPI *shield.Client,
bedrockAPI *bedrock.Client,
) Client {
if scrapeMetrics == nil {
scrapeMetrics = promutil.Discard
Expand All @@ -98,6 +102,7 @@ func NewClient(
prometheusSvcAPI: newPrometheusClientAdapter(prometheusClient),
storageGatewayAPI: newStorageGatewayClientAdapter(storageGatewayAPI),
shieldAPI: newShieldClientAdapter(shieldAPI),
bedrockAPI: newBedrockClientAdapter(bedrockAPI),
}
}

Expand Down
57 changes: 57 additions & 0 deletions pkg/clients/tagging/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/apigateway"
"github.com/aws/aws-sdk-go-v2/service/apigatewayv2"
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
"github.com/aws/aws-sdk-go-v2/service/bedrock"
"github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/shield"
Expand Down Expand Up @@ -136,6 +137,62 @@ var ServiceFilters = map[string]ServiceFilter{
return resources, nil
},
},
"AWS/Bedrock": {
// Bedrock application inference profiles aren't discoverable via the tagging API in a
// way that also surfaces the profile's human-readable name, so ListInferenceProfiles is
// used directly here instead. The profile's InferenceProfileId is what CloudWatch's
// ModelId dimension is set to for these resources (not the ARN), so the ARN field here
// is repurposed - like AWS/StorageGateway does - to carry "<id>/<name>" instead of the
// real ARN. This lets the ModelId dimension regex (see pkg/config/services.go) match the
// id prefix, while the profile name still ends up in the metric's "name" label.
ResourceFunc: func(ctx context.Context, client client, job model.DiscoveryJob, region string) ([]*model.TaggedResource, error) {
const maxPages = 100
pageNum := 0

var resources []*model.TaggedResource
paginator := bedrock.NewListInferenceProfilesPaginator(client.bedrockAPI, &bedrock.ListInferenceProfilesInput{}, func(options *bedrock.ListInferenceProfilesPaginatorOptions) {
options.StopOnDuplicateToken = true
})

for paginator.HasMorePages() && pageNum < maxPages {
page, err := paginator.NextPage(ctx)
client.scrapeMetrics.BedrockAPICounter.Inc()
if err != nil {
return nil, fmt.Errorf("error calling bedrockAPI.ListInferenceProfiles, %w", err)
}
pageNum++

for _, profile := range page.InferenceProfileSummaries {
resource := model.TaggedResource{
ARN: fmt.Sprintf("%s/%s", *profile.InferenceProfileId, *profile.InferenceProfileName),
Namespace: job.Namespace,
Region: region,
}

tagsRequest := &bedrock.ListTagsForResourceInput{
ResourceARN: profile.InferenceProfileArn,
}
// System-defined profiles are owned by AWS rather than the caller's account and
// don't support tagging, so ListTagsForResource is expected to fail for them.
// Treat that as "no tags" instead of aborting discovery for the whole namespace.
tagsResponse, err := client.bedrockAPI.ListTagsForResource(ctx, tagsRequest)
client.scrapeMetrics.BedrockAPICounter.Inc()

if err == nil {
for _, t := range tagsResponse.Tags {
resource.Tags = append(resource.Tags, model.Tag{Key: *t.Key, Value: *t.Value})
}
}

if resource.FilterThroughTags(job.SearchTags) {
resources = append(resources, &resource)
}
}
}

return resources, nil
},
},
"AWS/DMS": {
// Append the replication instance identifier to DMS task and instance ARNs
FilterFunc: func(ctx context.Context, client client, inputResources []*model.TaggedResource) ([]*model.TaggedResource, error) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,15 @@ var SupportedServices = serviceConfigs{
},
},
{
// Resources for this namespace are discovered via a ServiceFilter ResourceFunc
// (see pkg/clients/tagging/filters.go) rather than ResourceFilters, because
// application inference profiles aren't returned by the tagging API in a way
// that also carries the profile's human-readable name.
Namespace: "AWS/Bedrock",
Alias: "bedrock",
DimensionRegexps: []*regexp.Regexp{
regexp.MustCompile("^(?P<ModelId>[^/]+)/"),
},
},
{
Namespace: "AWS/Bedrock/Agents",
Expand Down
91 changes: 91 additions & 0 deletions pkg/job/maxdimassociator/associator_bedrock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 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 maxdimassociator

import (
"testing"

"github.com/prometheus/common/promslog"
"github.com/stretchr/testify/require"

"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/config"
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/model"
)

var bedrockApplicationInferenceProfile = &model.TaggedResource{
ARN: "p152fiotth4d/var-review-agent",
Namespace: "AWS/Bedrock",
}

var bedrockResources = []*model.TaggedResource{
bedrockApplicationInferenceProfile,
}

func TestAssociatorBedrock(t *testing.T) {
type args struct {
dimensionRegexps []model.DimensionsRegexp
resources []*model.TaggedResource
metric *model.Metric
}

type testCase struct {
name string
args args
expectedSkip bool
expectedResource *model.TaggedResource
}

testcases := []testCase{
{
name: "should match application inference profile with ModelId dimension",
args: args{
dimensionRegexps: config.SupportedServices.GetService("AWS/Bedrock").ToModelDimensionsRegexp(),
resources: bedrockResources,
metric: &model.Metric{
MetricName: "InputTokenCount",
Namespace: "AWS/Bedrock",
Dimensions: []model.Dimension{
{Name: "ModelId", Value: "p152fiotth4d"},
},
},
},
expectedSkip: false,
expectedResource: bedrockApplicationInferenceProfile,
},
{
name: "should skip foundation model ModelId not backed by a tagged resource",
args: args{
dimensionRegexps: config.SupportedServices.GetService("AWS/Bedrock").ToModelDimensionsRegexp(),
resources: bedrockResources,
metric: &model.Metric{
MetricName: "InputTokenCount",
Namespace: "AWS/Bedrock",
Dimensions: []model.Dimension{
{Name: "ModelId", Value: "anthropic.claude-3-haiku-20240307-v1:0"},
},
},
},
expectedSkip: true,
expectedResource: nil,
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
associator := NewAssociator(promslog.NewNopLogger(), tc.args.dimensionRegexps, tc.args.resources)
res, skip := associator.AssociateMetricToResource(tc.args.metric)
require.Equal(t, tc.expectedSkip, skip)
require.Equal(t, tc.expectedResource, res)
})
}
}
Loading