Skip to content

Commit

Permalink
Add missing arg run-id & improve error messages (#87)
Browse files Browse the repository at this point in the history
* Add missing arg run-id & improve error messages

* v0.12.2
  • Loading branch information
baksetercx authored Oct 23, 2024
1 parent 7e3a9c0 commit 4be5146
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.1
0.12.2
6 changes: 5 additions & 1 deletion pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ var Command *cli.Command = &cli.Command{
Name: "grafana-api-key",
Usage: "The Grafana API key to use for deployment annotations.",
},
&cli.StringFlag{
Name: "run-id",
Usage: "The GitHub Actions run ID to use for deployment annotations.",
},
},
Action: Deploy,
}
Expand Down Expand Up @@ -329,7 +333,7 @@ func Deploy(c *cli.Context) error {
RunID: runID,
},
); err != nil {
return cli.Exit(err, 1)
return cli.Exit(fmt.Errorf("Failed to post Grafana annotation: %w", err), 1)
}
}

Expand Down
12 changes: 10 additions & 2 deletions pkg/deploy/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ func addGrafanaDeploymentAnnotation(
}

// TODO: actually find out why Grafana is returning 429 instead of just retrying
const RETRY_ATTEMPTS = 5
const RETRY_DELAY = 5 * time.Second

_, _, err = lo.AttemptWithDelay(
5,
5*time.Second,
RETRY_ATTEMPTS,
RETRY_DELAY,
func(i int, duration time.Duration) error {
log.Printf("Sending deploy annotation to Grafana, attempt %d\n", i)

statusCode, err := sendRequest(
grafanaURL+"annotations/graphite",
grafanaSecret,
Expand All @@ -138,9 +143,12 @@ func addGrafanaDeploymentAnnotation(
},
)
if err != nil {
log.Printf("Failed to send deploy annotation to Grafana after %d attempts\n", RETRY_ATTEMPTS)
return err
}

log.Println("Deploy annotation sent to Grafana!")

return nil
}

Expand Down

0 comments on commit 4be5146

Please sign in to comment.