Skip to content

Commit

Permalink
chore: Added Datadog heartbeat metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
syedimranhassan committed Sep 4, 2024
1 parent 21066af commit 23b5090
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions dataeng/resources/opsgenie-enable-heartbeat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


OPSGENIE_HEARTBEAT_API_URL="https://api.opsgenie.com/v2/heartbeats"
PAGERDUTY_HEARTBEAT_API_URL=""

if [ -n "$OPSGENIE_HEARTBEAT_NAME" ] && \
[ -n "$OPSGENIE_HEARTBEAT_CONFIG_KEY" ] && \
Expand Down
16 changes: 16 additions & 0 deletions devops/jobs/CheckASGLifeCycleHooks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class CheckASGLifeCycleHooks {
credentialsBinding {
string('ROLE_ARN', "check-lifecycle-hooks-${deployment}-role-arn")
string("GENIE_KEY", "opsgenie_heartbeat_key")
string("DD_KEY", "datadog_heartbeat_key")
}
}

Expand Down Expand Up @@ -104,6 +105,21 @@ class CheckASGLifeCycleHooks {
if (opsgenie_heartbeat_name) {
shell('curl -X GET "https://api.opsgenie.com/v2/heartbeats/'+opsgenie_heartbeat_name+'/ping" -H "Authorization: GenieKey ${GENIE_KEY}"')
}
String datadog_heartbeat_name = configuration.get('DATADOG_HEARTBEAT_NAME', '')
if (datadog_heartbeat_name) {
String DD_JSON = """
{
"series": [{
"metric": "${datadog_heartbeat_name}",
"points": [['\$(date +%s)', 1]],
"type": "gauge",
"tags": ["env:${deployment}"]
}]
}
"""

shell('curl -X POST "https://api.datadoghq.com/api/v1/series?api_key=${DD_KEY}" -H "Content-Type: application/json" -d \'' + DD_JSON + '\'')
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions devops/jobs/CheckTableSize.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CheckTableSize {
def variable = "${deployment}-table-size-monitoring"
string("ROLE_ARN", variable)
string("GENIE_KEY", "opsgenie_heartbeat_key")
string("DD_KEY", "datadog_heartbeat_key")
}
}

Expand Down
13 changes: 13 additions & 0 deletions devops/jobs/CreateSandboxCI.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CreateSandboxCI {
wrappers {
credentialsBinding {
string("GENIE_KEY", "opsgenie_heartbeat_key")
string("DD_KEY", "datadog_heartbeat_key")
}
}

Expand Down Expand Up @@ -124,6 +125,18 @@ class CreateSandboxCI {
}
}
shell('curl -X GET "https://api.opsgenie.com/v2/heartbeats/SandboxCI'+type+'/ping" -H "Authorization: GenieKey ${GENIE_KEY}"')
def metricName = "SandboxCI${type}.heartbeat"
String DD_JSON = """
{
"series": [{
"metric": "${metricName}",
"points": [['\$(date +%s)', 1]],
"type": "gauge"
}]
}
"""

shell('curl -X POST "https://api.datadoghq.com/api/v1/series?api_key=${DD_KEY}" -H "Content-Type: application/json" -d \'' + DD_JSON + '\'')
}

triggers {
Expand Down
2 changes: 2 additions & 0 deletions devops/jobs/Janitor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Janitor {
credentialsBinding {
string('ROLE_ARN', "tools-jenkins-janitor-${deployment}-role-arn")
string("GENIE_KEY", "opsgenie_heartbeat_key")
string("DD_KEY", "datadog_heartbeat_key")
}
}

Expand Down Expand Up @@ -102,6 +103,7 @@ class Janitor {
env('AWS_CLEANER', configuration.get('aws_cleaner'))
env('DENY_LIST', configuration.get('deny_list'))
env('NOOP', extraVars.get('NOOP', false))
env('DEPLOYMENT', deployment)
}


Expand Down
15 changes: 15 additions & 0 deletions devops/jobs/JenkinsHeartbeat.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class JenkinsHeartbeat{
wrappers {
credentialsBinding {
string("GENIE_KEY", "opsgenie_heartbeat_key")
string("DD_KEY", "datadog_heartbeat_key")
}
}

Expand All @@ -30,6 +31,20 @@ class JenkinsHeartbeat{
if (opsgenie_heartbeat_name) {
shell('curl -X GET "https://api.opsgenie.com/v2/heartbeats/'+opsgenie_heartbeat_name+'/ping" -H "Authorization: GenieKey ${GENIE_KEY}"')
}
String datadog_heartbeat_name = extraVars.get('DATADOG_HEARTBEAT_NAME', '')
if (datadog_heartbeat_name) {
String DD_JSON = """
{
"series": [{
"metric": "${datadog_heartbeat_name}",
"points": [['\$(date +%s)', 1]],
"type": "gauge"
}]
}
"""

shell('curl -X POST "https://api.datadoghq.com/api/v1/series?api_key=${DD_KEY}" -H "Content-Type: application/json" -d \'' + DD_JSON + '\'')
}
}

}
Expand Down
2 changes: 2 additions & 0 deletions devops/jobs/ProspectusJanitor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ProspectusJanitor {
credentialsBinding {
string('ROLE_ARN', "tools-jenkins-janitor-${deployment}-role-arn")
string("GENIE_KEY", "opsgenie_heartbeat_key")
string("DD_KEY", "datadog_heartbeat_key")
}
}

Expand Down Expand Up @@ -100,6 +101,7 @@ class ProspectusJanitor {
env('AWS_REGION', configuration.get('aws_region', 'us-east-1'))
env('AWS_CLEANER', configuration.get('aws_cleaner'))
env('NOOP', extraVars.get('NOOP', false))
env('DEPLOYMENT', deployment)
}


Expand Down
15 changes: 15 additions & 0 deletions devops/jobs/SandboxTermination.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SandboxTermination{
string('ROLE_ARN', "launch-sandboxes-role-arn")
string('EDX_GIT_BOT_TOKEN', "edx_git_bot_token")
string("GENIE_KEY", "opsgenie_heartbeat_key")
string("DD_KEY", "datadog_heartbeat_key")
}
}

Expand Down Expand Up @@ -102,6 +103,20 @@ class SandboxTermination{
if (opsgenie_heartbeat_name) {
shell('curl -X GET "https://api.opsgenie.com/v2/heartbeats/'+opsgenie_heartbeat_name+'/ping" -H "Authorization: GenieKey ${GENIE_KEY}"')
}
String datadog_heartbeat_name = extraVars.get('DATADOG_HEARTBEAT_NAME', '')
if (datadog_heartbeat_name) {
String DD_JSON = """
{
"series": [{
"metric": "${datadog_heartbeat_name}",
"points": [['\$(date +%s)', 1]],
"type": "gauge"
}]
}
"""

shell('curl -X POST "https://api.datadoghq.com/api/v1/series?api_key=${DD_KEY}" -H "Content-Type: application/json" -d \'' + DD_JSON + '\'')
}
}

if (extraVars.get('NOTIFY_ON_FAILURE')){
Expand Down
10 changes: 10 additions & 0 deletions devops/resources/janitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,13 @@ else
fi

curl -X GET 'https://api.opsgenie.com/v2/heartbeats/'${JOB_NAME##*/}'/ping' -H 'Authorization: GenieKey '${GENIE_KEY}
curl -X POST "https://api.datadoghq.com/api/v1/series?api_key=${DD_KEY}" \
-H "Content-Type: application/json" \
-d '{
"series" : [{
"metric": '${JOB_NAME##*/}".heartbeat"',
"points": [['"$(date +%s)"', 1]],
"type": "gauge",
"tags": ["env:'${DEPLOYMENT}'"]
}]
}'
10 changes: 10 additions & 0 deletions devops/resources/table-size-monitoring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@ fi
python check_table_size.py --threshold ${THRESHOLD} ${RDSTHRESHOLD} ${RDSIGNORE}

curl -X GET 'https://api.opsgenie.com/v2/heartbeats/table-size-monitoring-'${DEPLOYMENT}'/ping' -H 'Authorization: GenieKey '${GENIE_KEY}
curl -X POST "https://api.datadoghq.com/api/v1/series?api_key=${DD_KEY}" \
-H "Content-Type: application/json" \
-d '{
"series" : [{
"metric": "table-size-monitoring-'${DEPLOYMENT}'.heartbeat",
"points": [['"$(date +%s)"', 1]],
"type": "gauge",
"tags": ["env:'${DEPLOYMENT}'"]
}]
}'

0 comments on commit 23b5090

Please sign in to comment.