Skip to content

Remove status command, fold into get and logs #171

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

Merged
merged 2 commits into from
Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ assignees: ''

### Stack Trace

[If applicable, the stack trace which shows the error. Find it with `cortex logs <resource name>`, or use `kubectl get pods -n cortex` and use the name of the failed pod in `kubectl logs <pod name> -n cortex`]
[If applicable, the stack trace which shows the error. Find it with `cortex logs -v <resource name>`, or use `kubectl get pods -n cortex` and use the name of the failed pod in `kubectl logs <pod name> -n cortex`]

```
<paste stack trace here>
Expand Down
126 changes: 126 additions & 0 deletions cli/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func init() {
addAppNameFlag(getCmd)
addEnvFlag(getCmd)
addWatchFlag(getCmd)
addSummaryFlag(getCmd)
addResourceTypesToHelp(getCmd)
}

Expand All @@ -64,6 +65,9 @@ func runGet(cmd *cobra.Command, args []string) (string, error) {

switch len(args) {
case 0:
if flagSummary {
return resourceStatusesStr(resourcesRes), nil
}
return allResourcesStr(resourcesRes), nil

case 1:
Expand Down Expand Up @@ -515,3 +519,125 @@ func titleStr(title string) string {
bottom := strings.Repeat("-", titleLength)
return "\n" + top + "\n" + title + "\n" + bottom + "\n\n"
}

func resourceStatusesStr(resourcesRes *schema.GetResourcesResponse) string {
out := "\n"
out += pythonPackageStatusesStr(resourcesRes.DataStatuses, resourcesRes.Context) + "\n"
out += rawColumnStatusesStr(resourcesRes.DataStatuses, resourcesRes.Context) + "\n"
out += aggregateStatusesStr(resourcesRes.DataStatuses, resourcesRes.Context) + "\n"
out += transformedColumnStatusesStr(resourcesRes.DataStatuses, resourcesRes.Context) + "\n"
out += trainingDatasetStatusesStr(resourcesRes.DataStatuses, resourcesRes.Context) + "\n"
out += modelStatusesStr(resourcesRes.DataStatuses, resourcesRes.Context) + "\n"
out += apiStatusesStr(resourcesRes.APIGroupStatuses)
return out
}

func pythonPackageStatusesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Context) string {
var statuses = make([]resource.Status, len(ctx.PythonPackages))
i := 0
for _, pythonPackage := range ctx.PythonPackages {
statuses[i] = dataStatuses[pythonPackage.GetID()]
i++
}
return "Python Packages: " + StatusStr(statuses)
}

func rawColumnStatusesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Context) string {
var statuses = make([]resource.Status, len(ctx.RawColumns))
i := 0
for _, rawColumn := range ctx.RawColumns {
statuses[i] = dataStatuses[rawColumn.GetID()]
i++
}
return "Raw Columns: " + StatusStr(statuses)
}

func aggregateStatusesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Context) string {
var statuses = make([]resource.Status, len(ctx.Aggregates))
i := 0
for _, aggregate := range ctx.Aggregates {
statuses[i] = dataStatuses[aggregate.GetID()]
i++
}
return "Aggregates: " + StatusStr(statuses)
}

func transformedColumnStatusesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Context) string {
var statuses = make([]resource.Status, len(ctx.TransformedColumns))
i := 0
for _, transformedColumn := range ctx.TransformedColumns {
statuses[i] = dataStatuses[transformedColumn.GetID()]
i++
}
return "Transformed Columns: " + StatusStr(statuses)
}

func trainingDatasetStatusesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Context) string {
var statuses = make([]resource.Status, len(ctx.Models))
i := 0
for _, model := range ctx.Models {
statuses[i] = dataStatuses[model.Dataset.GetID()]
i++
}
return "Training Datasets: " + StatusStr(statuses)
}

func modelStatusesStr(dataStatuses map[string]*resource.DataStatus, ctx *context.Context) string {
var statuses = make([]resource.Status, len(ctx.Models))
i := 0
for _, model := range ctx.Models {
statuses[i] = dataStatuses[model.GetID()]
i++
}
return "Models: " + StatusStr(statuses)
}

func apiStatusesStr(apiGroupStatuses map[string]*resource.APIGroupStatus) string {
var statuses = make([]resource.Status, len(apiGroupStatuses))
i := 0
for _, apiGroupStatus := range apiGroupStatuses {
statuses[i] = apiGroupStatus
i++
}
return "APIs: " + StatusStr(statuses)
}

func StatusStr(statuses []resource.Status) string {
if len(statuses) == 0 {
return "none"
}

messageBuckets := make(map[int][]string)
for _, status := range statuses {
bucketKey := status.GetCode().SortBucket()
messageBuckets[bucketKey] = append(messageBuckets[bucketKey], status.Message())
}

var bucketKeys []int
for bucketKey := range messageBuckets {
bucketKeys = append(bucketKeys, bucketKey)
}
sort.Ints(bucketKeys)

var messageItems []string

for _, bucketKey := range bucketKeys {
messageCounts := make(map[string]int)
for _, message := range messageBuckets[bucketKey] {
messageCounts[message]++
}

var messages []string
for message := range messageCounts {
messages = append(messages, message)
}
sort.Strings(messages)

for _, message := range messages {
messageItem := fmt.Sprintf("%d %s", messageCounts[message], message)
messageItems = append(messageItems, messageItem)
}
}

return strings.Join(messageItems, " | ")
}
3 changes: 2 additions & 1 deletion cli/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
func init() {
addAppNameFlag(logsCmd)
addEnvFlag(logsCmd)
addVerboseFlag(logsCmd)
addResourceTypesToHelp(logsCmd)
}

Expand Down Expand Up @@ -58,7 +59,7 @@ var logsCmd = &cobra.Command{
errors.Exit(err)
}

err = StreamLogs(appName, resourceName, resourceTypeStr, true)
err = StreamLogs(appName, resourceName, resourceTypeStr, flagVerbose)
if err != nil {
errors.Exit(err)
}
Expand Down
11 changes: 10 additions & 1 deletion cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var cmdStr string
var flagEnv string
var flagWatch bool
var flagAppName string
var flagVerbose bool
var flagSummary bool

var configFileExts = []string{"yaml", "yml"}

Expand Down Expand Up @@ -73,7 +75,6 @@ func Execute() {
rootCmd.AddCommand(deleteCmd)

rootCmd.AddCommand(getCmd)
rootCmd.AddCommand(statusCmd)
rootCmd.AddCommand(logsCmd)

rootCmd.AddCommand(configureCmd)
Expand All @@ -99,6 +100,14 @@ func addAppNameFlag(cmd *cobra.Command) {
cmd.PersistentFlags().StringVarP(&flagAppName, "app", "a", "", "app name")
}

func addVerboseFlag(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&flagVerbose, "verbose", "v", false, "show verbose output")
}

func addSummaryFlag(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&flagSummary, "summary", "s", false, "show summarized output")
}

var resourceTypesHelp = fmt.Sprintf("\nResource Types:\n %s\n", strings.Join(resource.VisibleTypes.StringList(), "\n "))

func addResourceTypesToHelp(cmd *cobra.Command) {
Expand Down
Loading