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

Support the empty_default_hostname instance field #184

Merged
merged 7 commits into from
Nov 30, 2018
Merged

Support the empty_default_hostname instance field #184

merged 7 commits into from
Nov 30, 2018

Conversation

xvello
Copy link
Contributor

@xvello xvello commented Oct 1, 2018

This makes jmxfetch submit metrics and service-checks with the dummy host: tag for cluster checks. It is supported for metrics since agent5, and for service-checks in 6.6.

See DataDog/datadog-agent#2334 and DataDog/datadog-agent#2351

Copy link
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

Looks great for the most part, just a couple of small comments.

@@ -51,7 +51,8 @@
private Boolean cassandraAliasing;

JMXAttribute(MBeanAttributeInfo attribute, ObjectName beanName, String instanceName,
Connection connection, HashMap<String, String> instanceTags, Boolean cassandraAliasing) {
Connection connection, HashMap<String, String> instanceTags, Boolean cassandraAliasing,
Copy link
Member

Choose a reason for hiding this comment

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

How do you feel we should handle the case where the instanceTags host tag is set (for whatever reason), but emptyDefaultHostname is true. IMHO it might make sense to just evict it from the HashMap and make the boolean option take precedence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For python/golang checks, we want to support an empty default hostname + check-provided hostname override (for kubernetes events node events / kube_state node metrics), so it's a legit use case.

It's currently not possible as an instance tag as it'll be sanitized to bean_host, but could it be added as a bean tag?

If so, do you think there's a better method to plug this logic into?

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave as-is, I think its probably fine.

for (HashMap<String, Object> metric : metrics) {
String[] tags = (String[]) metric.get("tags");
this.assertHostnameTags(Arrays.asList(tags));
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: this doesn't look like it's properly aligned 📏

@@ -83,10 +84,16 @@ public Instance(LinkedHashMap<String, Object> instanceMap, LinkedHashMap<String,
// a jmxtree that is not completely initialized and would be missing some attributes
}

this.minCollectionPeriod = (Integer) instanceMap.get("min_collection_interval");
this.minCollectionPeriod = (Integer) this.instanceMap.get("min_collection_interval");
Copy link
Member

Choose a reason for hiding this comment

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

Not really your fault, but we have so much room for NullPointerException in this constructor.....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, though the same thing while working on it. Do you think we should wrap these in try/catch blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about:

    private boolean emptyDefaultHostname;

...

        try {
            this.emptyDefaultHostname = (Boolean) this.instanceMap.get("empty_default_hostname");
        } catch (NullPointerException e) {
            this.emptyDefaultHostname = false;
        }

if (this.minCollectionPeriod == null && initConfig != null) {
this.minCollectionPeriod = (Integer) initConfig.get("min_collection_interval");
}

this.emptyDefaultHostname = (Boolean) this.instanceMap.get("empty_default_hostname");
Copy link
Member

Choose a reason for hiding this comment

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

Again, not your fault as you're following a pattern used in the class, but I'd say it's safer to use boolean as the type for this.emptyDefaultHostname.

This makes jmxfetch submit metrics and service-checks
with the dummy `host:` tag. It is supported for metrics
since agent5, and for service-checks in 6.6
@xvello
Copy link
Contributor Author

xvello commented Oct 10, 2018

@truthbk rebased and addressed your feedback

Copy link
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

Merging this, I think it looks good, and test health seems to prove no regressions when not enabled, so I'm quite confident this will not break anything. Nice 👍

@@ -51,7 +51,8 @@
private Boolean cassandraAliasing;

JMXAttribute(MBeanAttributeInfo attribute, ObjectName beanName, String instanceName,
Connection connection, HashMap<String, String> instanceTags, Boolean cassandraAliasing) {
Connection connection, HashMap<String, String> instanceTags, Boolean cassandraAliasing,
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave as-is, I think its probably fine.

}

@Test
public void testEmptyDefaultHostname() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

🍰

@truthbk truthbk merged commit 1fa4fd5 into DataDog:master Nov 30, 2018
@xvello xvello deleted the xvello/emptydefaulthostname branch November 30, 2018 09:07
@truthbk truthbk added this to the 0.23.0 milestone Nov 30, 2018
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.

2 participants