Skip to content

Commit 8262f53

Browse files
Add auto-discovery for Directory Services(MicrosoftAD) #757 (#1556)
Signed-off-by: Ruslan Mustaev <ruslan.mustaev@orionhealth.com> Signed-off-by: Cristian Greco <cristian@regolo.cc> Co-authored-by: Cristian Greco <cristian@regolo.cc>
1 parent 2ee4901 commit 8262f53

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Only the latest version gets security updates. We won't support older versions.
7171
* `AWS/Cognito` - Cognito
7272
* `AWS/DataSync` - DataSync
7373
* `AWS/DDoSProtection` - Distributed Denial of Service (DDoS) protection service
74+
* `AWS/DirectoryService` - Directory Services (MicrosoftAD)
7475
* `AWS/DMS` - Database Migration Service
7576
* `AWS/DocDB` - DocumentDB (with MongoDB compatibility)
7677
* `AWS/DX` - Direct Connect

examples/ds.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1alpha1
2+
discovery:
3+
jobs:
4+
- type: AWS/DirectoryService
5+
regions:
6+
- us-east-1
7+
period: 300
8+
length: 300
9+
metrics:
10+
- name: "Bytes Sent/sec"
11+
statistics: [Average]
12+
- name: "% Processor Time"
13+
statistics: [Average]
14+
- name: "DS Directory Searches/Sec"
15+
statistics: [Average]
16+
- name: "Database Cache % Hit"
17+
statistics: [Average]
18+
- name: "% Free Space"
19+
statistics: [Sum]

pkg/config/services.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ var SupportedServices = serviceConfigs{
255255
regexp.MustCompile(":agent/(?P<AgentId>[^/]+)"),
256256
},
257257
},
258+
{
259+
Namespace: "AWS/DirectoryService",
260+
Alias: "ds",
261+
ResourceFilters: []*string{
262+
aws.String("ds:directory"),
263+
},
264+
DimensionRegexps: []*regexp.Regexp{
265+
regexp.MustCompile(":directory/(?P<Directory_ID>[^/]+)"),
266+
},
267+
},
258268
{
259269
Namespace: "AWS/DMS",
260270
Alias: "dms",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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/prometheus/common/promslog"
19+
"github.com/stretchr/testify/require"
20+
21+
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/config"
22+
"github.com/prometheus-community/yet-another-cloudwatch-exporter/pkg/model"
23+
)
24+
25+
var directory = &model.TaggedResource{
26+
ARN: "arn:aws:ds::012345678901:directory/d-abc123",
27+
Namespace: "AWS/DirectoryService",
28+
}
29+
30+
func TestAssociatorDirectoryService(t *testing.T) {
31+
type args struct {
32+
dimensionRegexps []model.DimensionsRegexp
33+
resources []*model.TaggedResource
34+
metric *model.Metric
35+
}
36+
37+
type testCase struct {
38+
name string
39+
args args
40+
expectedSkip bool
41+
expectedResource *model.TaggedResource
42+
}
43+
44+
testcases := []testCase{
45+
{
46+
name: "should match directory id with Directory ID dimension",
47+
args: args{
48+
dimensionRegexps: config.SupportedServices.GetService("AWS/DirectoryService").ToModelDimensionsRegexp(),
49+
resources: []*model.TaggedResource{directory},
50+
metric: &model.Metric{
51+
MetricName: "Current Bandwidth",
52+
Namespace: "AWS/DirectoryService",
53+
Dimensions: []model.Dimension{
54+
{Name: "Metric Category", Value: "NTDS"},
55+
{Name: "Domain Controller IP", Value: "123.123.123.123"},
56+
{Name: "Directory ID", Value: "d-abc123"},
57+
},
58+
},
59+
},
60+
expectedSkip: false,
61+
expectedResource: directory,
62+
},
63+
}
64+
65+
for _, tc := range testcases {
66+
t.Run(tc.name, func(t *testing.T) {
67+
associator := NewAssociator(promslog.NewNopLogger(), tc.args.dimensionRegexps, tc.args.resources)
68+
res, skip := associator.AssociateMetricToResource(tc.args.metric)
69+
require.Equal(t, tc.expectedSkip, skip)
70+
require.Equal(t, tc.expectedResource, res)
71+
})
72+
}
73+
}

0 commit comments

Comments
 (0)