Skip to content

Commit

Permalink
🎨 Activity cli cleanup (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
Munklinde96 authored Oct 22, 2024
1 parent c25fe0e commit 2b683c1
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 10 deletions.
120 changes: 116 additions & 4 deletions cmd/rig/cmd/activity/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (

"connectrpc.com/connect"
"github.com/jedib0t/go-pretty/v6/table"

"github.com/rigdev/rig-go-api/api/v1/activity"
rollout_api "github.com/rigdev/rig-go-api/api/v1/capsule/rollout"
"github.com/rigdev/rig-go-api/model"
"github.com/rigdev/rig-go-sdk"
"github.com/rigdev/rig/cmd/common"
Expand All @@ -25,6 +27,11 @@ var (
toStr string
since string

projectFilter string
environmentFilter string
capsuleFilter string
userFilter string

limit int
offset int
)
Expand Down Expand Up @@ -81,6 +88,28 @@ func Setup(parent *cobra.Command, s *cli.SetupContext) {
"Offset the activities returned. Default is 0.",
)

activity.Flags().StringVar(
&projectFilter, "project-filter", "",
"Filter activities by project ID",
)

activity.Flags().StringVar(
&environmentFilter, "environment-filter", "",
"Filter activities by environment ID",
)

activity.Flags().StringVar(
&capsuleFilter, "capsule-filter", "",
"Filter activities by capsule ID",
)

activity.Flags().StringVar(
&userFilter, "user-filter", "",
"Filter activities by user ID",
)

// activity.Flags().StringVar()

parent.AddCommand(activity)
}

Expand All @@ -94,9 +123,14 @@ func (c *Cmd) list(ctx context.Context, _ *cobra.Command, _ []string) error {
From: timestamppb.New(from),
To: timestamppb.New(to),
Pagination: &model.Pagination{
Limit: uint32(limit),
Offset: uint32(offset),
Descending: true,
Limit: uint32(limit),
Offset: uint32(offset),
},
Filter: &activity.ActivityFilter{
ProjectFilter: projectFilter,
EnvironmentFilter: environmentFilter,
CapsuleFilter: capsuleFilter,
UserIdentifierFilter: userFilter,
},
}))
if err != nil {
Expand All @@ -120,8 +154,10 @@ func (c *Cmd) list(ctx context.Context, _ *cobra.Command, _ []string) error {
})

for _, a := range activities {
topic, msg := activityMessageToString(a.GetMessage())

t.AppendRow(table.Row{
common.TopicToString(a.GetTopic()), a.GetMessage(), activityScopeToString(a.GetScope()),
topic, msg, activityScopeToString(a.GetScope()),
a.GetTimestamp().AsTime().Local().Format("2006-01-02 15:04:05"),
})
}
Expand All @@ -131,6 +167,82 @@ func (c *Cmd) list(ctx context.Context, _ *cobra.Command, _ []string) error {
return nil
}

func activityMessageToString(m *activity.Message) (string, string) {
if m == nil {
return "", ""
}

switch v := m.Message.(type) {
case *activity.Message_Rollout_:
msg := fmt.Sprintf("Rollout #%d", v.Rollout.GetRolloutId())
switch v.Rollout.GetState() {
case rollout_api.StepState_STEP_STATE_ONGOING:
msg += " initiated"
case rollout_api.StepState_STEP_STATE_DONE:
msg += " deployed"
case rollout_api.StepState_STEP_STATE_FAILED:
msg += " failed"
}

return "Rollout", msg
case *activity.Message_Issue_:
var level string
switch v.Issue.GetLevel() {
case model.Level_LEVEL_INFORMATIVE:
level = "informatic"
case model.Level_LEVEL_MINOR:
level = "minor"
case model.Level_LEVEL_MAJOR:
level = "major"
case model.Level_LEVEL_CRITICAL:
level = "critical"
}

action := "reported"
if v.Issue.GetResolved() {
action = "resolved"
}

return "Issue", fmt.Sprintf("%s issue %s in rollout #%d: %s",
level, action, v.Issue.GetRolloutID(), v.Issue.GetMessage())

case *activity.Message_Project_:
action := "created"
if v.Project.GetDeleted() {
action = "deleted"
}

return "Project", fmt.Sprintf("Project '%s' %s", v.Project.GetProjectId(), action)

case *activity.Message_Environment_:
action := "created"
if v.Environment.GetDeleted() {
action = "deleted"
}

return "Environment", fmt.Sprintf("Environment '%s' %s", v.Environment.GetEnvironmentId(), action)

case *activity.Message_Capsule_:
action := "created"
if v.Capsule.GetDeleted() {
action = "deleted"
}

return "Capsule", fmt.Sprintf("Capsule '%s' %s", v.Capsule.GetCapsuleId(), action)

case *activity.Message_User_:
action := "created"
if v.User.GetDeleted() {
action = "deleted"
}

return "User", fmt.Sprintf("User '%s' %s", v.User.GetPrintableName(), action)

default:
return "", ""
}
}

func activityScopeToString(s *activity.Scope) string {
if s == nil {
return "All"
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/api/platform-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ Different states a step can be in.
| level | [model.Level](#model-Level) | | |
| rolloutID | [uint64](#uint64) | | |
| message | [string](#string) | | |
| resolved | [bool](#bool) | | |



Expand Down Expand Up @@ -1154,6 +1155,7 @@ Scrypt hashing instance.
| from | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| to | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| pagination | [model.Pagination](#model-Pagination) | | |
| filter | [ActivityFilter](#api-v1-activity-ActivityFilter) | | |



Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require (
github.com/nyaruka/phonenumbers v1.1.7
github.com/pkg/errors v0.9.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.70.0
github.com/rigdev/rig-go-api v0.0.0-20241021160034-62cd93877247
github.com/rigdev/rig-go-api v0.0.0-20241022115326-03c0e30d80cc
github.com/rigdev/rig-go-sdk v0.0.0-20241021090503-b515c1ca035f
github.com/rivo/tview v0.0.0-20240524063012-037df494fb76
github.com/robfig/cron v1.2.0
Expand Down Expand Up @@ -182,7 +182,7 @@ require (
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.25.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gotest.tools/v3 v3.5.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJ
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rigdev/rig-go-api v0.0.0-20241021160034-62cd93877247 h1:oPBaX5xZ6+Us9z9fru1YC2qzYeOttmJQE0NEcimK8h4=
github.com/rigdev/rig-go-api v0.0.0-20241021160034-62cd93877247/go.mod h1:6xxlwvADYBFRiIrot3yrcXVJT2IMGfkTZ5LIRomNlXY=
github.com/rigdev/rig-go-api v0.0.0-20241022115326-03c0e30d80cc h1:lWyePpmFgQT8UxAZtU17KaSPjLgbdi/J8MEntTLsgwQ=
github.com/rigdev/rig-go-api v0.0.0-20241022115326-03c0e30d80cc/go.mod h1:0yAwJnPID3gHfB3ETQAFYGM1tkNWkJKbVzauZiHmHKw=
github.com/rigdev/rig-go-sdk v0.0.0-20241021090503-b515c1ca035f h1:SScDJVwFt/QzURstwUdi/ejnRoqB1ZsBLlICPD6Lt0c=
github.com/rigdev/rig-go-sdk v0.0.0-20241021090503-b515c1ca035f/go.mod h1:DJAwoPmFI6Jo71n/2VfFk/Nyzlyd24ARWCLC4Hsm1gg=
github.com/rivo/tview v0.0.0-20240524063012-037df494fb76 h1:iqvDlgyjmqleATtFbA7c14djmPh2n4mCYUv7JlD/ruA=
Expand Down Expand Up @@ -516,8 +516,8 @@ gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuB
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8=
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 h1:zciRKQ4kBpFgpfC5QQCVtnnNAcLIqweL7plyZRQHVpI=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
Expand Down

0 comments on commit 2b683c1

Please sign in to comment.