Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: List the queued replays [PC-13341] #232

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (r *RootCmd) NewReplayCmd() *cobra.Command {
cmd.Flags().Var(&replay.from, "from", "Sets the start of Replay time window.")

cmd.AddCommand(replay.AddDeleteCommand())
cmd.AddCommand(replay.AddListCommand())

return cmd
}
Expand Down Expand Up @@ -425,6 +426,7 @@ func (r *ReplayCmd) getReplayStatus(
const (
endpointReplayPost = "/timetravel"
endpointReplayDelete = "/timetravel"
endpointReplayList = "/timetravel/list"
endpointReplayGetStatus = "/timetravel/%s"
endpointReplayGetAvailability = "/internal/timemachine/availability"
endpointGetSLO = "/get/slo"
Expand Down
64 changes: 64 additions & 0 deletions internal/replay_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package internal

import (
"encoding/json"
"fmt"
"net/http"
"os"

"github.com/mitchellh/colorstring"
"github.com/spf13/cobra"

"github.com/nobl9/sloctl/internal/printer"
)

// AddListCommand returns cobra command list, which allows to list all queued Replays.
func (r *ReplayCmd) AddListCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List queued Replays",
dawidwisn marked this conversation as resolved.
Show resolved Hide resolved
RunE: func(cmd *cobra.Command, args []string) error {
return r.listAllReplays(cmd)
},
}
return cmd
}

type ReplayQueueItem struct {
Slo string `json:"slo,omitempty"`
Project string `json:"project"`
ElapsedTime string `json:"elapsedTime,omitempty"`
RetrievedScope string `json:"retrievedScope,omitempty"`
RetrievedFrom string `json:"retrievedFrom,omitempty"`
Status string `json:"status"`
}

func (r *ReplayCmd) listAllReplays(cmd *cobra.Command) error {
cmd.Println(colorstring.Color("[yellow]Listing all queued Replays[reset]"))

response, err := r.doRequest(
cmd.Context(),
http.MethodGet,
endpointReplayList,
"",
nil,
nil,
)
if err != nil {
return err
}

var replayQueueList []ReplayQueueItem
if err := json.Unmarshal(response, &replayQueueList); err != nil {
fmt.Printf("err: %v\n", err)
}

p, err := printer.New(os.Stdout, "yaml", "", "")
if err != nil {
return err
}
if err = p.Print(replayQueueList); err != nil {
return err
}
return nil
}
Loading