-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add cluster command to show cluster and peer statuses. #2256
Add cluster command to show cluster and peer statuses. #2256
Conversation
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.
Thanks for this! A few comments but this is in the right direction.
cli/format/format_extended.go
Outdated
@@ -89,6 +89,23 @@ func (formatter *ExtendedFormatter) FormatConfig(status *models.AlertmanagerStat | |||
return nil | |||
} | |||
|
|||
// FormatClusterStatus formats the cluster status with peers into a readable string |
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.
(nit) missing dot at the end.
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.
added 🎉
cli/format/format_extended.go
Outdated
// FormatClusterStatus formats the cluster status with peers into a readable string | ||
func (formatter *ExtendedFormatter) FormatClusterStatus(status *models.ClusterStatus) error { | ||
w := tabwriter.NewWriter(formatter.writer, 0, 0, 2, ' ', 0) | ||
fmt.Fprintf(w, "Cluster Status:\t%s\n\n", *status.Status) |
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.
I would add the node's name (e.g. status.Name
).
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.
I added the node name into the simple format as well
cli/format/format_simple.go
Outdated
@@ -75,6 +75,12 @@ func (formatter *SimpleFormatter) FormatConfig(status *models.AlertmanagerStatus | |||
return nil | |||
} | |||
|
|||
func (formatter *SimpleFormatter) FormatClusterStatus(status *models.ClusterStatus) error { | |||
w := tabwriter.NewWriter(formatter.writer, 0, 0, 2, ' ', 0) | |||
fmt.Fprintf(w, "Cluster Status:\t%s\n", *status.Status) |
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.
ditto
cli/format/sort.go
Outdated
func (s ByAddress) Len() int { return len(s) } | ||
func (s ByAddress) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | ||
func (s ByAddress) Less(i, j int) bool { | ||
return bytes.Compare([]byte(*s[i].Address), []byte(*s[j].Address)) < 0 |
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.
not sure why you cast string to bytes.
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.
I double-checked this logic and that was wrong. I need to collect an IP addresses from host:ip format. Then using net.IP to comparing using bytes will be much correct
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.
Here is the new way
func (s ByAddress) Less(i, j int) bool {
ip1, port1, _ := net.SplitHostPort(*s[i].Address)
ip2, port2, _ := net.SplitHostPort(*s[j].Address)
if ip1 == ip2 {
return port1 < port2
} else {
return bytes.Compare(net.ParseIP(ip1), net.ParseIP(ip2)) < 0
}
}
Im not sure about the ignoring errors what do you think about this implementation
This way it can also sort same-ip different ports
8b18362
to
cc0d7d6
Compare
cc0d7d6
to
242c5d6
Compare
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.
one last nit
Which part is this nit @simonpasquier 🤔 |
hmm GitHub discarded my previous comment... |
Signed-off-by: Fahri Yardımcı <f.yardimci06@gmail.com> Signed-off-by: Fahri Yardımcı <f.yardimci06@gmail.com>
b8dbe09
to
a6adf4d
Compare
Thanks! |
Closes #2192
This pr implements amtool cluster show command
Simple output
Extended output
Json output