- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1k
jmx state metrics #12369
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
jmx state metrics #12369
Changes from all commits
9272bfe
              6f20784
              d1a195b
              3f2f151
              5973b01
              4fd10aa
              6155206
              af37bb4
              6551200
              376acc5
              679c460
              e5ff7c5
              8e73f10
              e9e8e83
              550b003
              1bb4302
              ebf58ff
              6c10e6d
              652ab32
              e24b9ae
              2698be3
              e4b9fe5
              111c26b
              96bb6cc
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -151,7 +151,7 @@ AttributeInfo getAttributeInfo(MBeanServerConnection connection, ObjectName obje | |
|  | ||
| // Verify correctness of configuration by attempting to extract the metric value. | ||
| // The value will be discarded, but its type will be checked. | ||
| Object sampleValue = extractAttributeValue(connection, objectName, logger); | ||
| Object sampleValue = getSampleValue(connection, objectName); | ||
|  | ||
| // Only numbers can be used to generate metric values | ||
| if (sampleValue instanceof Number) { | ||
|  | @@ -194,6 +194,11 @@ AttributeInfo getAttributeInfo(MBeanServerConnection connection, ObjectName obje | |
| return null; | ||
| } | ||
|  | ||
| @Nullable | ||
| protected Object getSampleValue(MBeanServerConnection connection, ObjectName objectName) { | ||
| return extractAttributeValue(connection, objectName, logger); | ||
| } | ||
| 
      Comment on lines
    
      +198
     to 
      +200
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] this allows to bypass the sample value check for the "artificial" attribute value that we need for the state metric. | ||
|  | ||
| /** | ||
| * Extracts the specified attribute value. In case the value is a CompositeData, drills down into | ||
| * it to find the correct singleton value (usually a Number or a String). | ||
|  | @@ -203,7 +208,7 @@ AttributeInfo getAttributeInfo(MBeanServerConnection connection, ObjectName obje | |
| * pattern | ||
| * @param logger the logger to use, may be null. Typically we want to log any issues with the | ||
| * attributes during MBean discovery, but once the attribute is successfully detected and | ||
| * confirmed to be eligble for metric evaluation, any further attribute extraction | ||
| * confirmed to be eligible for metric evaluation, any further attribute extraction | ||
| * malfunctions will be silent to avoid flooding the log. | ||
| * @return the attribute value, if found, or {@literal null} if an error occurred | ||
| */ | ||
|  | @@ -253,7 +258,8 @@ private Object extractAttributeValue(MBeanServerConnection connection, ObjectNam | |
| } | ||
|  | ||
| @Nullable | ||
| Number extractNumericalAttribute(MBeanServerConnection connection, ObjectName objectName) { | ||
| protected Number extractNumericalAttribute( | ||
| MBeanServerConnection connection, ObjectName objectName) { | ||
| Object value = extractAttributeValue(connection, objectName); | ||
| if (value instanceof Number) { | ||
| return (Number) value; | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -120,6 +120,13 @@ void enrollExtractor( | |
| } | ||
| logger.log(INFO, "Created Gauge for {0}", metricName); | ||
| } | ||
| break; | ||
| // CHECKSTYLE:OFF | ||
| case STATE: | ||
| { | ||
| // CHECKSTYLE:ON | ||
| throw new IllegalStateException("state metrics should not be registered"); | ||
| } | ||
| 
      Comment on lines
    
      +125
     to 
      +129
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] this is needed to have the switch statement cover all cases. | ||
| } | ||
| } | ||
|  | ||
|  | @@ -173,9 +180,8 @@ static Consumer<ObservableLongMeasurement> longTypeCallback(MetricExtractor extr | |
| */ | ||
| static Attributes createMetricAttributes( | ||
| MBeanServerConnection connection, ObjectName objectName, MetricExtractor extractor) { | ||
| MetricAttribute[] metricAttributes = extractor.getAttributes(); | ||
| AttributesBuilder attrBuilder = Attributes.builder(); | ||
| for (MetricAttribute metricAttribute : metricAttributes) { | ||
| for (MetricAttribute metricAttribute : extractor.getAttributes()) { | ||
| String attributeValue = metricAttribute.acquireAttributeValue(connection, objectName); | ||
| if (attributeValue != null) { | ||
| attrBuilder = attrBuilder.put(metricAttribute.getAttributeName(), attributeValue); | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.