Skip to content

Commit ed1f454

Browse files
authored
Merge pull request #28 from grafana/20200310_fix_delete_handling
fix delete handling
2 parents 48203fd + 28e10d8 commit ed1f454

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## v0.1.4 / 2020-03-10
66

7+
* [CHANGE] Ensure 404 deletes do not trigger an error for `rules` and `alertmanager` commands #28
78
* [ENHANCEMENT] Add separate `chunktool` for operating on cortex chunk backends #23 #26
89
* [ENHANCEMENT] Add `--disable-color` flag to `rules print`, `rules diff`, and `alertmanager get` command #25
910
* [BUGFIX] `alertmanager load` command will ensure provided template files are also loaded #25

pkg/client/alerts.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io/ioutil"
7+
"net/http"
78

89
"github.com/pkg/errors"
910
log "github.com/sirupsen/logrus"
@@ -57,11 +58,15 @@ func (r *CortexClient) DeleteAlermanagerConfig(ctx context.Context) error {
5758
return err
5859
}
5960

60-
if res.StatusCode%2 > 0 {
61-
return fmt.Errorf("error occured, %v", string(body))
61+
switch res.StatusCode {
62+
case http.StatusAccepted, http.StatusOK:
63+
return nil
64+
case http.StatusNotFound:
65+
log.Debugln("alertmanager config not found, already deleted")
66+
return nil
6267
}
6368

64-
return nil
69+
return fmt.Errorf("error occured, %v", string(body))
6570
}
6671

6772
// GetAlertmanagerConfig retrieves a rule group

pkg/client/rules.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io/ioutil"
7+
"net/http"
78
"net/url"
89

910
"github.com/pkg/errors"
@@ -47,11 +48,15 @@ func (r *CortexClient) DeleteRuleGroup(ctx context.Context, namespace, groupName
4748
return err
4849
}
4950

50-
if res.StatusCode%2 > 0 {
51-
return fmt.Errorf("error occured, %v", string(body))
51+
switch res.StatusCode {
52+
case http.StatusAccepted, http.StatusOK:
53+
return nil
54+
case http.StatusNotFound:
55+
log.Debugln("alertmanager config not found, already deleted")
56+
return nil
5257
}
5358

54-
return nil
59+
return fmt.Errorf("error occured, %v", string(body))
5560
}
5661

5762
// GetRuleGroup retrieves a rule group

0 commit comments

Comments
 (0)