Skip to content

Commit

Permalink
Add support for AWS/ClientVPN (prometheus-community#1128)
Browse files Browse the repository at this point in the history
Co-authored-by: Cristian Greco <[email protected]>
  • Loading branch information
hc2p and cristiangreco authored Sep 8, 2023
1 parent 824ace1 commit a26b9f8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,16 @@ var SupportedServices = serviceConfigs{
regexp.MustCompile(":vpn-connection/(?P<VpnId>[^/]+)"),
},
},
{
Namespace: "AWS/ClientVPN",
Alias: "clientvpn",
ResourceFilters: []*string{
aws.String("ec2:client-vpn-endpoint"),
},
DimensionRegexps: []*regexp.Regexp{
regexp.MustCompile(":client-vpn-endpoint/(?P<Endpoint>[^/]+)"),
},
},
{
Namespace: "AWS/WAFV2",
Alias: "wafv2",
Expand Down
60 changes: 60 additions & 0 deletions pkg/job/maxdimassociator/associator_client_vpn_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 clientVpn = &model.TaggedResource{
ARN: "arn:aws:ec2:eu-central-1:075055617227:client-vpn-endpoint/cvpn-endpoint-0c9e5bd20be71e296",
Namespace: "AWS/ClientVPN",
}

func TestAssociatorClientVPN(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 ClientVPN with Endpoint dimension",
args: args{
dimensionRegexps: config.SupportedServices.GetService("AWS/ClientVPN").DimensionRegexps,
resources: []*model.TaggedResource{clientVpn},
metric: &model.Metric{
MetricName: "CrlDaysToExpiry",
Namespace: "AWS/ClientVPN",
Dimensions: []*model.Dimension{
{Name: "Endpoint", Value: "cvpn-endpoint-0c9e5bd20be71e296"},
},
},
},
expectedSkip: false,
expectedResource: clientVpn,
},
}

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 a26b9f8

Please sign in to comment.