-
Notifications
You must be signed in to change notification settings - Fork 66
WIP: feat(status) display failed_reason for a failing Kafka instance #476
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,14 @@ import ( | |
| "fmt" | ||
| "io" | ||
| "reflect" | ||
| "strings" | ||
| "text/tabwriter" | ||
|
|
||
| "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/connection" | ||
| "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/kafka" | ||
|
|
||
| "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/color" | ||
|
|
||
| "github.com/bf2fc6cc711aee1a0c2a/cli/internal/config" | ||
| "github.com/bf2fc6cc711aee1a0c2a/cli/internal/localizer" | ||
| kas "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/api/kas" | ||
| kasclient "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/api/kas/client" | ||
| "github.com/bf2fc6cc711aee1a0c2a/cli/pkg/logging" | ||
|
|
@@ -30,6 +30,7 @@ type KafkaStatus struct { | |
| Name string `json:"name,omitempty"` | ||
| Status string `json:"status,omitempty"` | ||
| BootstrapServerHost string `json:"bootstrap_server_host,omitempty" title:"Bootstrap URL"` | ||
| FailedReason string `json:"failed_reason,omitempty" title:"Failed Reason"` | ||
| } | ||
|
|
||
| type Options struct { | ||
|
|
@@ -64,14 +65,14 @@ func Get(ctx context.Context, opts *Options) (status *Status, ok bool, err error | |
| if kas.IsErr(err, kas.ErrorNotFound) { | ||
| err = kafka.ErrorNotFound(kafkaCfg.ClusterID) | ||
| logger.Info(err) | ||
| logger.Info("Run", color.CodeSnippet("rhoas kafka use --id=<kafka-instance-id>"), "to use another Kafka instance.") | ||
| logger.Info(localizer.MustLocalizeFromID("status.log.info.selectAnotherKafka")) | ||
| } | ||
| } else { | ||
| status.Kafka = kafkaStatus | ||
| ok = true | ||
| } | ||
| } else { | ||
| logger.Debug("No Kafka instance is currently used, skipping status check") | ||
| logger.Debug(localizer.MustLocalizeFromID("status.log.debug.noKafkaSelected")) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouild this be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What convention should we follow to localize strings splitted like this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think they need to see that information all the time. If I use $ rhoas status
A
-------------------
Blah:
Blah:
Blah:
Blah:
No B instance is currently used, skipping status check
No C instance is currently used, skipping status check
No D instance is currently used, skipping status check
No E instance is currently used, skipping status check
No F instance is currently used, skipping status check
No G instance is currently used, skipping status check
No H instance is currently used, skipping status check
No I instance is currently used, skipping status check
No J instance is currently used, skipping status check
No K instance is currently used, skipping status check
No L instance is currently used, skipping status check
No M instance is currently used, skipping status check
..."No B instance is currently used, skipping status check" does not tell the user much more than they can already figure out by there being no status information about the service in the output, but it is useful if they know that this service is currently used, they can check if it is being skipped, which can be useful to debug the problem.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This was only split because Since we are using localization now, there will be no need for splitting the strings like this as the full sentence is formed in the locales file. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -120,10 +121,12 @@ func printServiceStatus(w io.Writer, name string, v reflect.Value) { | |
| // get the title to use for the field | ||
| title := getTitle(&fieldType) | ||
|
|
||
| // print the row and take note of its character length | ||
| len, _ := fmt.Fprintf(tw, "%v:\t\t%v\n", title, fieldValue) | ||
| if len > maxRowLen { | ||
| maxRowLen = len | ||
| if !getOmitEmpty(&fieldType) || !fieldValue.IsZero() { | ||
| // print the row and take note of its character length | ||
| len, _ := fmt.Fprintf(tw, "%v:\t\t%v\n", title, fieldValue) | ||
| if len > maxRowLen { | ||
| maxRowLen = len | ||
| } | ||
| } | ||
| } | ||
| // print the service header | ||
|
|
@@ -146,6 +149,17 @@ func getTitle(f *reflect.StructField) string { | |
| return tag | ||
| } | ||
|
|
||
| // check if omitempty is set | ||
| func getOmitEmpty(f *reflect.StructField) bool { | ||
| var omitempty bool | ||
| tag := f.Tag.Get("json") | ||
| if tag != "" { | ||
| omitempty = strings.Contains(tag, "omitempty") | ||
| } | ||
|
|
||
| return omitempty | ||
| } | ||
|
|
||
| // create a divider for the top of the table of n length | ||
| func createDivider(n int) string { | ||
| b := "-" | ||
|
|
@@ -172,6 +186,10 @@ func getKafkaStatus(ctx context.Context, api kasclient.DefaultApi, id string) (s | |
| BootstrapServerHost: kafkaResponse.GetBootstrapServerHost(), | ||
| } | ||
|
|
||
| if kafkaResponse.GetStatus() == "failed" { | ||
| status.FailedReason = kafkaResponse.GetFailedReason() | ||
| } | ||
|
|
||
| return status, err | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omitemptyis not getting rid of theFailedReasonkey when the value is"". Same goes with other fields(tested by hardcoding).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, we will need to update the status printing logic in
printServiceStatusto skip the field if omitempty is set and the value is empty.