Skip to content

Commit 3a2d0c4

Browse files
Associate Cassandra tables
Associates Amazon Keyspaces (for Apache Cassandra) tables based on the metric dimensions, similar to many other services. Signed-off-by: Johannes Gehrs <[email protected]>
1 parent 49a296a commit 3a2d0c4

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

pkg/config/services.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ var SupportedServices = serviceConfigs{
222222
ResourceFilters: []*string{
223223
aws.String("cassandra"),
224224
},
225+
DimensionRegexps: []*regexp.Regexp{
226+
regexp.MustCompile("keyspace/(?P<Keyspace>[^/]+)/table/(?P<TableName>[^/]+)"),
227+
},
225228
},
226229
{
227230
Namespace: "AWS/CloudFront",
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2024 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
package maxdimassociator
14+
15+
import (
16+
"testing"
17+
18+
"github.com/stretchr/testify/require"
19+
20+
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/config"
21+
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/logging"
22+
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/model"
23+
)
24+
25+
var keyspacesTable = &model.TaggedResource{
26+
ARN: "arn:aws:cassandra:eu-west-1:123456789012:/keyspace/my_keyspace/table/my_table",
27+
Namespace: "AWS/Cassanrdra",
28+
}
29+
30+
var cassandraResources = []*model.TaggedResource{
31+
keyspacesTable,
32+
}
33+
34+
func TestAssociatorCassandra(t *testing.T) {
35+
type args struct {
36+
dimensionRegexps []model.DimensionsRegexp
37+
resources []*model.TaggedResource
38+
metric *model.Metric
39+
}
40+
41+
type testCase struct {
42+
name string
43+
args args
44+
expectedSkip bool
45+
expectedResource *model.TaggedResource
46+
}
47+
48+
testcases := []testCase{
49+
{
50+
name: "keyspace should match with clusterId dimension",
51+
args: args{
52+
dimensionRegexps: config.SupportedServices.GetService("AWS/Cassandra").ToModelDimensionsRegexp(),
53+
resources: cassandraResources,
54+
metric: &model.Metric{
55+
MetricName: "BillableTableSizeInBytes",
56+
Namespace: "AWS/Cassandra",
57+
Dimensions: []model.Dimension{
58+
{Name: "Keyspace", Value: "my_keyspace"},
59+
{Name: "TableName", Value: "my_table"},
60+
},
61+
},
62+
},
63+
expectedSkip: false,
64+
expectedResource: keyspacesTable,
65+
},
66+
}
67+
68+
for _, tc := range testcases {
69+
t.Run(tc.name, func(t *testing.T) {
70+
associator := NewAssociator(logging.NewNopLogger(), tc.args.dimensionRegexps, tc.args.resources)
71+
res, skip := associator.AssociateMetricToResource(tc.args.metric)
72+
require.Equal(t, tc.expectedSkip, skip)
73+
require.Equal(t, tc.expectedResource, res)
74+
})
75+
}
76+
}

0 commit comments

Comments
 (0)