Closed SylvainJuge closed 3 weeks ago
One of the downsides of sending a constant 1
metric value is that from the consumer side we always have to query for the metric without the "state" attribute and then check the actual value of the state attribute to see if it changes, however the metric name + attributes define the metric identity so it is not optimal.
After reflecting a bit more on this issue, I think that having the ability to define "state metrics" would be possible by trying to implement the following with Tomcat as example:
JMX object name: Catalina:type=Connector,port=*
, JMX attribute name stateName
We can capture this as tomcat.connector.count
metric:
port
is mapped 1:1
from JMX Object namestate
will be generated from all the known values of stateName
port
there is one metric with state
for each value of stateName
port
, the metric value will be 1
for when state
matches the current value of stateName
, it will be 0
otherwise.Example if we have a single 8080
port and two values for stateName
: STARTED
and STOPPED
, we have the following metrics reported
stateName
= STARTED
tomcat.connector.count
= 1
, port
= 8080
, state
= STARTED
tomcat.connector.count
= 0
, port
= 8080
, state
= STOPPED
stateName
= STOPPED
tomcat.connector.count
= 0
, port
= 8080
, state
= STARTED
tomcat.connector.count
= 1
, port
= 8080
, state
= STOPPED
The list of values for stateName
must be known in advance, otherwise we can't generate the metric breakdown for values that haven't been seen yet.
stateName
= UNKNOWN
, then consider it as stateName
= STOPPED
)In order to normalize the values that are read from JMX and underlying implementation, we will need to have a way to express a 1:1 mapping for each value, for example:
STARTED -> started
, STOPPED -> stopped
, ...Of course, doing that with YAML syntax could be a challenge, but it does not sound like something impossible.
I just opened a first draft implementation PR for this: https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/12369, as usual, feedback is welcome.
For now, the current implementation of JMX Insights only allows to capture numeric MBean attributes as metrics.
However, it is common to find MBean attributes that expose internal state as a string, boolean or even enum. For example, with Tomcat
Catalina:type=Connector,port=*
MBean where thestateName
attribute (see code) and the string values come from LifeCycleState enum (code).The JMX Gatherer in contrib provides a way to create metrics from non-numeric MBean attributes, but replicating this with YAML seems tricky.
For string attributes, we can already capture them as a metric attribute of another metric, but it has two caveats:
Prometheus exporter has this ability, and I think it would be relevant to add it here as well. When looking at the implementation in this PR for enums, we can see that they use a "filter" on the attribute value to implement this, for example in prometheus configuration:
With this configuration:
kafka_streams_state_running
with value of1
is issued whenstate
=RUNNING
kafka_streams_state_rebalancing
with value of1
is issued whenstate
=REBALANCING
state
value does not match no metric is issuedI think there are a few solutions to implement a similar feature with YAML configuration, which in the case of Tomcat could be something like this for
http.server.tomcat.connector
metric:Here the
value: 1
indicates the metric value will be a constant value of 1 and thebeanattrmap
allows to translate the original values. Thisbeanattrmap
function would support mappingstring
,boolean
andenums
through their string representation.In short, the metric value will be constant, but the attributes of the metric will change over time.
As a simpler version of this, we could also capture the attribute values as-is, in which case the original upper-case values would be preserved with
state: beanattr(state)
As another alternative, we could map using distinct metrics to make it closer to prometheus solution:
Where the
valuematch(XXX,1,0)
function would return0
value when attribute value does not match and1
when it does.Also, the YAML syntax does not allow for duplicate beans mapping.
I have the following questions that I'd like to have feedback on:
0
to cancel the previous1
when state changes ?