Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
* Restore compatibility with Java 7 - {pull}3657[#3657]
* Avoid `ClassCastException` and issue warning when trying to use otel span links - {pull}3672[#3672]
* Avoid `NullPointerException` with runtime attach API and invalid map entries - {pull}3712[#3712]
* Enhance invalid state JMX metrics handling - {pull}3713[#3713]
* Skips using NOFOLLOW_LINKS file open option when running on z/OS as it's unsupported there - {pull}3722[#3722]

[float]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.RuntimeMBeanException;
import javax.management.MBeanException;
import javax.management.ReflectionException;
import javax.management.openmbean.CompositeData;
import javax.management.relation.MBeanServerNotificationFilter;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -367,31 +369,39 @@ private void addJmxMetricRegistration(final JmxMetric jmxMetric, List<JmxMetricR
MBeanInfo info = server.getMBeanInfo(objectName);
MBeanAttributeInfo[] attrInfo = info.getAttributes();
for (MBeanAttributeInfo attr : attrInfo) {
try {
final Object value = server.getAttribute(objectName, attr.getName());
addJmxMetricRegistration(jmxMetric, registrations, objectName, value, attribute, attr.getName(), metricPrepend);
} catch (AttributeNotFoundException e) {
logger.warn("Can't create metric '{}' because attribute '{}' could not be found", jmxMetric, attribute.getJmxAttributeName());
} catch (RuntimeMBeanException e) {
if (e.getCause() instanceof UnsupportedOperationException) {
//ignore this attribute
} else {
throw e;
}
}
String attributeName = attr.getName();
tryAddJmxMetric(jmxMetric, registrations, server, attribute, objectName, attributeName, metricPrepend);
}
} else {
final Object value = server.getAttribute(objectName, attribute.getJmxAttributeName());
try {
addJmxMetricRegistration(jmxMetric, registrations, objectName, value, attribute, attribute.getJmxAttributeName(), null);
} catch (AttributeNotFoundException e) {
logger.warn("Can't create metric '{}' because attribute '{}' could not be found", jmxMetric, attribute.getJmxAttributeName());
}
String attributeName = attribute.getJmxAttributeName();
tryAddJmxMetric(jmxMetric, registrations, server, attribute, objectName, attributeName, null);
}
}
}
}

private void tryAddJmxMetric(JmxMetric jmxMetric,
List<JmxMetricRegistration> registrations,
MBeanServer server,
JmxMetric.Attribute attribute,
ObjectName objectName,
String attributeName,
@Nullable String metricPrepend) throws MBeanException, InstanceNotFoundException, ReflectionException {

try {
Object value = server.getAttribute(objectName, attributeName);
addJmxMetricRegistration(jmxMetric, registrations, objectName, value, attribute, attributeName, metricPrepend);
} catch (AttributeNotFoundException e) {
logger.warn("Can't create metric '{}' because attribute '{}' could not be found", jmxMetric, attributeName);
} catch (RuntimeMBeanException e) {
if (e.getCause() instanceof UnsupportedOperationException) {
// silently ignore this attribute, won't retry as it's not a transient runtime exception
} else {
throw e;
}
}
}

private static boolean isWildcard(JmxMetric.Attribute attribute) {
return "*".equals(attribute.getJmxAttributeName());
}
Expand Down Expand Up @@ -486,7 +496,7 @@ public double get() {
value = ((Number) ((CompositeData) server.getAttribute(objectName, jmxAttribute)).get(compositeDataKey)).doubleValue();
}
return value;
} catch (InstanceNotFoundException | AttributeNotFoundException e) {
} catch (InstanceNotFoundException | AttributeNotFoundException | RuntimeMBeanException e) {
if (unsubscribeOnError) {
unregister(tracer);
}
Expand Down