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

[tags] service instance tag should not be excluded if specified. #360

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Instance(
// Make sure to refresh the beans list every 10 minutes
// Useful because sometimes if the application restarts, jmxfetch might read
// a jmxtree that is not completely initialized and would be missing some attributes
this.refreshBeansPeriod = DEFAULT_REFRESH_BEANS_PERIOD;
this.refreshBeansPeriod = DEFAULT_REFRESH_BEANS_PERIOD;
}
} else {
// Allow global overrides
Expand All @@ -146,7 +146,7 @@ public Instance(
// by refresh_beans
// Useful for Java applications that are lazy loaded and may take some time after
// application startup before actually being exposed
this.initialRefreshBeansPeriod = this.refreshBeansPeriod;
this.initialRefreshBeansPeriod = this.refreshBeansPeriod;
}
} else {
// Allow global overrides
Expand Down Expand Up @@ -575,6 +575,7 @@ private void getMatchingAttributes() throws IOException {
beanName,
className,
instanceName,
service,
checkName,
connection,
tags,
Expand All @@ -593,6 +594,7 @@ private void getMatchingAttributes() throws IOException {
beanName,
className,
instanceName,
service,
checkName,
connection,
tags,
Expand All @@ -610,6 +612,7 @@ private void getMatchingAttributes() throws IOException {
beanName,
className,
instanceName,
service,
checkName,
connection,
tags,
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/org/datadog/jmxfetch/JmxAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public abstract class JmxAttribute {
private ObjectName beanName;
private String domain;
private String className;
private String serviceName;
private String beanStringName;
private Map<String, String> beanParameters;
private String attributeName;
Expand All @@ -66,6 +67,7 @@ public abstract class JmxAttribute {
ObjectName beanName,
String className,
String instanceName,
String serviceName,
String checkName,
Connection connection,
Map<String, String> instanceTags,
Expand All @@ -80,6 +82,7 @@ public abstract class JmxAttribute {
this.beanStringName = beanName.toString();
this.cassandraAliasing = cassandraAliasing;
this.checkName = checkName;
this.serviceName = serviceName; // alternatively store this as "service:" + serviceName

// A bean name is formatted like that:
// org.apache.cassandra.db:type=Caches,keyspace=system,cache=HintsColumnFamilyKeyCache
Expand Down Expand Up @@ -109,7 +112,14 @@ private void applyTagsBlackList() {

for (String excludedTagName : include.getExcludeTags()) {
for (Iterator<String> it = this.defaultTagsList.iterator(); it.hasNext(); ) {
if (it.next().startsWith(excludedTagName + ":")) {
String tag = it.next();
if (tag.startsWith("service:")) {
if (tag.equals("service:" + this.serviceName)) {
continue;
} else {
it.remove();
}
olivielpeau marked this conversation as resolved.
Show resolved Hide resolved
} else if (tag.startsWith(excludedTagName + ":")) {
it.remove();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/datadog/jmxfetch/JmxComplexAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public JmxComplexAttribute(
ObjectName beanName,
String className,
String instanceName,
String serviceName,
String checkName,
Connection connection,
Map<String, String> instanceTags,
Expand All @@ -33,6 +34,7 @@ public JmxComplexAttribute(
beanName,
className,
instanceName,
serviceName,
checkName,
connection,
instanceTags,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/datadog/jmxfetch/JmxSimpleAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public JmxSimpleAttribute(
ObjectName beanName,
String className,
String instanceName,
String serviceName,
String checkName,
Connection connection,
Map<String, String> instanceTags,
Expand All @@ -31,6 +32,7 @@ public JmxSimpleAttribute(
beanName,
className,
instanceName,
serviceName,
checkName,
connection,
instanceTags,
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/datadog/jmxfetch/JmxSubAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ abstract class JmxSubAttribute extends JmxAttribute {
private Map<String, Metric> cachedMetrics = new HashMap<String, Metric>();

public JmxSubAttribute(MBeanAttributeInfo attribute, ObjectName beanName, String className,
String instanceName, String checkName, Connection connection,
String instanceName, String serviceName, String checkName, Connection connection,
Map<String, String> instanceTags, boolean cassandraAliasing,
boolean emptyDefaultHostname) {
super(attribute, beanName, className, instanceName, checkName, connection, instanceTags,
cassandraAliasing, emptyDefaultHostname);
super(attribute, beanName, className, instanceName, serviceName, checkName, connection,
instanceTags, cassandraAliasing, emptyDefaultHostname);
}

public Metric getCachedMetric(String name) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/datadog/jmxfetch/JmxTabularAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public JmxTabularAttribute(
ObjectName beanName,
String className,
String instanceName,
String serviceName,
String checkName,
Connection connection,
Map<String, String> instanceTags,
Expand All @@ -42,6 +43,7 @@ public JmxTabularAttribute(
beanName,
className,
instanceName,
serviceName,
checkName,
connection,
instanceTags,
Expand Down
27 changes: 26 additions & 1 deletion src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,31 @@ public void testExcludeTags() throws Exception {
assertMetric("test1.histogram", 424242, commonTags, 2, "histogram");
}

@Test
public void testExcludeServiceTagsAndOverride() throws Exception {
// We expose a few metrics through JMX
SimpleTestJavaApp testApp = new SimpleTestJavaApp();
registerMBean(testApp, "org.datadog.jmxfetch.test:type=SimpleTestJavaApp,service=foo");
olivielpeau marked this conversation as resolved.
Show resolved Hide resolved

// We do a first collection
initApplication("jmx_exclude_tags_override_service.yml");
run();
List<Map<String, Object>> metrics = getMetrics();

// We test for the presence and the value of the metrics we want to collect.
// Tags "type", "newTag" and "env" should be excluded
List<String> commonTags =
Arrays.asList("instance:jmx_test_service_override_instance",
"jmx_domain:org.datadog.jmxfetch.test","service:test");

// 15 = 13 metrics from java.lang + the 2 collected (gauge and histogram)
assertEquals(15, metrics.size());

// There should only left 2 tags per metric
assertMetric("test1.gauge", 1000.0, commonTags, 3, "gauge");
assertMetric("test1.histogram", 424242, commonTags, 3, "histogram");
}

@Test
public void testAdditionalTags() throws Exception {
// We expose a few metrics through JMX
Expand Down Expand Up @@ -844,7 +869,7 @@ public void testAppCounterRate() throws Exception {
assertCoverage();
}

/**
/**
* Test JMX Service Discovery.
* */
@Test
Expand Down
24 changes: 24 additions & 0 deletions src/test/resources/jmx_exclude_tags_override_service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
init_config:

instances:
- process_name_regex: .*surefire.*
name: jmx_test_service_override_instance
service: test
tags:
env: stage
newTag: test
conf:
- include:
domain: org.datadog.jmxfetch.test
exclude_tags:
- env
- type
- newTag
- service
attribute:
ShouldBe1000:
metric_type: gauge
alias: test1.gauge
Int424242:
metric_type: histogram
alias: test1.histogram