Skip to content

Commit 79649bd

Browse files
committed
fix: add support for setting timeout through env variable
- bump image tag to 0.2.0 - add sample sli and slo - use podtatohead for test events
1 parent f73609e commit 79649bd

File tree

8 files changed

+65
-17
lines changed

8 files changed

+65
-17
lines changed

eventhandlers.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,23 @@ import (
1616
"github.com/vadasambar/datadog-service/pkg/utils"
1717
)
1818

19-
const sliFile = "datadog/sli.yaml"
20-
const apiSleep = 30
19+
const (
20+
sliFile = "datadog/sli.yaml"
21+
defaultSleepBeforeAPIInSeconds = 30
22+
)
23+
24+
// We have to put a min of 30s of sleep for the datadog API to reflect the data correctly
25+
// More info: https://github.com/keptn-sandbox/datadog-service/issues/8
26+
var sleepBeforeAPIInSeconds int
27+
28+
func init() {
29+
var err error
30+
sleepBeforeAPIInSeconds, err = strconv.Atoi(strings.TrimSpace(os.Getenv("SLEEP_BEFORE_API_IN_SECONDS")))
31+
if err != nil || sleepBeforeAPIInSeconds < defaultSleepBeforeAPIInSeconds {
32+
logger.Infof("defaulting SLEEP_BEFORE_API_IN_SECONDS to 30s because it was set to '%v' which is less than the min allowed value of 30s", sleepBeforeAPIInSeconds)
33+
sleepBeforeAPIInSeconds = defaultSleepBeforeAPIInSeconds
34+
}
35+
}
2136

2237
// HandleGetSliTriggeredEvent handles get-sli.triggered events if SLIProvider == datadog
2338
func HandleGetSliTriggeredEvent(myKeptn *keptnv2.Keptn, incomingEvent cloudevents.Event, data *keptnv2.GetSLITriggeredEventData) error {
@@ -29,7 +44,7 @@ func HandleGetSliTriggeredEvent(myKeptn *keptnv2.Keptn, incomingEvent cloudevent
2944

3045
// Step 1 - Do we need to do something?
3146
// Lets make sure we are only processing an event that really belongs to our SLI Provider
32-
if data.GetSLI.SLIProvider != "datadog-service" {
47+
if data.GetSLI.SLIProvider != "datadog" {
3348
logger.Infof("Not handling get-sli event as it is meant for %s", data.GetSLI.SLIProvider)
3449
return nil
3550
}
@@ -108,8 +123,8 @@ func HandleGetSliTriggeredEvent(myKeptn *keptnv2.Keptn, incomingEvent cloudevent
108123
// Pulling the data from Datadog api immediately gives incorrect data in api response
109124
// we have to wait for some time for the correct data to be reflected in the api response
110125
// TODO: Find a better way around the sleep time for datadog api
111-
logger.Debugf("waiting for %vs so that the metrics data is reflected correctly in the api", apiSleep)
112-
time.Sleep(time.Second * apiSleep)
126+
logger.Debugf("waiting for %vs so that the metrics data is reflected correctly in the api", sleepBeforeAPIInSeconds)
127+
time.Sleep(time.Second * time.Duration(sleepBeforeAPIInSeconds))
113128

114129
query := replaceQueryParameters(data, sliConfig[indicatorName], start, end)
115130
logger.Debugf("actual query sent to datadog: %v, from: %v, to: %v", query, start.Unix(), end.Unix())

helm/templates/secret.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ metadata:
99
type: Opaque
1010
data:
1111
DD_API_KEY: {{ required "A valid DD_API_KEY is required to connect to the Datadog API" .Values.datadogservice.ddApikey | b64enc | quote }}
12-
DD_APP_KEY: {{ required "A valid DD_API_KEY is required to connect to the Datadog API" .Values.datadogservice.ddAppKey | b64enc | quote }}
13-
DD_SITE: {{ required "A valid DD_API_KEY is required to connect to the Datadog API" .Values.datadogservice.ddSite | b64enc | quote }}
12+
DD_APP_KEY: {{ required "A valid DD_APP_KEY is required to connect to the Datadog API" .Values.datadogservice.ddAppKey | b64enc | quote }}
13+
DD_SITE: {{ required "A valid DD_SITE is required to connect to the Datadog API" .Values.datadogservice.ddSite | b64enc | quote }}
1414

1515
{{- end -}}

helm/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ datadogservice:
1414
image:
1515
repository: ghcr.io/keptn-sandbox/datadog-service # Container Image Name
1616
pullPolicy: IfNotPresent # Kubernetes Image Pull Policy
17-
tag: 0.1.0 # Container Tag
17+
tag: 0.2.0 # Container Tag
1818
service:
1919
enabled: true # Creates a Kubernetes Service for the datadog-service
2020

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import (
1616

1717
var keptnOptions = keptn.KeptnOpts{}
1818

19-
const envVarLogLevel = "LOG_LEVEL"
19+
const (
20+
envVarLogLevel = "LOG_LEVEL"
21+
)
2022

2123
type envConfig struct {
2224
// Port on which to listen for cloudevents

resources/sli.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
spec_version: '1.0'
3+
indicators:
4+
# http_response_time_seconds_main_page_sum: sum(rate(http_server_request_duration_seconds_sum{method="GET",route="/",status_code="200",job="$SERVICE-$PROJECT-$STAGE"}[$DURATION_SECONDS])/rate(http_server_request_duration_seconds_count{method="GET",route="/",status_code="200",job="$SERVICE-$PROJECT-$STAGE"}[$DURATION_SECONDS]))
5+
# failing_request: promhttp_metric_handler_requests_total{code!="200",job="$SERVICE-$PROJECT-$STAGE"}
6+
# http_requests_total_sucess: http_requests_total{status="success"}
7+
# go_routines: go_goroutines{job="$SERVICE-$PROJECT-$STAGE"}
8+
# request_throughput: sum(rate(http_requests_total{status="success"}[2m]))
9+
system_load: avg:system.load.1{*}.rollup(avg, $DURATION)

resources/slo.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
spec_version: '0.1.0'
3+
comparison:
4+
compare_with: "single_result"
5+
include_result_with_score: "pass"
6+
aggregate_function: avg
7+
objectives:
8+
- sli: system_load
9+
displayName: "System Load"
10+
pass:
11+
- criteria:
12+
- "<0.6"
13+
warning:
14+
- criteria:
15+
- ">=0.6"
16+
- "<0.7"
17+
fail:
18+
- criteria:
19+
- ">0.7"
20+
21+
total_score:
22+
pass: "100%"
23+
warning: "50%"

test-events/evaluation.triggered.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
},
1010
"labels": null,
1111
"message": "",
12-
"project": "sockshop",
12+
"project": "podtatohead",
1313
"result": "",
14-
"service": "carts",
15-
"stage": "staging",
14+
"service": "helloservice",
15+
"stage": "hardening",
1616
"status": "",
1717
"test": {
1818
"end": "",

test-events/get-sli.triggered.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
"customFilters": [],
55
"end": "2021-01-15T15:09:45.000Z",
66
"indicators": [
7-
"response_time_p95",
8-
"some_other_metric"
7+
"system_load"
98
],
109
"sliProvider": "datadog-service",
1110
"start": "2021-01-15T15:04:45.000Z"
1211
},
1312
"labels": null,
1413
"message": "",
15-
"project": "sockshop",
14+
"project": "podtatohead",
1615
"result": "",
17-
"service": "carts",
18-
"stage": "staging",
16+
"service": "helloservice",
17+
"stage": "hardening",
1918
"status": ""
2019
},
2120
"id": "409539ae-c0b9-436e-abc6-c257292e28ff",

0 commit comments

Comments
 (0)