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

JMX Metric Insight #6573

Merged
merged 21 commits into from
Nov 16, 2022
Merged

JMX Metric Insight #6573

merged 21 commits into from
Nov 16, 2022

Conversation

PeterF778
Copy link
Contributor

Solving #6131 (JMX Support).

@PeterF778 PeterF778 requested a review from a team as a code owner September 9, 2022 22:54
Solving  open-telemetry#6131 (JMX Support).
Correcting a typo in a comment.
Using the latest version of snakeyaml.
Version 1.30 had this vulnerability https://nvd.nist.gov/vuln/detail/CVE-2022-25857.
@PeterF778
Copy link
Contributor Author

Thank you @jack-berg for the review and your comments!

@PeterF778
Copy link
Contributor Author

Thank you, @trask, for the review. I'm working on an update for the PR, I should have it ready later this week.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

@PeterF778 thanks for your patience with the slow reviews

instrumentation/jmx/javaagent/README.md Outdated Show resolved Hide resolved
instrumentation/jmx/javaagent/README.md Outdated Show resolved Hide resolved
instrumentation/jmx/javaagent/README.md Outdated Show resolved Hide resolved
instrumentation/jmx/javaagent/README.md Outdated Show resolved Hide resolved
instrumentation/jmx/javaagent/README.md Outdated Show resolved Hide resolved
instrumentation/jmx/javaagent/README.md Outdated Show resolved Hide resolved
instrumentation/jmx/javaagent/README.md Outdated Show resolved Hide resolved
instrumentation/jmx/javaagent/README.md Outdated Show resolved Hide resolved
Renaming module 'jmx' to 'jmx-metrics'.
Changing the syntax of the metric attributes retrieved from Mbean attributes.
Editing docs and comments for better readability.
@PeterF778
Copy link
Contributor Author

My last commit changes the documentation for the YAML syntax, replacing label with attribute.
Once the new syntax is agreed upon, I'll change the code and the built-in metric rules. Right now they are out-of-sync with the documentation.

@trask
Copy link
Member

trask commented Oct 20, 2022

I played around with a few possible changes to the yaml structure, with questionable results.

1. Changing mapping to metric

e.g., change

    mapping:
      Usage.used:
        metric: my.own.jvm.memory.pool.used
        type: updowncounter
        desc: Pool memory currently used
        unit: By

to

    metric:
      Usage.used:
        name: my.own.jvm.memory.pool.used
        type: updowncounter
        desc: Pool memory currently used
        unit: By

Reason: more explicit name for what the things under it represent.

My take: I kind of like this, though maybe mapping is better given the considerations below in # 2 (?)

2 Change attribute to metricAttribute

e.g., change

    attribute:
      pool: param(name)
      type: beanattr(Type)

to

    metricAttribute:
      pool: param(name)
      type: beanattr(Type)

Reason: more explicit name for what the things under it represent, especially given the confusion of bean attribute vs metric attribute.

My take: I kind of like this (but probably makes most sense with # 1 above also)

3 Changing mapping from a map to a list

e.g., change

    mapping:
      Usage.used:
        metric: my.own.jvm.memory.pool.used
        type: updowncounter
        desc: Pool memory currently used
        unit: By

to

    metrics:
      - beanAttr: Usage.used
        name: my.own.jvm.memory.pool.used
        type: updowncounter
        desc: Pool memory currently used
        unit: By

Reason: give names to the beanAttr field, instead of having it be "anonymous" key for the map.

My take: I don't think this helps. We are mapping from mbeans to otel metrics in this file, so I think it is not too confusing for the key to be the mbean attribute.

4 Change attribute from a map to a list

e.g., change

    attribute:
      pool: param(name)
      type: beanattr(Type)

to

    metricAttributes:
      - name: pool
        value: param(name)
      - name: type
        value: beanattr(Type)

Reason: give names to the attribute name field, instead of having it be "anonymous" key for the map.

My take: I don't think this helps.

@PeterF778
Copy link
Contributor Author

Thank you @trask for your experiments and suggestions. They all have merits, and I'll address them in the increasing order of my subjective agreement with them.

Re: 3 Changing mapping from a map to a list

It looks good, and is readable, but it does not allow a shortcut notations as demonstrated in the section Making shortcuts, with simplified one-line mapping from MBean attributes to metrics. I believe many users would appreciate such simplicity, even if only for experimenting with the available MBeans.

Re: 1. Changing mapping to metric

I think the key to understanding the essence of the proposed yaml schema for the metric rules is the realization that they provide a mapping from MBean attributes to OTEL metrics. Looking at

metric:
      Usage.used:
        name: my.own.jvm.memory.pool.used
        type: updowncounter
        desc: Pool memory currently used
        unit: By

one does not necessarily see that this is a mapping. It looks like Usage.used is a part of a metric or a metric definition name. In reality, the metric definition starts only below Usage.used, so saying metric above it can be confusing, IMHO.

On the other hand, the originally proposed schema does not say that the anonymous key is an MBean attribute, but I thought it was an acceptable sacrifice to achieve that one-line mappings mentioned above. It did say mapping and metric though, even if the latter is optional.

Re: 4 Change attribute from a map to a list

Modeling metric attributes as a list is a common mental shortcut, but they are not really a list of pairs (name, value), but a mapping from names to values. A nuance for some, I know ...

BTW, point 3 has the same minor flaw.

Also I believe that in most cases there will be just one element in such a metric attribute list. Many of the metrics we encountered in our metric modeling so far follow a pattern in which a rule has one metric attribute defined globally (for all MBean attributes) and one specific to each metric.

Re: 2 Change attribute to metricAttribute

It is longer than I would like. We went from tag to label and then to attribute, but if it clears potential confusion, I'm fine with it.

Please let me know your thoughts on the above. Thanks!

@trask
Copy link
Member

trask commented Oct 26, 2022

Re: 1. Changing mapping to metric

I think the key to understanding the essence of the proposed yaml schema for the metric rules is the realization that they provide a mapping from MBean attributes to OTEL metrics. Looking at

👍

and I think eliminates 3. Changing mapping from a map to a list as well

I think that just leaves the attributes section to discuss a bit further.

One additional thought about the current attribute section is that while the mapping section is a mapping from MBean attributes to OTel metrics, the attribute map goes in the opposite direction, from OTel to MBean.

Interestingly, I find the attribute section pretty clear when its under the mapping section, since at that point we're talking about how to map the thing to OTel, so the context makes it clear (to me at least) that we're talking about how to populate otel attributes.

The top-level attribute section doesn't read as clearly for me though, since I'm thinking mbean, and so I'm thinking mbean attribute, and then thinking the attribute key is an mbean attribute name instead of an otel attribute name:

  - bean: kafka.streams:type=stream-thread-metrics,thread-id=*
    attribute:
      threadId: param(thread-id)

any other thoughts for making this part clearer?

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 3, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

*
* <p>Objects of this class are immutable.
*/
public class MetricBanner {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not following the association with the word Banner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The class encapsulates metric properties which help identify/explain it to end users via a hypothetical UI, before looking at the metric values or other technical details. They represent the facet of the metric which will most likely be looked at first when browsing a list of metrics. Other possible names considered were MetricTitle or MetricManifest. What name would you propose?

Copy link
Member

Choose a reason for hiding this comment

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

maybe MetricInfo?

private final BeanPack beans;

// Describes how to get the metric values and their attributes, and how to report them
private final MetricExtractor[] metricExtractors;
Copy link
Member

Choose a reason for hiding this comment

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

we typically use List<> over array unless its super perf sensitive, or dealing with an inherently array-based underlying api

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The constructors for MetricDef and a number of other classes take varargs which are translated directly to arrays. And the varargs are there to make the direct access to those classes easier when attempting to hard-code some JMX rules - with the examples of that missing from the first PR.

private final BeanAttributeExtractor attributeExtractor;

// Defines the Measurement attributes to be used when reporting the metric value.
private final MetricAttribute[] attributes;
Copy link
Member

Choose a reason for hiding this comment

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

similar for List over array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the same case - the constructor uses varargs, so internal representation as array is a natural fit.

*
* <p>Objects of this class are immutable.
*/
public class MetricBanner {
Copy link
Member

Choose a reason for hiding this comment

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

maybe MetricInfo?

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

Thanks @PeterF778, this is a great addition!

@trask trask merged commit 4db65b6 into open-telemetry:main Nov 16, 2022
@svrnm
Copy link
Member

svrnm commented Nov 16, 2022

Wow! Amazing to see this merged, thank you @PeterF778 & @trask !

@PeterF778 PeterF778 mentioned this pull request Nov 17, 2022
@tylerbenson
Copy link
Member

@PeterF778 I assume that thread/memory metrics aren't given a "target" is because they're already covered in runtime-metrics. I suggest mentioning this in the readme to make it more clear.

@PeterF778
Copy link
Contributor Author

@PeterF778 I assume that thread/memory metrics aren't given a "target" is because they're already covered in runtime-metrics. I suggest mentioning this in the readme to make it more clear.

Yes, several JVM metrics (threads/memory/GC) as well as other types of metrics are covered independently by the agent. Where in the readme file would you suggest putting a note about it?


To control the time interval between MBean detection attempts, one can use the `otel.jmx.discovery.delay` property, which defines the number of milliseconds to elapse between the first and the next detection cycle. JMX Metric Insight may dynamically adjust the time interval between further attempts, but it guarantees that the MBean discovery will run perpetually.

## Predefined metrics
Copy link
Member

Choose a reason for hiding this comment

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

@PeterF778 this section is where I would suggest adding a reference/link to the runtime metrics, otherwise it seems like an oversight for people that are looking for jmx memory metrics but don't know that runtime metrics are separate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I see your point. Could you please create an issue (https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues) for this so it gets tracked?

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.

None yet

6 participants