Skip to content

Commit

Permalink
Add support for QLDB (prometheus-community#1032)
Browse files Browse the repository at this point in the history
Co-authored-by: Cristian Greco <[email protected]>
  • Loading branch information
alexandre-alvarengazh and cristiangreco authored Sep 8, 2023
1 parent e640767 commit 039ba23
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/qldb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: v1alpha1
discovery:
exportedTagsOnMetrics:
qldb:
- Name
jobs:
- type: qldb
regions:
- us-east-2
period: 300
length: 300
metrics:
- name: JournalStorage
statistics:
- Average
- name: IndexedStorage
statistics:
- Average
- name: ReadIOs
statistics:
- Sum
- name: WriteIOs
statistics:
- Sum
- name: CommandLatency
statistics:
- Average
- name: OccConflictExceptions
statistics:
- Sum
- name: Session4xxExceptions
statistics:
- Sum
- name: Session5xxExceptions
statistics:
- Sum
- name: SessionRateExceededExceptions
statistics:
- Sum

10 changes: 10 additions & 0 deletions pkg/config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,16 @@ var SupportedServices = serviceConfigs{
Namespace: "AWS/Prometheus",
Alias: "amp",
},
{
Namespace: "AWS/QLDB",
Alias: "qldb",
ResourceFilters: []*string{
aws.String("qldb"),
},
DimensionRegexps: []*regexp.Regexp{
regexp.MustCompile(":ledger/(?P<LedgerName>[^/]+)"),
},
},
{
Namespace: "AWS/RDS",
Alias: "rds",
Expand Down
76 changes: 76 additions & 0 deletions pkg/job/maxdimassociator/associator_qldb_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package maxdimassociator

import (
"testing"

"github.com/grafana/regexp"
"github.com/stretchr/testify/require"

"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/config"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/logging"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
)

var validQldbInstance = &model.TaggedResource{
ARN: "arn:aws:qldb:us-east-1:123456789012:ledger/test1",
Namespace: "AWS/QLDB",
}

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

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

testcases := []testCase{
{
name: "should match with ledger name dimension",
args: args{
dimensionRegexps: config.SupportedServices.GetService("AWS/QLDB").DimensionRegexps,
resources: []*model.TaggedResource{validQldbInstance},
metric: &model.Metric{
Namespace: "AWS/QLDB",
MetricName: "JournalStorage",
Dimensions: []*model.Dimension{
{Name: "LedgerName", Value: "test2"},
},
},
},
expectedSkip: true,
expectedResource: nil,
},
{
name: "should not match with ledger name dimension when QLDB arn is not valid",
args: args{
dimensionRegexps: config.SupportedServices.GetService("AWS/QLDB").DimensionRegexps,
resources: []*model.TaggedResource{validQldbInstance},
metric: &model.Metric{
Namespace: "AWS/QLDB",
MetricName: "JournalStorage",
Dimensions: []*model.Dimension{
{Name: "LedgerName", Value: "test1"},
},
},
},
expectedSkip: false,
expectedResource: validQldbInstance,
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
associator := NewAssociator(logging.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)
})
}
}

0 comments on commit 039ba23

Please sign in to comment.