Skip to content

Commit 652ab32

Browse files
committed
switch to _ + enhance doc for 2 state
1 parent 6c10e6d commit 652ab32

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

instrumentation/jmx-metrics/javaagent/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ rules:
239239
connector_state:
240240
ok: STARTED
241241
failed: [STOPPED,FAILED]
242-
degraded: '*'
242+
degraded: _
243243
```
244244

245245
For a given value of `port`, let's say `8080` This will capture the `tomcat.connector.state` metric of type `updowncounter` with value `0` or `1` and the `state` metric attribute will have a value in [`ok`,`failed`,`degraded`].
@@ -265,9 +265,22 @@ For other values of `stateName`, we have:
265265

266266
Each state key can be mapped to one or more values of the MBean attribute using:
267267
- a string literal or a string array
268-
- a `*` wildcard to provide default option and avoid enumerating all values.
268+
- a `_` character to provide default option and avoid enumerating all values.
269269

270-
Exactly one wildcard must be present in the mapping to ensure all possible values of the MBean attribute can be mapped to a state key.
270+
Exactly one `_` value must be present in the mapping to ensure all possible values of the MBean attribute can be mapped to a state key.
271+
272+
The default value indicated by `_` does not require a dedicated state key. For example, if we want to have `connector_state` metric attribute with values `on` or `off`, we can use:
273+
```yaml
274+
connector_state:
275+
on: STARTED
276+
off: [STOPPED,FAILED,_]
277+
```
278+
In the particular case where only two values are defined, we can simplify further by explicitly defining one state and rely on default for the other.
279+
```yaml
280+
connector_state:
281+
on: STARTED
282+
off: _
283+
```
271284

272285
### General Syntax
273286

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/yaml/MetricStructure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ abstract class MetricStructure {
4444

4545
private Map<String, Object> metricAttribute;
4646
private StateMapping stateMapping = StateMapping.empty();
47-
private static final String STATE_MAPPING_WILDCARD = "*";
47+
private static final String STATE_MAPPING_DEFAULT = "_";
4848
private String unit;
4949

5050
private MetricInfo.Type metricType;
@@ -68,7 +68,7 @@ public void setUnit(String unit) {
6868

6969
private static void addMappedValue(
7070
StateMapping.Builder builder, String stateValue, String stateKey) {
71-
if (stateValue.equals(STATE_MAPPING_WILDCARD)) {
71+
if (stateValue.equals(STATE_MAPPING_DEFAULT)) {
7272
builder.withDefaultState(stateKey);
7373
} else {
7474
builder.withMappedValue(stateValue, stateKey);

instrumentation/jmx-metrics/library/src/test/java/io/opentelemetry/instrumentation/jmx/engine/RuleParserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void testConf8() throws Exception {
373373
+ " state_attribute: \n" // --> only one state attribute allowed
374374
+ " ok: STARTED\n" // as simple string
375375
+ " failed: [STOPPED,FAILED]\n" // as array of strings
376-
+ " degraded: '*'\n" // wildcard value for default
376+
+ " degraded: _\n" // degraded value for default
377377
+ "";
378378

379379
@Test

0 commit comments

Comments
 (0)