Add new node status metrics #71
Conversation
| @@ -0,0 +1,15 @@ | |||
| package org.datadog.jenkins.plugins.datadog.publishers; | |||
There was a problem hiding this comment.
An alternative way to stub the client would be to use PowerMock as in: #74, which means we wouldn't need this file and to add a wrapper getDatadogClient() method.
| expectedTags[1] = "node_label:master"; | ||
| expectedTags[2] = "jenkins_url:" + url; | ||
|
|
||
| // The CI sets a hostname but we cannot set a hostname locally: https://javadoc.jenkins-ci.org/hudson/model/Computer.html#getHostName-- |
There was a problem hiding this comment.
This case was tricky- locally computer.getHostname() does not return anything, but on the CI it does. I couldn't find a good way to update this, see https://javadoc.jenkins-ci.org/hudson/model/Computer.html#getHostName--
There was a problem hiding this comment.
I'm wondering if just 1 metric would appropriately represent the status? For example, would it make more sense if we submit jenkins.node_status.online as 1 when it's online and 0 when it's not vs submitting jenkins.node_status.offline with the opposite value?
The number of offline nodes can also be calculated with jenkins.node_status.count - jenkins.node_status.online
| nodeCount++; | ||
| boolean online = true; | ||
| if (computer.isOffline()) { | ||
| online = false; |
There was a problem hiding this comment.
Would it make sense to submit the metric here?
| online = false; | |
| client.gauge("jenkins.node_status.offline", isOffline, hostname, tags); |
There was a problem hiding this comment.
Hm that is true- both the offline and online metrics aren't needed. These metrics were based off of the jenkins.node.* metrics though, and there is both a jenkins.node.offline and a jenkins.node.online, so it would be inconsistent if we submitted only one of them for node_status. It's definitely worth considering though.
There was a problem hiding this comment.
jenkins.node.offline and jenkins.node.online are total counts vs standalone status. It does work to immediately query a metric for a node to see its exact status. I was thinking in terms of metrics like a service check, we only use can_connect to determine 🟢 or 🔴
There was a problem hiding this comment.
That's true! It could even be named something different like jenkins.node_status.up or something like that
cc @FlorianVeaux
There was a problem hiding this comment.
I think this is a great idea, this will work exactly the same way as the datadog.agent.up metric.
So 👍
There was a problem hiding this comment.
Updated! Thanks for the suggestion @ChristineTChen !
| expectedTags[1] = "node_label:master"; | ||
| expectedTags[2] = "jenkins_url:" + url; | ||
|
|
||
| // The CI sets a hostname but we cannot set a hostname locally: https://javadoc.jenkins-ci.org/hudson/model/Computer.html#getHostName-- |
| globalTags = TagsUtil.addTagToTags(globalTags, "jenkins_url", DatadogUtilities.getJenkinsUrl()); | ||
| for (Computer computer : computers) { | ||
| Map<String, Set<String>> tags = TagsUtil.merge( | ||
| DatadogUtilities.getComputerTags(computer), globalTags); |
There was a problem hiding this comment.
Can we quickly benchmark this method ? Especially the call to computer.getHostname. According to docs this method can be slow as the master will try various endpoints.
At the moment this method is only used upon modification of a computer status, now it will be run periodically. Is there any layer of caching happening?
There was a problem hiding this comment.
Yeah, true. I can look into it. I'm not sure if the hostname tags are needed/helpful for these metrics so it might be worth using a new method that doesn't calculate hostname.
There was a problem hiding this comment.
One thing to note is I'm not changing the amount of times getComputerTags is called, this line is just moving it up in the loop: https://github.com/jenkinsci/datadog-plugin/pull/71/files#diff-e231a7baaf7bf9e40bbcfcd53c65b47cL95
There was a problem hiding this comment.
Oh that's correct, thanks I missed that 👍
There was a problem hiding this comment.
The method is pretty time consuming, though (locally running my new tests it takes 22.465s). It's definitely something to keep in mind when thinking of improvements to clients.
ChristineTChen
left a comment
There was a problem hiding this comment.
LGTM! Just a minor comment to simplify the logic :)
| Map<String, Set<String>> tags = TagsUtil.merge( | ||
| DatadogUtilities.getComputerTags(computer), globalTags); | ||
| nodeCount++; | ||
| boolean online = true; |
There was a problem hiding this comment.
any reason to keep this variable? what if the metric is submitted during the online/offline checks?
if (computer.isOffline()) {
nodeOffline++;
client.gauge("jenkins.node_status.up", 0, hostname, tags);
}
if (computer.isOnline()) {
nodeOnline++;
client.gauge("jenkins.node_status.up", 1, hostname, tags);
}
There was a problem hiding this comment.
Sure, that way is simpler now that there's only one metric!
* Add computer tags * Add node tags * Add test for hostname * correct node status * Change package * Remove multiple variables * Add more test cases * Fix formatting * Add link to comment * Add comment to new assertion * Change to node status up * Fix typo * Remove loop in tests: * Add computer tag * Remove tags * Use new client factory testing * Remove spaces * Update comment * Fix space * Add better description
Requirements for Contributing to this repository
What does this PR do?
Description of the Change
Alternate Designs
Possible Drawbacks
Verification Process
Additional Notes
Release Notes
Review checklist (to be filled by reviewers)
changelog/label attached. If applicable it should have thebackward-incompatiblelabel attached.do-not-merge/label attached.kind/andseverity/labels attached at least.