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
Issue #449 API endpoint for Peer Monitor metrics #572
Conversation
@hsanjuan @lanzafame |
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! First round of comments.
api/rest/client/client.go
Outdated
|
||
// PeerMonitorLatestMetrics returns a map with the latest metrics of matching name | ||
// for the current cluster peers. | ||
PeerMonitorLatestMetrics(name string) ([]api.Metric, error) |
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.
PeerMonitorLatestMetrics(name string) ([]api.Metric, error) | |
Metrics(name string) ([]api.Metric, error) |
api/rest/client/client.go
Outdated
@@ -103,6 +103,10 @@ type Client interface { | |||
// GetConnectGraph returns an ipfs-cluster connection graph. The | |||
// serialized version, strings instead of pids, is returned | |||
GetConnectGraph() (api.ConnectGraphSerial, error) | |||
|
|||
// PeerMonitorLatestMetrics returns a map with the latest metrics of matching 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.
// PeerMonitorLatestMetrics returns a map with the latest metrics of matching name | |
// Metrics returns a map with the latest metrics of matching name |
api/rest/restapi.go
Outdated
{ | ||
"PeerMonitorLatestMetrics", | ||
"GET", | ||
"/health/metrics/{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.
Let's name this /monitor/metrics/..
because this comes from the monitor component? Or should this be /informer/<name>
because it returns stuff from the informer
. Hmm I'm not sure. @lanzafame what do you think?
api/rest/restapi.go
Outdated
"PeerMonitorLatestMetrics", | ||
name, | ||
&metrics) | ||
sendResponse(w, err, metrics) |
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.
will break with #578 . Reminder to rebase on master once that's merged. (or viceversa)
cmd/ipfs-cluster-ctl/formatters.go
Outdated
@@ -202,6 +215,15 @@ func textFormatPrintAddedOutput(obj *api.AddedOutput) { | |||
fmt.Printf("added %s %s\n", obj.Cid, obj.Name) | |||
} | |||
|
|||
func textFormatPrintMetric(obj *api.Metric) { | |||
fmt.Printf("{\n") | |||
fmt.Printf(" Peer: %s\n", (obj.Peer).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.
fmt.Printf(" Peer: %s\n", (obj.Peer).String()) | |
fmt.Printf(" Peer: %s\n", obj.Peer.Pretty()) |
@@ -202,6 +215,15 @@ func textFormatPrintAddedOutput(obj *api.AddedOutput) { | |||
fmt.Printf("added %s %s\n", obj.Cid, obj.Name) | |||
} | |||
|
|||
func textFormatPrintMetric(obj *api.Metric) { |
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.
This should not be { .. }
. This is text. i.e.
<peer> | <metric name>:
> Value: <v>
> Expire: <date>
> Valid: <t>
for consistency with other outputs (peers ls)
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.
On second thoughts, Valid
will be always true so we can skip that. We should probably collapse them to a single line:
<peer id>: <value> | Expire: <date>
(user should know the name anyway so we skip)
cmd/ipfs-cluster-ctl/formatters.go
Outdated
fmt.Printf(" Peer: %s\n", (obj.Peer).String()) | ||
fmt.Printf(" Value: %s\n", obj.Value) | ||
fmt.Printf(" Expire: %d\n", obj.Expire) | ||
fmt.Printf(" Expire: %t\n", obj.Valid) |
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.
s/Expire/Valid
cmd/ipfs-cluster-ctl/formatters.go
Outdated
fmt.Printf("{\n") | ||
fmt.Printf(" Peer: %s\n", (obj.Peer).String()) | ||
fmt.Printf(" Value: %s\n", obj.Value) | ||
fmt.Printf(" Expire: %d\n", obj.Expire) |
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.
We do %s
for a date in a different place (textFormatPrintGPInfo). I don't know if the result is the same, but we should use the same printing format for dates in both places.
cmd/ipfs-cluster-ctl/main.go
Outdated
@@ -762,6 +762,20 @@ graph of the connections. Output is a dot file encoding the cluster's connectio | |||
return nil | |||
}, | |||
}, | |||
{ | |||
Name: "metrics", | |||
Usage: "Get latest metrics of matching name for the current cluster peers.", |
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.
Usage: "Get latest metrics of matching name for the current cluster peers.", | |
Usage: "List latest metrics logged by this peer", |
cmd/ipfs-cluster-ctl/main.go
Outdated
Name: "metrics", | ||
Usage: "Get latest metrics of matching name for the current cluster peers.", | ||
Description: ` | ||
This command would show the peers and the last list of metrics logged for each as |
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.
This commands displays the latest valid metrics of the given type logged by this peer for all current cluster peers.
Rename method PeerMonitorLatestMetrics to Metrics Addressing first round of comment as in ipfs-cluster#572 (review) License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Opened new endpoint `GET /health/metrics/<name>` which would respond with metrics of type <name> License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Support the new endpoint for later metrics in `rest/api/client` Support the new method created in `rest/api/client` in ipfs-cluster-ctl. i.e. `ipfs-cluster-ctl health metrics <name>` would show the peers and the last list of metrics logged for each as returned by the Peer Monitor, in a friendly way. License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
Rename method PeerMonitorLatestMetrics to Metrics Addressing first round of comment as in ipfs-cluster#572 (review) License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
16cc58a
to
ec4588a
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.
Cool, I missed this was ready! Thanks @kishansagathiya
@hsanjuan Wouldn' this change require us to add sharness tests ? My bad, I took too long to update this PR. |
Hmm, actually it requires API tests, client tests and sharness tests. Can you do another PR? Also, can you create your branches directly in the |
Sure, will do that |
Issue #572 exposes metrics but they carry the peer ID in binary. This was ok with our internal codecs but it doesn't seem to work very well with json, and makes the output format unusable. This makes the Metric.Peer field a string. Additinoally, fixes calling the command without arguments and displaying the date in the right format. License: MIT Signed-off-by: Hector Sanjuan <code@hector.link>
name := vars["name"] | ||
|
||
var metrics []types.Metric | ||
err := api.rpcClient.Call("", |
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.
@kishansagathiya I am not reopening this pr for this but in the future if multilining a function call do it in the format of a multiline struct initialization, i.e.
err := api.rpcClient.Call(
"",
"Cluster",
"PeerMonitorLatestMetrics",
name,
&metrics,
)
Benefits of doing it this way are 1) new parameters don't result in a multiline git diff but just a single addition, 2) the first parameter doesn't visually blend into the with the function call.
Don't worry about changing it now. This is just for future reference. 🙂
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.
will keep this in mind
Issue #572 exposes metrics but they carry the peer ID in binary. This was ok with our internal codecs but it doesn't seem to work very well with json, and makes the output format unusable. This makes the Metric.Peer field a string. Additinoally, fixes calling the command without arguments and displaying the date in the right format. License: MIT Signed-off-by: Hector Sanjuan <code@hector.link>
Issue #572 exposes metrics but they carry the peer ID in binary. This was ok with our internal codecs but it doesn't seem to work very well with json, and makes the output format unusable. This makes the Metric.Peer field a string. Additinoally, fixes calling the command without arguments and displaying the date in the right format. License: MIT Signed-off-by: Hector Sanjuan <code@hector.link>
Issue #572 exposes metrics but they carry the peer ID in binary. This was ok with our internal codecs but it doesn't seem to work very well with json, and makes the output format unusable. This makes the Metric.Peer field a string. Additinoally, fixes calling the command without arguments and displaying the date in the right format. License: MIT Signed-off-by: Hector Sanjuan <code@hector.link>
GET /health/metrics/<name>
which would respondwith metrics of type
<name>
Fixes #449