diff --git a/examples/qldb.yml b/examples/qldb.yml new file mode 100644 index 000000000..4b4d76832 --- /dev/null +++ b/examples/qldb.yml @@ -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 + diff --git a/pkg/config/services.go b/pkg/config/services.go index 4b0f35483..a2f54eb76 100644 --- a/pkg/config/services.go +++ b/pkg/config/services.go @@ -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[^/]+)"), + }, + }, { Namespace: "AWS/RDS", Alias: "rds", diff --git a/pkg/job/maxdimassociator/associator_qldb_test.go b/pkg/job/maxdimassociator/associator_qldb_test.go new file mode 100644 index 000000000..e2244f0b1 --- /dev/null +++ b/pkg/job/maxdimassociator/associator_qldb_test.go @@ -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) + }) + } +}