Skip to content
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

Merged
merged 3 commits into from Oct 22, 2018

Conversation

kishansagathiya
Copy link
Contributor

@kishansagathiya kishansagathiya commented Oct 7, 2018

  • Opened new endpoint GET /health/metrics/<name> which would respond
    with metrics of type <name>
  • Support the new endpoint in rest/api/client
  • Support the new method in ipfs-cluster-ctl. i.e. ipfs-cluster-ctl health metrics would show the peers and the last list of metrics logged for each as returned by the Peer Monitor, in a friendly way.
  • Tests

Fixes #449

@ghost ghost assigned kishansagathiya Oct 7, 2018
@ghost ghost added the status/in-progress In progress label Oct 7, 2018
@coveralls
Copy link

coveralls commented Oct 7, 2018

Coverage Status

Coverage decreased (-0.3%) to 65.182% when pulling ec4588a on kishansagathiya:issue_449 into b0b826d on ipfs:master.

@kishansagathiya
Copy link
Contributor Author

@hsanjuan @lanzafame
If this looks good to you so far, I can start with tests.

Copy link
Collaborator

@hsanjuan hsanjuan left a 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.


// PeerMonitorLatestMetrics returns a map with the latest metrics of matching name
// for the current cluster peers.
PeerMonitorLatestMetrics(name string) ([]api.Metric, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PeerMonitorLatestMetrics(name string) ([]api.Metric, error)
Metrics(name string) ([]api.Metric, error)

@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// PeerMonitorLatestMetrics returns a map with the latest metrics of matching name
// Metrics returns a map with the latest metrics of matching name

{
"PeerMonitorLatestMetrics",
"GET",
"/health/metrics/{name}",
Copy link
Collaborator

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?

"PeerMonitorLatestMetrics",
name,
&metrics)
sendResponse(w, err, metrics)
Copy link
Collaborator

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)

@@ -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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Collaborator

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)

Copy link
Collaborator

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)

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Expire/Valid

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)
Copy link
Collaborator

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.

@@ -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.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Usage: "Get latest metrics of matching name for the current cluster peers.",
Usage: "List latest metrics logged by this peer",

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
Copy link
Collaborator

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.

kishansagathiya added a commit to kishansagathiya/ipfs-cluster that referenced this pull request Oct 21, 2018
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>
Copy link
Collaborator

@hsanjuan hsanjuan left a 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 hsanjuan mentioned this pull request Oct 22, 2018
@hsanjuan hsanjuan merged commit 48c89fb into ipfs-cluster:master Oct 22, 2018
@ghost ghost removed the status/in-progress In progress label Oct 22, 2018
@kishansagathiya
Copy link
Contributor Author

@hsanjuan Wouldn' this change require us to add sharness tests ? My bad, I took too long to update this PR.

@hsanjuan
Copy link
Collaborator

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 ipfs-cluster repo/origin? That way I can commit to them and can save some roundtrips.

@kishansagathiya
Copy link
Contributor Author

can you create your branches directly in the ipfs-cluster repo/origin

Sure, will do that

hsanjuan added a commit that referenced this pull request Oct 23, 2018
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>
@hsanjuan hsanjuan mentioned this pull request Oct 23, 2018
name := vars["name"]

var metrics []types.Metric
err := api.rpcClient.Call("",
Copy link
Contributor

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. 🙂

Copy link
Contributor Author

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

hsanjuan added a commit that referenced this pull request Oct 25, 2018
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>
hsanjuan added a commit that referenced this pull request Oct 26, 2018
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>
hsanjuan added a commit that referenced this pull request Oct 26, 2018
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>
@kishansagathiya kishansagathiya deleted the issue_449 branch November 6, 2019 15:38
@kishansagathiya kishansagathiya restored the issue_449 branch November 6, 2019 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants