-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PC-13613 PC-13391 remove replay from queue (#225)
**Merge after the feature is released.** ## Motivation Ability to control the upcoming feature through sloctl. ## Summary - Upgraded to go 1.23 - Updated linter rules - Added sloctl replay delete --all and sloctl replay delete sloName -p projectName ## Testing - Run replay (normal, without queue) - Get agents (change in get agents command) - Add replays to queue, then try deleting them using sloctl (both all and for specific SLO) Release notes intentionally left empty, to be filled in when the feature is released. ## Release Notes
- Loading branch information
1 parent
12e0630
commit 86aa897
Showing
6 changed files
with
136 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/nobl9/sloctl | ||
|
||
go 1.22 | ||
go 1.23 | ||
|
||
require ( | ||
github.com/go-playground/validator/v10 v10.22.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/mitchellh/colorstring" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// AddDeleteCommand returns cobra command delete, which allows to delete a queued Replay. | ||
func (r *ReplayCmd) AddDeleteCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete <slo-name>", | ||
Short: "Delete a queued Replay", | ||
Args: r.deleteArguments, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if r.project != "" { | ||
r.client.Config.Project = r.project | ||
} | ||
if r.deleteAll { | ||
return r.deleteAllReplays(cmd) | ||
} else { | ||
return r.deleteReplaysForSLO(cmd, r.sloName) | ||
} | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&r.project, "project", "p", "", | ||
`Specifies the Project of the SLO you want to remove queued Replays for.`) | ||
cmd.Flags().BoolVar(&r.deleteAll, "all", false, "Delete ALL queued Replays.") | ||
|
||
return cmd | ||
} | ||
|
||
func (r *ReplayCmd) deleteArguments(cmd *cobra.Command, args []string) error { | ||
if !r.deleteAll && len(args) == 0 { | ||
_ = cmd.Usage() | ||
return errReplayDeleteInvalidOptions | ||
} | ||
if len(args) > 1 { | ||
return errReplayTooManyArgs | ||
} | ||
if len(args) == 1 { | ||
r.sloName = args[0] | ||
} | ||
return nil | ||
} | ||
|
||
type deleteReplayRequest struct { | ||
Project string `json:"project,omitempty"` | ||
Slo string `json:"slo,omitempty"` | ||
All bool `json:"all,omitempty"` | ||
} | ||
|
||
func (r *ReplayCmd) deleteAllReplays(cmd *cobra.Command) error { | ||
cmd.Println(colorstring.Color("[yellow]Deleting all queued Replays[reset]")) | ||
|
||
_, err := r.doRequest( | ||
cmd.Context(), | ||
http.MethodDelete, | ||
endpointReplayDelete, | ||
"", | ||
nil, | ||
deleteReplayRequest{ | ||
All: true, | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
cmd.Println(colorstring.Color("[green]All queued Replays deleted successfully[reset]")) | ||
|
||
return nil | ||
} | ||
|
||
func (r *ReplayCmd) deleteReplaysForSLO(cmd *cobra.Command, sloName string) error { | ||
cmd.Println( | ||
colorstring.Printf( | ||
"[yellow]Deleting queued Replays for SLO '%s' in project '%s'[reset]", | ||
sloName, | ||
r.client.Config.Project, | ||
)) | ||
|
||
_, err := r.doRequest( | ||
cmd.Context(), | ||
http.MethodDelete, | ||
endpointReplayDelete, | ||
r.client.Config.Project, | ||
nil, | ||
deleteReplayRequest{ | ||
Project: r.client.Config.Project, | ||
Slo: sloName, | ||
}, | ||
) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
cmd.Println( | ||
colorstring.Color( | ||
fmt.Sprintf("[green]Queued Replays for SLO '%s' in project '%s' deleted successfully[reset]", | ||
sloName, | ||
r.client.Config.Project, | ||
), | ||
), | ||
) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package internal | ||
|
||
import "github.com/pkg/errors" | ||
|
||
var ( | ||
errReplayInvalidOptions = errors.New("you must either run 'sloctl replay' for a single SLO," + | ||
" providing its name as an argument, or provide configuration file using '-f' flag, but not both") | ||
errReplayDeleteInvalidOptions = errors.New("you must either run 'sloctl replay delete' for a single " + | ||
"SLO, providing its name as an argument, or use the '--all' flag to delete all queued replays, but not both") | ||
errReplayTooManyArgs = errors.New("'replay' command accepts a single SLO name," + | ||
" If you want to run it for multiple SLOs provide a configuration file instead using '-f' flag") | ||
errReplayMissingFromArg = errors.Errorf("when running 'sloctl replay' for a single SLO,"+ | ||
" you must provide Replay window start time (%s layout) with '--from' flag", timeLayoutString) | ||
errProjectWildcardIsNotAllowed = errors.New( | ||
"wildcard Project is not allowed, you must provide specific Project name(s)") | ||
) |