Skip to content

Add new node status metrics #71

Merged
sarah-witt merged 21 commits into
masterfrom
sarah/add-more-tags-nodes
Jun 22, 2020
Merged

Add new node status metrics #71
sarah-witt merged 21 commits into
masterfrom
sarah/add-more-tags-nodes

Conversation

@sarah-witt

@sarah-witt sarah-witt commented Jun 9, 2020

Copy link
Copy Markdown
Collaborator

Requirements for Contributing to this repository

  • Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • The pull request must only fix one issue at the time.
  • The pull request must update the test suite to demonstrate the changed functionality.
  • After you create the pull request, all status checks must be pass before a maintainer reviews your contribution. For more details, please see CONTRIBUTING.

What does this PR do?

  • Adds new node status metrics that are tagged by node, so that we can determine which nodes are offline/online, and when.
  • These metrics are submitted as a 1 or 0, but when summed across nodes/labels, they can also show total number of nodes, etc.

Description of the Change

Alternate Designs

Possible Drawbacks

Verification Process

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@github-actions github-actions Bot added the documentation Documentation related changes label Jun 15, 2020
@sarah-witt sarah-witt changed the title Add computer tags to node metrics Add new node status metrics Jun 15, 2020
@@ -0,0 +1,15 @@
package org.datadog.jenkins.plugins.datadog.publishers;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@sarah-witt
sarah-witt marked this pull request as ready for review June 15, 2020 19:30
@sarah-witt sarah-witt added changelog/Added Added features results into a minor version bump and removed changelog/Added Added features results into a minor version bump labels Jun 15, 2020

@ChristineTChen ChristineTChen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it make sense to submit the metric here?

Suggested change
online = false;
client.gauge("jenkins.node_status.offline", isOffline, hostname, tags);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@ChristineTChen ChristineTChen Jun 15, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 🔴

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's true! It could even be named something different like jenkins.node_status.up or something like that
cc @FlorianVeaux

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is a great idea, this will work exactly the same way as the datadog.agent.up metric.
So 👍

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

globalTags = TagsUtil.addTagToTags(globalTags, "jenkins_url", DatadogUtilities.getJenkinsUrl());
for (Computer computer : computers) {
Map<String, Set<String>> tags = TagsUtil.merge(
DatadogUtilities.getComputerTags(computer), globalTags);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

@sarah-witt sarah-witt Jun 16, 2020

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh that's correct, thanks I missed that 👍

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

FlorianVeaux
FlorianVeaux previously approved these changes Jun 17, 2020
ChristineTChen
ChristineTChen previously approved these changes Jun 17, 2020

@ChristineTChen ChristineTChen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Just a minor comment to simplify the logic :)

Map<String, Set<String>> tags = TagsUtil.merge(
DatadogUtilities.getComputerTags(computer), globalTags);
nodeCount++;
boolean online = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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);
}	              

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure, that way is simpler now that there's only one metric!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated!

@sarah-witt sarah-witt added the changelog/Added Added features results into a minor version bump label Jun 17, 2020

@ChristineTChen ChristineTChen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@sarah-witt
sarah-witt merged commit f092e48 into master Jun 22, 2020
@sarah-witt
sarah-witt deleted the sarah/add-more-tags-nodes branch June 22, 2020 14:04
sarah-witt added a commit that referenced this pull request Jun 22, 2020
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Added Added features results into a minor version bump documentation Documentation related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants