Skip to content

Commit ce57a21

Browse files
author
nicolas.bazinet
committed
feat: Add support for Redshift-Serverless
Signed-off-by: nickbazinet <nicolas.bazinet@hotmail.com>
1 parent 49a296a commit ce57a21

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Only the latest version gets security updates. We won't support older versions.
118118
* `AWS/QuickSight` - QuickSight (Business Intelligence)
119119
* `AWS/RDS` - Relational Database Service
120120
* `AWS/Redshift` - Redshift Database
121+
* `AWS/Redshift-Serverless` - Redshift Serverless
121122
* `AWS/Route53` - Route53 Health Checks
122123
* `AWS/Route53Resolver` - Route53 Resolver
123124
* `AWS/RUM` - Real User Monitoring

examples/redshift-serverless.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v1alpha1
2+
discovery:
3+
jobs:
4+
- type: AWS/Redshift-Serverless
5+
regions:
6+
- us-east-1
7+
period: 300
8+
length: 300
9+
metrics:
10+
- name: DatabaseConnections
11+
statistics: [Average]
12+
- name: ComputeCapacity
13+
statistics: [Average]
14+
- name: QueryRuntimeBreakdown
15+
statistics: [Average]
16+
- name: QueriesRunning
17+
statistics: [Average]
18+
- name: QueriesQueued
19+
statistics: [Average]
20+
- name: QueryDuration
21+
statistics: [Average]

pkg/config/services.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,14 @@ var SupportedServices = serviceConfigs{
760760
regexp.MustCompile(":cluster:(?P<ClusterIdentifier>[^/]+)"),
761761
},
762762
},
763+
{
764+
Namespace: "AWS/Redshift-Serverless",
765+
Alias: "redshift",
766+
ResourceFilters: []*string{
767+
aws.String("redshift-serverless:workgroup"),
768+
aws.String("redshift-serverless:namespace"),
769+
},
770+
},
763771
{
764772
Namespace: "AWS/Route53Resolver",
765773
Alias: "route53-resolver",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 workgroup = &model.TaggedResource{
26+
ARN: "arn:aws:redshift-serverless:us-east-1:123456789012:workgroup/my-workgroup1",
27+
Namespace: "AWS/Redshift-Serverless",
28+
}
29+
30+
var namespace = &model.TaggedResource{
31+
ARN: "arn:aws:redshift-serverless:us-east-1:123456789012:namespace/my-namespace1",
32+
Namespace: "AWS/Redshift-Serverless",
33+
}
34+
35+
var redshiftResources = []*model.TaggedResource{
36+
workgroup,
37+
namespace,
38+
}
39+
40+
func TestAssociatorRedshiftServerless(t *testing.T) {
41+
type args struct {
42+
dimensionRegexps []model.DimensionsRegexp
43+
resources []*model.TaggedResource
44+
metric *model.Metric
45+
}
46+
47+
type testCase struct {
48+
name string
49+
args args
50+
expectedSkip bool
51+
expectedResource *model.TaggedResource
52+
}
53+
54+
testcases := []testCase{
55+
{
56+
name: "should not match nor skip with any workgroup none ARN dimension",
57+
args: args{
58+
dimensionRegexps: config.SupportedServices.GetService("AWS/Redshift-Serverless").ToModelDimensionsRegexp(),
59+
resources: redshiftResources,
60+
metric: &model.Metric{
61+
MetricName: "ComputeSeconds",
62+
Namespace: "AWS/Redshift-Serverless",
63+
Dimensions: []model.Dimension{
64+
{Name: "ResourceArn", Value: "my-nonexistant-workgroup-test1"},
65+
},
66+
},
67+
},
68+
expectedSkip: false,
69+
expectedResource: nil,
70+
},
71+
}
72+
73+
for _, tc := range testcases {
74+
t.Run(tc.name, func(t *testing.T) {
75+
associator := NewAssociator(logging.NewNopLogger(), tc.args.dimensionRegexps, tc.args.resources)
76+
res, skip := associator.AssociateMetricToResource(tc.args.metric)
77+
require.Equal(t, tc.expectedSkip, skip)
78+
require.Equal(t, tc.expectedResource, res)
79+
})
80+
}
81+
}

0 commit comments

Comments
 (0)