Skip to content

Commit

Permalink
Add dd service tag (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
eversC authored Jan 10, 2024
1 parent 302f2b4 commit c787db4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
23 changes: 13 additions & 10 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If running in AWS Lambda, store the config in SecretManager in a secret named
`ckr-config`.

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

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

```json

{
"EnableKeyAgeLogging": true,
"RotationMode": false,
"CloudProviders": [{
"Name":"aws"
}]
"CloudProviders": [
{
"Name": "aws"
}
]
}
```

For scraping of GCP key ages:

```json

{
"EnableKeyAgeLogging": true,
"RotationMode": false,
"CloudProviders": [{
"Project":"my-project",
"Name": "gcp"
}]
"CloudProviders": [
{
"Project": "my-project",
"Name": "gcp"
}
]
}
```

Expand All @@ -55,6 +57,7 @@ If you add a Datadog struct to the config, you can get `cloud-key-rotator` to po
"MetricEnv": "prod",
"MetricName": "cloud-key-rotator.age",
"MetricProject": "my_project",
"MetricService": "my_service",
"MetricTeam": "my_team"
},
"DatadogAPIKey": "okj23434poz3j4o324p455oz3j4o324",
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Datadog struct {
MetricTeam string
MetricName string
MetricProject string
MetricService string
}

// Filter type
Expand Down
7 changes: 7 additions & 0 deletions pkg/rotate/rotatekeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ func isDatadogKeySet(apiKey string) bool {
// postMetric posts details of each keys.Key to a metrics api
func postMetric(keys []keys.Key, apiKey string, datadog config.Datadog) (err error) {
url := strings.Join([]string{datadogURL, apiKey}, "")
ddServiceTag := "cloud-key-rotator"
if datadog.MetricService != "" {
ddServiceTag = datadog.MetricService
} else if datadog.MetricProject != "" {
ddServiceTag = datadog.MetricProject
}
for _, key := range keys {
var jsonString = []byte(
`{ "series" :[{"metric":"` + datadog.MetricName + `",` +
Expand All @@ -548,6 +554,7 @@ func postMetric(keys []keys.Key, apiKey string, datadog config.Datadog) (err err
`"tags":[` +
`"team:` + datadog.MetricTeam + `",` +
`"project:` + datadog.MetricProject + `",` +
`"service:` + ddServiceTag + `",` +
`"environment:` + datadog.MetricEnv + `",` +
`"key:` + key.Name + `",` +
`"provider:` + key.Provider.Provider + `",` +
Expand Down

0 comments on commit c787db4

Please sign in to comment.