Skip to content

Commit

Permalink
display specific error messages when cloud-config fails (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfratto authored Jun 4, 2021
1 parent c91b61d commit 62a36fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- [FEATURE] (beta) A Grafana Agent Operator is now available. (@rfratto)

- [ENHANCEMENT] Error messages when installing the Grafana Agent for Grafana
Cloud will now be shown. (@rfratto)

# v0.15.0 (2021-06-03)

BREAKING CHANGE: Configuration of Tempo Autologging changed in this release.
Expand Down
9 changes: 5 additions & 4 deletions pkg/client/grafanacloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ func (c *Client) AgentConfig(ctx context.Context, stackID string) (string, error
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
return "", fmt.Errorf("unexpected status code %d", resp.StatusCode)
}

// Even though the API returns json, we'll parse it as YAML here so we can
// re-encode it with the same order it was decoded in.
payload := struct {
Expand All @@ -62,7 +58,12 @@ func (c *Client) AgentConfig(ctx context.Context, stackID string) (string, error
}{}

dec := yaml.NewDecoder(resp.Body)
dec.SetStrict(true)
if err := dec.Decode(&payload); err != nil {
if resp.StatusCode != 200 {
return "", fmt.Errorf("unexpected status code %d", resp.StatusCode)
}

return "", fmt.Errorf("failed to read response: %w", err)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/client/grafanacloud/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestClient_AgentConfig_Error(t *testing.T) {

func TestClient_AgentConfig_ErrorMessage(t *testing.T) {
httpClient := testClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
_, err := w.Write([]byte(`{
"status": "error",
"error": "Something went wrong"
Expand Down

0 comments on commit 62a36fe

Please sign in to comment.