Skip to content

Commit c787db4

Browse files
authored
Add dd service tag (#920)
1 parent 302f2b4 commit c787db4

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

examples/README.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ If running in AWS Lambda, store the config in SecretManager in a secret named
1111
`ckr-config`.
1212

1313
If running in GCP CloudFunctions, store the config in GCS, e.g. in
14-
`your_bucket/ckr-config.json`, then set an env var
14+
`your_bucket/ckr-config.json`, then set an env var
1515
`CKR_BUCKET_NAME=your_bucket`.
1616

1717
Otherwise, when running the binary or code directly, pop the config into
@@ -22,27 +22,29 @@ a file called `config.json` in `/etc/cloud-key-rotator/`.
2222
For scraping of AWS key ages:
2323

2424
```json
25-
2625
{
2726
"EnableKeyAgeLogging": true,
2827
"RotationMode": false,
29-
"CloudProviders": [{
30-
"Name":"aws"
31-
}]
28+
"CloudProviders": [
29+
{
30+
"Name": "aws"
31+
}
32+
]
3233
}
3334
```
3435

3536
For scraping of GCP key ages:
3637

3738
```json
38-
3939
{
4040
"EnableKeyAgeLogging": true,
4141
"RotationMode": false,
42-
"CloudProviders": [{
43-
"Project":"my-project",
44-
"Name": "gcp"
45-
}]
42+
"CloudProviders": [
43+
{
44+
"Project": "my-project",
45+
"Name": "gcp"
46+
}
47+
]
4648
}
4749
```
4850

@@ -55,6 +57,7 @@ If you add a Datadog struct to the config, you can get `cloud-key-rotator` to po
5557
"MetricEnv": "prod",
5658
"MetricName": "cloud-key-rotator.age",
5759
"MetricProject": "my_project",
60+
"MetricService": "my_service",
5861
"MetricTeam": "my_team"
5962
},
6063
"DatadogAPIKey": "okj23434poz3j4o324p455oz3j4o324",

pkg/config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Datadog struct {
5858
MetricTeam string
5959
MetricName string
6060
MetricProject string
61+
MetricService string
6162
}
6263

6364
// Filter type

pkg/rotate/rotatekeys.go

+7
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ func isDatadogKeySet(apiKey string) bool {
537537
// postMetric posts details of each keys.Key to a metrics api
538538
func postMetric(keys []keys.Key, apiKey string, datadog config.Datadog) (err error) {
539539
url := strings.Join([]string{datadogURL, apiKey}, "")
540+
ddServiceTag := "cloud-key-rotator"
541+
if datadog.MetricService != "" {
542+
ddServiceTag = datadog.MetricService
543+
} else if datadog.MetricProject != "" {
544+
ddServiceTag = datadog.MetricProject
545+
}
540546
for _, key := range keys {
541547
var jsonString = []byte(
542548
`{ "series" :[{"metric":"` + datadog.MetricName + `",` +
@@ -548,6 +554,7 @@ func postMetric(keys []keys.Key, apiKey string, datadog config.Datadog) (err err
548554
`"tags":[` +
549555
`"team:` + datadog.MetricTeam + `",` +
550556
`"project:` + datadog.MetricProject + `",` +
557+
`"service:` + ddServiceTag + `",` +
551558
`"environment:` + datadog.MetricEnv + `",` +
552559
`"key:` + key.Name + `",` +
553560
`"provider:` + key.Provider.Provider + `",` +

0 commit comments

Comments
 (0)