Skip to content

Commit

Permalink
Fix mimirtool commands issued to API returning 404 (#2834) (#2835)
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Pracucci <marco@pracucci.com>

Signed-off-by: Marco Pracucci <marco@pracucci.com>
(cherry picked from commit 13bf78a)

Co-authored-by: Marco Pracucci <marco@pracucci.com>
  • Loading branch information
grafanabot and pracucci committed Aug 25, 2022
1 parent dcc238f commit 3292627
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion pkg/mimirtool/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const (
)

var (
ErrNoConfig = errors.New("No config exists for this user")
ErrResourceNotFound = errors.New("requested resource not found")
errConflict = errors.New("conflict with current state of target resource")
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/mimirtool/commands/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (a *AlertmanagerCommand) setup(k *kingpin.ParseContext) error {
func (a *AlertmanagerCommand) getConfig(k *kingpin.ParseContext) error {
cfg, templates, err := a.cli.GetAlertmanagerConfig(context.Background())
if err != nil {
if err == client.ErrResourceNotFound {
if errors.Is(err, client.ErrResourceNotFound) {
log.Infof("no Alertmanager config currently exists for this user")
return nil
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func (a *AlertmanagerCommand) loadConfig(k *kingpin.ParseContext) error {

func (a *AlertmanagerCommand) deleteConfig(k *kingpin.ParseContext) error {
err := a.cli.DeleteAlermanagerConfig(context.Background())
if err != nil && err != client.ErrResourceNotFound {
if err != nil && !errors.Is(err, client.ErrResourceNotFound) {
return err
}
return nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/mimirtool/commands/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (r *RuleCommand) listRules(k *kingpin.ParseContext) error {
func (r *RuleCommand) printRules(k *kingpin.ParseContext) error {
rules, err := r.cli.ListRules(context.Background(), "")
if err != nil {
if err == client.ErrResourceNotFound {
if errors.Is(err, client.ErrResourceNotFound) {
log.Infof("no rule groups currently exist for this user")
return nil
}
Expand All @@ -357,7 +357,7 @@ func (r *RuleCommand) printRules(k *kingpin.ParseContext) error {
func (r *RuleCommand) getRuleGroup(k *kingpin.ParseContext) error {
group, err := r.cli.GetRuleGroup(context.Background(), r.Namespace, r.RuleGroup)
if err != nil {
if err == client.ErrResourceNotFound {
if errors.Is(err, client.ErrResourceNotFound) {
log.Infof("this rule group does not currently exist")
return nil
}
Expand All @@ -370,7 +370,7 @@ func (r *RuleCommand) getRuleGroup(k *kingpin.ParseContext) error {

func (r *RuleCommand) deleteRuleGroup(k *kingpin.ParseContext) error {
err := r.cli.DeleteRuleGroup(context.Background(), r.Namespace, r.RuleGroup)
if err != nil && err != client.ErrResourceNotFound {
if err != nil && !errors.Is(err, client.ErrResourceNotFound) {
log.Fatalf("Unable to delete rule group from Grafana Mimir, %v", err)
}
return nil
Expand All @@ -387,7 +387,7 @@ func (r *RuleCommand) loadRules(k *kingpin.ParseContext) error {
for _, group := range ns.Groups {
fmt.Printf("group: '%v', ns: '%v'\n", group.Name, ns.Namespace)
curGroup, err := r.cli.GetRuleGroup(context.Background(), ns.Namespace, group.Name)
if err != nil && err != client.ErrResourceNotFound {
if err != nil && !errors.Is(err, client.ErrResourceNotFound) {
return errors.Wrap(err, "load operation unsuccessful, unable to contact Grafana Mimir API")
}
if curGroup != nil {
Expand Down Expand Up @@ -511,7 +511,7 @@ func (r *RuleCommand) syncRules(k *kingpin.ParseContext) error {
//TODO: Skipping the 404s here might end up in an unsual scenario.
// If we're unable to reach the Mimir API due to a bad URL, we'll assume no rules are
// part of the namespace and provide a diff of the whole ruleset.
if err != nil && err != client.ErrResourceNotFound {
if err != nil && !errors.Is(err, client.ErrResourceNotFound) {
return errors.Wrap(err, "sync operation unsuccessful, unable to contact the Grafana Mimir API")
}

Expand Down Expand Up @@ -606,7 +606,7 @@ func (r *RuleCommand) executeChanges(ctx context.Context, changes []rules.Namesp
"namespace": ch.Namespace,
}).Infof("deleting group")
err = r.cli.DeleteRuleGroup(ctx, ch.Namespace, g.Name)
if err != nil && err != client.ErrResourceNotFound {
if err != nil && !errors.Is(err, client.ErrResourceNotFound) {
return err
}
}
Expand Down

0 comments on commit 3292627

Please sign in to comment.