Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potential fix for repos with executors from orbs + better debug logs in DD #307

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions circleci/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ func getDockerUpdates(node *yaml.Node) map[string]*yaml.Node {

for i, nextHole := range node.Content {
if nextHole.Value == "executors" || nextHole.Value == "jobs" {

// check if there is a docker image
if i+1 >= len(node.Content) {
return updates
}

dockers := node.Content[i+1]
updates := extractImages(dockers.Content)
for k, v := range updates {
Expand Down
19 changes: 11 additions & 8 deletions datadog/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func IncrementCount(metricName string, value int64, tags []string) {
metric := metricPrefix + "." + metricName
err := postDataDogMetric(metric, value, "count", tags)
if err != nil {
log.Debug().Err(err).Msgf("could not increment datadog counter %s", metricName)
log.Debug().Err(err).Msgf("Could not increment datadog, metric: %s, value: %d, tags: %s", metricName, value, tags)
}
}

Expand All @@ -41,7 +41,7 @@ func Gauge(metricName string, value float64, tags []string) {
metric := metricPrefix + "." + metricName
err := postDataDogMetric(metric, int64(value), "gauge", tags)
if err != nil {
log.Debug().Err(err).Msgf("could not send gauge to datadog %s", metricName)
log.Debug().Err(err).Msgf("could not send gauge to datadog, metric: %s, value: %d, tags: %s", metricName, int64(value), tags)
}
}

Expand All @@ -50,7 +50,7 @@ func Distribution(metricName string, value float64, tags []string) {
metric := metricPrefix + "." + metricName
err := postDataDogMetric(metric, int64(value), "distribution", tags)
if err != nil {
log.Debug().Err(err).Msgf("could not send distribution to datadog %s", metricName)
log.Debug().Err(err).Msgf("could not send distribution to datadog, metric: %s, value: %d, tags: %s", metricName, int64(value), tags)
}

}
Expand All @@ -75,7 +75,6 @@ func postDataDogMetric(metric string, value int64, metricType string, tags []str

_, err := postStructAsJSON(url, payload, nil)
if err != nil {
log.Debug().Err(err).Msg("could send metric to datadog")
return err
}

Expand Down Expand Up @@ -108,10 +107,14 @@ func postStructAsJSON(url string, payload interface{}, target interface{}) (stri
if r.StatusCode < 200 || r.StatusCode > 299 {
return "", fmt.Errorf("request failed, expected status: 2xx got: %d, error message: %s", r.StatusCode, bodyString)
}
decode := json.NewDecoder(r.Body)
err = decode.Decode(&target)
if err != nil {
return "", err

// only decode if target is not nil
if target != nil {
decode := json.NewDecoder(r.Body)
err = decode.Decode(&target)
if err != nil {
return "", err
}
}

return bodyString, nil
Expand Down
Loading