@@ -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
2338func 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 ())
0 commit comments