Skip to content

Commit

Permalink
Reverted custom jmxfetch bean to track number of ingested beans, attr…
Browse files Browse the repository at this point in the history
…ibutes, and metrics (#468)

* Revert "custom jmxfetch bean to track number of ingested beans, attributes, and metrics (#453)"
This reverts commit 3c03064.

* Revert "remove quotes from bean parameter based tags (#456)"
This reverts commit 02c071f.
  • Loading branch information
carlosroman authored Aug 10, 2023
1 parent 3c03064 commit b33e1d3
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 270 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target/*
.idea
.vscode
*.iml

*.ucls

*.png
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,11 @@ void start() {
System.arraycopy(minibuff, 0, buffer, oldLen, len);
}
}
boolean result = processAutoDiscovery(buffer);
this.setReinit(result);
this.setReinit(processAutoDiscovery(buffer));
}

if (this.appConfig.remoteEnabled()) {
boolean result = getJsonConfigs();
this.setReinit(result);
this.setReinit(getJsonConfigs());
}
} catch (IOException e) {
log.warn(
Expand Down
77 changes: 5 additions & 72 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
import org.datadog.jmxfetch.reporter.Reporter;
import org.datadog.jmxfetch.service.ConfigServiceNameProvider;
import org.datadog.jmxfetch.service.ServiceNameProvider;
import org.datadog.jmxfetch.util.InstanceTelemetry;
import org.yaml.snakeyaml.Yaml;



import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -24,15 +20,8 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.security.auth.login.FailedLoginException;

Expand Down Expand Up @@ -114,10 +103,6 @@ public Yaml initialValue() {
private AppConfig appConfig;
private Boolean cassandraAliasing;
private boolean emptyDefaultHostname;
private InstanceTelemetry instanceTelemetryBean;
private ObjectName instanceTelemetryBeanName;
private MBeanServer mbs;
private Boolean normalizeBeanParamTags;

/** Constructor, instantiates Instance based of a previous instance and appConfig. */
public Instance(Instance instance, AppConfig appConfig) {
Expand Down Expand Up @@ -226,12 +211,6 @@ public Instance(
this.serviceCheckPrefix = (String) initConfig.get("service_check_prefix");
}

this.normalizeBeanParamTags = (Boolean) instanceMap.get("normalize_bean_param_tags");
if (this.normalizeBeanParamTags == null) {
this.normalizeBeanParamTags = false;
}


// Alternative aliasing for CASSANDRA-4009 metrics
// More information: https://issues.apache.org/jira/browse/CASSANDRA-4009
this.cassandraAliasing = (Boolean) instanceMap.get("cassandra_aliasing");
Expand Down Expand Up @@ -278,34 +257,8 @@ public Instance(
} else {
log.info("collect_default_jvm_metrics is false - not collecting default JVM metrics");
}

instanceTelemetryBean = createJmxBean();
}

private ObjectName getObjName(String domain,String instance)
throws MalformedObjectNameException {
return new ObjectName(domain + ":target_instance=" + ObjectName.quote(instance));
}

private InstanceTelemetry createJmxBean() {
mbs = ManagementFactory.getPlatformMBeanServer();
InstanceTelemetry bean = new InstanceTelemetry();
log.debug("Created jmx bean for instance: " + this.getCheckName());

try {
instanceTelemetryBeanName = getObjName("JMXFetch" , this.getName());
mbs.registerMBean(bean,instanceTelemetryBeanName);
log.debug("Succesfully registered jmx bean for instance: " + this.getCheckName());

} catch (MalformedObjectNameException | InstanceAlreadyExistsException
| MBeanRegistrationException | NotCompliantMBeanException e) {
log.warn("Could not register bean for instance: " + this.getCheckName(),e);
}

return bean;
}


public static boolean isDirectInstance(Map<String, Object> configInstance) {
Object directInstance = configInstance.get(JVM_DIRECT);
return directInstance instanceof Boolean && (Boolean) directInstance;
Expand Down Expand Up @@ -500,7 +453,7 @@ public List<Metric> getMetrics() throws IOException {
? this.initialRefreshBeansPeriod : this.refreshBeansPeriod;

if (isPeriodDue(this.lastRefreshTime, period)) {
log.info("Refreshing bean list for " + this.getCheckName());
log.info("Refreshing bean list");
this.refreshBeansList();
this.getMatchingAttributes();
}
Expand Down Expand Up @@ -532,13 +485,6 @@ public List<Metric> getMetrics() throws IOException {
}
}
}
instanceTelemetryBean.setBeanCount(beans.size());
instanceTelemetryBean.setAttributeCount(matchingAttributes.size());
instanceTelemetryBean.setMetricCount(metrics.size());
log.debug("Updated jmx bean for instance: " + this.getCheckName()
+ " With number of beans = " + instanceTelemetryBean.getBeanCount()
+ " attributes = " + instanceTelemetryBean.getAttributeCount()
+ " metrics = " + instanceTelemetryBean.getMetricCount());
return metrics;
}

Expand Down Expand Up @@ -632,8 +578,7 @@ private void getMatchingAttributes() throws IOException {
serviceNameProvider,
tags,
cassandraAliasing,
emptyDefaultHostname,
normalizeBeanParamTags);
emptyDefaultHostname);
} else if (COMPOSED_TYPES.contains(attributeType)) {
log.debug(
ATTRIBUTE
Expand All @@ -651,8 +596,7 @@ private void getMatchingAttributes() throws IOException {
connection,
serviceNameProvider,
tags,
emptyDefaultHostname,
normalizeBeanParamTags);
emptyDefaultHostname);
} else if (MULTI_TYPES.contains(attributeType)) {
log.debug(
ATTRIBUTE
Expand All @@ -670,8 +614,7 @@ private void getMatchingAttributes() throws IOException {
connection,
serviceNameProvider,
tags,
emptyDefaultHostname,
normalizeBeanParamTags);
emptyDefaultHostname);
} else {
try {
log.debug(
Expand Down Expand Up @@ -830,18 +773,8 @@ public boolean isLimitReached() {
return this.limitReached;
}

private void cleanupTelemetryBean() {
try {
mbs.unregisterMBean(instanceTelemetryBeanName);
log.debug("Successfully unregistered bean for instance: " + this.getCheckName());
} catch (MBeanRegistrationException | InstanceNotFoundException e) {
log.debug("Unable to unregister bean for instance: " + this.getCheckName());
}
}

/** Clean up config and close connection. */
public void cleanUp() {
cleanupTelemetryBean();
this.appConfig = null;
if (connection != null) {
connection.closeConnector();
Expand All @@ -854,7 +787,7 @@ public void cleanUp() {
* */
public synchronized void cleanUpAsync() {
appConfig = null;
cleanupTelemetryBean();

class AsyncCleaner implements Runnable {
Connection conn;

Expand Down
26 changes: 2 additions & 24 deletions src/main/java/org/datadog/jmxfetch/JmxAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public abstract class JmxAttribute {
private List<String> defaultTagsList;
private boolean cassandraAliasing;
protected String checkName;
private boolean normalizeBeanParamTags;

JmxAttribute(
MBeanAttributeInfo attribute,
Expand All @@ -74,8 +73,7 @@ public abstract class JmxAttribute {
ServiceNameProvider serviceNameProvider,
Map<String, String> instanceTags,
boolean cassandraAliasing,
boolean emptyDefaultHostname,
boolean normalizeBeanParamTags) {
boolean emptyDefaultHostname) {
this.attribute = attribute;
this.beanName = beanName;
this.className = className;
Expand All @@ -86,7 +84,6 @@ public abstract class JmxAttribute {
this.cassandraAliasing = cassandraAliasing;
this.checkName = checkName;
this.serviceNameProvider = serviceNameProvider;
this.normalizeBeanParamTags = normalizeBeanParamTags;

// A bean name is formatted like that:
// org.apache.cassandra.db:type=Caches,keyspace=system,cache=HintsColumnFamilyKeyCache
Expand Down Expand Up @@ -194,35 +191,16 @@ private List<String> getBeanParametersList(
return beanTags;
}

/**
* Wrapper for javax.management.ObjectName.unqoute that removes quotes from the bean parameter
* value if possible. If not, it hits the catch block and returns the original parameter.
*/
private String unquote(String beanParameter) {
int valueIndex = beanParameter.indexOf(':') + 1;
try {
return beanParameter.substring(0,valueIndex)
+ ObjectName.unquote(beanParameter.substring(valueIndex));
} catch (IllegalArgumentException e) {
return beanParameter;
}
}

/**
* Sanitize MBean parameter names and values, i.e. - Rename parameter names conflicting with
* existing tags - Remove illegal characters
*/
private List<String> sanitizeParameters(List<String> beanParametersList) {
private static List<String> sanitizeParameters(List<String> beanParametersList) {
List<String> defaultTagsList = new ArrayList<String>(beanParametersList.size());
for (String rawBeanParameter : beanParametersList) {
// Remove `|` characters
String beanParameter = rawBeanParameter.replace("|", "");

// Unquote bean parameters that have been quoted and escaped by ObjectName.quote()
if (normalizeBeanParamTags == true) {
beanParameter = unquote(beanParameter);
}

// 'host' parameter is renamed to 'bean_host'
if (beanParameter.startsWith("host:")) {
defaultTagsList.add("bean_host:" + beanParameter.substring("host:".length()));
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/datadog/jmxfetch/JmxComplexAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public JmxComplexAttribute(
Connection connection,
ServiceNameProvider serviceNameProvider,
Map<String, String> instanceTags,
boolean emptyDefaultHostname,
boolean normalizeBeanParamTags) {
boolean emptyDefaultHostname) {
super(
attribute,
beanName,
Expand All @@ -42,8 +41,7 @@ public JmxComplexAttribute(
serviceNameProvider,
instanceTags,
false,
emptyDefaultHostname,
normalizeBeanParamTags);
emptyDefaultHostname);
}

private void populateSubAttributeList(Object attributeValue) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/datadog/jmxfetch/JmxSimpleAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public JmxSimpleAttribute(
ServiceNameProvider serviceNameProvider,
Map<String, String> instanceTags,
boolean cassandraAliasing,
Boolean emptyDefaultHostname,
Boolean normalizeBeanParamTags) {
Boolean emptyDefaultHostname) {
super(
attribute,
beanName,
Expand All @@ -40,8 +39,7 @@ public JmxSimpleAttribute(
serviceNameProvider,
instanceTags,
cassandraAliasing,
emptyDefaultHostname,
normalizeBeanParamTags);
emptyDefaultHostname);
}

@Override
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/datadog/jmxfetch/JmxSubAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public JmxSubAttribute(
ServiceNameProvider serviceNameProvider,
Map<String, String> instanceTags,
boolean cassandraAliasing,
boolean emptyDefaultHostname,
boolean normalizeBeanParamTags) {
boolean emptyDefaultHostname) {
super(
attribute,
beanName,
Expand All @@ -33,8 +32,7 @@ public JmxSubAttribute(
serviceNameProvider,
instanceTags,
cassandraAliasing,
emptyDefaultHostname,
normalizeBeanParamTags);
emptyDefaultHostname);
}

public Metric getCachedMetric(String name) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/datadog/jmxfetch/JmxTabularAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public JmxTabularAttribute(
Connection connection,
ServiceNameProvider serviceNameProvider,
Map<String, String> instanceTags,
boolean emptyDefaultHostname,
boolean normalizeBeanParamTags) {
boolean emptyDefaultHostname) {
super(
attribute,
beanName,
Expand All @@ -50,8 +49,7 @@ public JmxTabularAttribute(
serviceNameProvider,
instanceTags,
false,
emptyDefaultHostname,
normalizeBeanParamTags);
emptyDefaultHostname);
subAttributeList = new HashMap<String, List<String>>();
}

Expand Down
44 changes: 0 additions & 44 deletions src/main/java/org/datadog/jmxfetch/util/InstanceTelemetry.java

This file was deleted.

This file was deleted.

Loading

0 comments on commit b33e1d3

Please sign in to comment.