Skip to content
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
3 changes: 3 additions & 0 deletions docs/reference/monitor_clusters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ NOTE: The `monitor cluster` command is currently experimental only and may be ch
* <<set-default-style, `cohctl set default-style`>> - sets the default style for monitor clusters command
* <<get-default-style, `cohctl get default-style`>> - gets the default style for monitor clusters command

NOTE: You can set the color style used by setting the `--style` option, or preview all styles using `--preview-styles`. To
always use a style look at <<set-default-style, `cohctl set default-style`>> command.

[#monitor-cluster]
==== Monitor Cluster

Expand Down
92 changes: 85 additions & 7 deletions pkg/cmd/monitor_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var (
originalMaxHeight int
padMaxHeightParam = true
colorStyleParam string
previewStylesParam bool
showAllPanels bool
ignoreRESTErrors bool
disablePadding bool
Expand Down Expand Up @@ -158,6 +159,11 @@ var styleConfigsMap = map[string]StyleConfig{
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorPeru),
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorMaroon),
},
"fog": {
TextStyle: tcell.StyleDefault.Foreground(tcell.ColorGainsboro),
TitleStyle: tcell.StyleDefault.Foreground(tcell.ColorSlateGray),
BoxStyle: tcell.StyleDefault.Foreground(tcell.ColorDarkSlateGray),
},
}

var validPanels = []panelImpl{
Expand Down Expand Up @@ -220,7 +226,7 @@ require you to specify cache, service, topic or subscriber.
Use --show-panels to show all available panels.`,
ValidArgsFunction: completionAllClusters,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 && !showAllPanels {
if len(args) != 1 && (!showAllPanels && !previewStylesParam) {
displayErrorAndExit(cmd, youMustProviderConnectionMessage)
}
return nil
Expand All @@ -238,6 +244,10 @@ Use --show-panels to show all available panels.`,
return nil
}

if previewStylesParam {
return previewAllStyles()
}

clusterName = args[0]

// set to tru to turn off incompatible color formatting
Expand Down Expand Up @@ -429,6 +439,68 @@ var getDefaultStyleCmd = &cobra.Command{
},
}

func previewAllStyles() error {
screen, err := tcell.NewScreen()
if err != nil {
return err
}
if err = screen.Init(); err != nil {
return err
}
defer screen.Fini()

screen.SetStyle(tcell.StyleDefault)

// ensure we reset the screen on any panic
defer func() {
if r := recover(); r != nil {
screen.Clear()
screen.Show()
screen.Fini()
log.Println("Panic: ", r)
}
}()

sortedStyles := getAllSortedStyles()

y := 1
x := 2
row := 1
for _, styleKey := range sortedStyles {
if style, ok := styleConfigsMap[styleKey]; ok {
titleStyle = style.TitleStyle
drawBox(screen, x, y, x+40, y+4, style.BoxStyle, fmt.Sprintf("Example style: [%s]", styleKey))
drawText(screen, x+1, y+1, x+39, y+1, style.TextStyle, "NODE ID ADDRESS PORT PROCESS")
drawText(screen, x+1, y+2, x+39, y+2, style.TextStyle, " 1 /127.0.0.1 58086 97529")
drawText(screen, x+1, y+3, x+39, y+3, style.TextStyle, " 2 /127.0.0.1 58044 66466")
}

if row%2 == 0 {
// move to next line
y += 5
x = 2
} else {
// move across
x += 45
}
row++
}

drawText(screen, 2, y+1, 40, y+40, tcell.StyleDefault, "Press any key to continue")

screen.Show()

// Wait for any key press
for {
ev := screen.PollEvent()
if _, ok := ev.(*tcell.EventKey); ok {
break
}
}

return nil
}

func setColorStyle() error {
// use default style if none specified
if colorStyleParam == "" {
Expand All @@ -449,17 +521,22 @@ func setColorStyle() error {
func getStyleValue(styleValue string) (StyleConfig, error) {
style, ok := styleConfigsMap[styleValue]
if !ok {
valid := make([]string, 0, len(styleConfigsMap))
for k := range styleConfigsMap {
valid = append(valid, k)
}
sort.Strings(valid)
return StyleConfig{}, fmt.Errorf("invalid color style %s, valid values are %v", colorStyleParam, valid)
return StyleConfig{}, fmt.Errorf("invalid color style %s, valid values are %v", colorStyleParam, getAllSortedStyles())
}

return style, nil
}

func getAllSortedStyles() []string {
sortedList := make([]string, 0, len(styleConfigsMap))
for k := range styleConfigsMap {
sortedList = append(sortedList, k)
}
sort.Strings(sortedList)

return sortedList
}

func updateExpanded(pressedKey rune, screen tcell.Screen, dataFetcher fetcher.Fetcher, parsedLayout []string) {
if expandedPanel != "" {
expandedPanel = ""
Expand Down Expand Up @@ -1606,4 +1683,5 @@ func init() {
monitorClusterCmd.Flags().Int64VarP(&subscriber, "subscriber-id", "B", 0, "subscriber")
monitorClusterCmd.Flags().IntVarP(&setMaxHeight, "max-height", "M", 0, "override max height for all panels")
monitorClusterCmd.Flags().BoolVarP(&ignoreSpecialCaches, "ignore-special", "", false, ignoreCachesDescription)
monitorClusterCmd.Flags().BoolVarP(&previewStylesParam, "preview-styles", "", false, "preview all the styles")
}
Loading