Skip to content

Commit 747ec32

Browse files
committed
Merge branch 'main' into jmx-unit-semconv-alignment
2 parents 1cc4080 + 236569e commit 747ec32

File tree

19 files changed

+262
-61
lines changed

19 files changed

+262
-61
lines changed

benchmark-overhead/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("java")
3-
id("com.diffplug.spotless") version "7.0.2"
3+
id("com.diffplug.spotless") version "7.0.3"
44
}
55

66
spotless {

conventions/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
`kotlin-dsl`
33
// When updating, update below in dependencies too
4-
id("com.diffplug.spotless") version "7.0.2"
4+
id("com.diffplug.spotless") version "7.0.3"
55
}
66

77
spotless {
@@ -54,7 +54,7 @@ dependencies {
5454
implementation("org.apache.maven:maven-aether-provider:3.3.9")
5555

5656
// When updating, update above in plugins too
57-
implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.2")
57+
implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.3")
5858
implementation("com.google.guava:guava:33.4.6-jre")
5959
implementation("gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.18")
6060
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.6")

examples/distro/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ buildscript {
1212
}
1313
}
1414
dependencies {
15-
classpath "com.diffplug.spotless:spotless-plugin-gradle:7.0.2"
15+
classpath "com.diffplug.spotless:spotless-plugin-gradle:7.0.3"
1616
classpath "com.gradleup.shadow:shadow-gradle-plugin:8.3.6"
1717
classpath "io.opentelemetry.instrumentation:gradle-plugins:2.15.0-alpha-SNAPSHOT"
1818
}

examples/extension/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
See https://imperceptiblethoughts.com/shadow/ for more details about Shadow plugin.
1212
*/
1313
id "com.gradleup.shadow" version "8.3.6"
14-
id "com.diffplug.spotless" version "7.0.2"
14+
id "com.diffplug.spotless" version "7.0.3"
1515

1616
id "io.opentelemetry.instrumentation.muzzle-generation" version "2.15.0-alpha-SNAPSHOT"
1717
id "io.opentelemetry.instrumentation.muzzle-check" version "2.15.0-alpha-SNAPSHOT"

instrumentation/apache-dubbo-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/OpenTelemetryClientFilter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import org.apache.dubbo.rpc.Invoker;
1212
import org.apache.dubbo.rpc.Result;
1313

14-
@Activate(group = {"consumer"})
14+
@Activate(
15+
group = {"consumer"},
16+
order = -1)
1517
public final class OpenTelemetryClientFilter implements Filter {
1618

1719
private final Filter delegate;

instrumentation/apache-dubbo-2.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/OpenTelemetryServerFilter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import org.apache.dubbo.rpc.Invoker;
1212
import org.apache.dubbo.rpc.Result;
1313

14-
@Activate(group = {"provider"})
14+
@Activate(
15+
group = {"provider"},
16+
order = -1)
1517
public final class OpenTelemetryServerFilter implements Filter {
1618

1719
private final Filter delegate;

instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/OpenTelemetryClientFilter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import org.apache.dubbo.rpc.Invoker;
1313
import org.apache.dubbo.rpc.Result;
1414

15-
@Activate(group = {"consumer"})
15+
@Activate(
16+
group = {"consumer"},
17+
order = -1)
1618
public final class OpenTelemetryClientFilter implements Filter {
1719

1820
private final Filter delegate;

instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/OpenTelemetryServerFilter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import org.apache.dubbo.rpc.Invoker;
1313
import org.apache.dubbo.rpc.Result;
1414

15-
@Activate(group = {"provider"})
15+
@Activate(
16+
group = {"provider"},
17+
order = -1)
1618
public final class OpenTelemetryServerFilter implements Filter {
1719

1820
private final Filter delegate;

instrumentation/jmx-metrics/javaagent/README.md

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ If such a conversion is not available, then an error is reported during JMX metr
320320
Currently available unit conversions:
321321

322322
| `sourceUnit` | `unit` |
323-
|--------------|-------|
324-
| ms | s |
325-
| us | s |
326-
| ns | s |
323+
|--------------|--------|
324+
| ms | s |
325+
| us | s |
326+
| ns | s |
327327

328328
Example of defining unit conversion in yaml file:
329329
```yaml
@@ -341,6 +341,29 @@ rules:
341341
```
342342
`sourceUnit` can also be defined on rule level (see [Making shortcuts](#making-shortcuts))
343343

344+
### Filtering negative values
345+
346+
Sometimes a negative value is returned by the MBean implementation when a metric is not available or not supported.
347+
For example, [`OperatingSystemMXBean.getProcessCpuLoad`](https://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html#getProcessCpuLoad()) can return a negative value.
348+
349+
In this case, it is recommended to filter out the negative values by setting the `dropNegativeValues` metric (or rule) property to `true`, it is set to `false` by default.
350+
351+
```yaml
352+
rules:
353+
- bean: java.lang:type=OperatingSystem
354+
# can also be set at rule-level (with lower priority)
355+
dropNegativeValues: false
356+
mapping:
357+
# jvm.cpu.recent_utilization
358+
ProcessCpuLoad:
359+
metric: jvm.cpu.recent_utilization
360+
type: gauge
361+
unit: '1'
362+
# setting dropNegativeValues at metric level has priority over rule level.
363+
dropNegativeValues: true
364+
desc: Recent CPU utilization for the process as reported by the JVM.
365+
```
366+
344367
### General Syntax
345368

346369
Here is the general description of the accepted configuration file syntax. The whole contents of the file is case-sensitive, with exception for `type` as described in the table below.
@@ -356,12 +379,14 @@ rules: # start of list of configuration rules
356379
prefix: <METRIC_NAME_PREFIX> # optional, useful for avoiding specifying metric names below
357380
unit: <UNIT> # optional, redefines the default unit for the whole rule
358381
type: <TYPE> # optional, redefines the default type for the whole rule
382+
dropNegativeValues: <BOOL> # optional, redefines if negative values are dropped for the whole rule
359383
mapping:
360384
<BEANATTR1>: # an MBean attribute name defining the metric value
361385
metric: <METRIC_NAME1> # metric name will be <METRIC_NAME_PREFIX><METRIC_NAME1>
362386
type: <TYPE> # optional, the default type is gauge
363387
desc: <DESCRIPTION1> # optional
364388
unit: <UNIT1> # optional
389+
dropNegativeValues: <BOOL> # optional, defines if negative values are dropped for the metric
365390
metricAttribute: # optional, will be used in addition to the shared metric attributes above
366391
<ATTRIBUTE3>: const(<STR>) # direct value for the metric attribute
367392
<BEANATTR2>: # use a.b to get access into CompositeData
@@ -381,19 +406,20 @@ rules: # start of list of configuration rules
381406

382407
The following table explains the used terms with more details.
383408

384-
| Syntactic Element | Description |
385-
| ---------------- | --------------- |
386-
| OBJECTNAME | A syntactically valid string representing an ObjectName (see [ObjectName constructor](https://docs.oracle.com/javase/8/docs/api/javax/management/ObjectName.html#ObjectName-java.lang.String-)). |
387-
| ATTRIBUTE | Any well-formed string that can be used as a metric [attribute](https://opentelemetry.io/docs/reference/specification/common/#attribute) key. |
388-
| ATTR | A non-empty string used as a name of the MBean attribute. The MBean attribute value must be a String, otherwise the specified metric attribute will not be used. |
389-
| PARAM | A non-empty string used as a property key in the ObjectName identifying the MBean which provides the metric value. If the ObjectName does not have a property with the given key, the specified metric attribute will not be used. |
390-
| METRIC_NAME_PREFIX | Any non-empty string which will be prepended to the specified metric (instrument) names. |
391-
| METRIC_NAME | Any non-empty string. The string, prefixed by the optional prefix (see above) must satisfy [instrument naming rule](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-naming-rule). |
392-
| TYPE | One of `counter`, `updowncounter`, or `gauge`. The default is `gauge`. This value is case insensitive. |
393-
| DESCRIPTION | Any string to be used as human-readable [description](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-description) of the metric. If the description is not provided by the rule, an attempt will be made to extract one automatically from the corresponding MBean. |
394-
| UNIT | A string identifying the [unit](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-unit) of measurements reported by the metric. Enclose the string in single or double quotes if using unit annotations. |
395-
| STR | Any string to be used directly as the metric attribute value. |
396-
| BEANATTR | A non-empty string representing the MBean attribute defining the metric value. The attribute value must be a number. Special dot-notation _attributeName.itemName_ can be used to access numerical items within attributes of [CompositeType](https://docs.oracle.com/javase/8/docs/api/javax/management/openmbean/CompositeType.html). If a dot happens to be an integral part of the MBean attribute name, it must be escaped by backslash (`\`). |
409+
| Syntactic Element | Description |
410+
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
411+
| OBJECTNAME | A syntactically valid string representing an ObjectName (see [ObjectName constructor](https://docs.oracle.com/javase/8/docs/api/javax/management/ObjectName.html#ObjectName-java.lang.String-)). |
412+
| ATTRIBUTE | Any well-formed string that can be used as a metric [attribute](https://opentelemetry.io/docs/reference/specification/common/#attribute) key. |
413+
| ATTR | A non-empty string used as a name of the MBean attribute. The MBean attribute value must be a String, otherwise the specified metric attribute will not be used. |
414+
| PARAM | A non-empty string used as a property key in the ObjectName identifying the MBean which provides the metric value. If the ObjectName does not have a property with the given key, the specified metric attribute will not be used. |
415+
| METRIC_NAME_PREFIX | Any non-empty string which will be prepended to the specified metric (instrument) names. |
416+
| METRIC_NAME | Any non-empty string. The string, prefixed by the optional prefix (see above) must satisfy [instrument naming rule](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-naming-rule). |
417+
| TYPE | One of `counter`, `updowncounter`, or `gauge`. The default is `gauge`. This value is case insensitive. |
418+
| DESCRIPTION | Any string to be used as human-readable [description](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-description) of the metric. If the description is not provided by the rule, an attempt will be made to extract one automatically from the corresponding MBean. |
419+
| UNIT | A string identifying the [unit](https://opentelemetry.io/docs/reference/specification/metrics/api/#instrument-unit) of measurements reported by the metric. Enclose the string in single or double quotes if using unit annotations. |
420+
| STR | Any string to be used directly as the metric attribute value. |
421+
| BEANATTR | A non-empty string representing the MBean attribute defining the metric value. The attribute value must be a number. Special dot-notation _attributeName.itemName_ can be used to access numerical items within attributes of [CompositeType](https://docs.oracle.com/javase/8/docs/api/javax/management/openmbean/CompositeType.html). If a dot happens to be an integral part of the MBean attribute name, it must be escaped by backslash (`\`). |
422+
| BOOL | A boolean value, either `true` or `false` |
397423

398424
## Assumptions and Limitations
399425

instrumentation/jmx-metrics/library/src/main/java/io/opentelemetry/instrumentation/jmx/engine/BeanAttributeExtractor.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static java.util.logging.Level.FINE;
99
import static java.util.logging.Level.INFO;
1010

11+
import io.opentelemetry.instrumentation.jmx.yaml.StateMapping;
1112
import java.util.ArrayList;
1213
import java.util.List;
1314
import java.util.logging.Level;
@@ -103,7 +104,7 @@ private static void verifyAndAddNameSegment(List<String> segments, StringBuilder
103104
segments.add(newSegment);
104105
}
105106

106-
public BeanAttributeExtractor(String baseName, String... nameChain) {
107+
private BeanAttributeExtractor(String baseName, String... nameChain) {
107108
if (baseName == null || nameChain == null) {
108109
throw new IllegalArgumentException("null argument for BeanAttributeExtractor");
109110
}
@@ -287,4 +288,49 @@ private String extractStringAttribute(MBeanServerConnection connection, ObjectNa
287288
}
288289
return null;
289290
}
291+
292+
/**
293+
* Provides a bean attribute extractor to filter-out negative values by replacing them with
294+
* {@literal null}.
295+
*
296+
* @param extractor original extractor
297+
* @return equivalent extractor filtering-out negative values
298+
*/
299+
public static BeanAttributeExtractor filterNegativeValues(BeanAttributeExtractor extractor) {
300+
return new BeanAttributeExtractor(extractor.baseName, extractor.nameChain) {
301+
@Nullable
302+
@Override
303+
protected Number extractNumericalAttribute(
304+
MBeanServerConnection connection, ObjectName objectName) {
305+
Number v = super.extractNumericalAttribute(connection, objectName);
306+
if (v instanceof Long || v instanceof Integer || v instanceof Short || v instanceof Byte) {
307+
return v.longValue() < 0 ? null : v;
308+
} else if (v instanceof Double || v instanceof Float) {
309+
return v.doubleValue() < 0 ? null : v;
310+
}
311+
return v;
312+
}
313+
};
314+
}
315+
316+
public static BeanAttributeExtractor forStateMetric(
317+
BeanAttributeExtractor extractor, String key, StateMapping stateMapping) {
318+
return new BeanAttributeExtractor(extractor.baseName, extractor.nameChain) {
319+
@Override
320+
protected Object getSampleValue(MBeanServerConnection connection, ObjectName objectName) {
321+
// metric actual type is sampled in the discovery process, so we have to
322+
// make this extractor as extracting integers.
323+
return 0;
324+
}
325+
326+
@Nullable
327+
@Override
328+
protected Number extractNumericalAttribute(
329+
MBeanServerConnection connection, ObjectName objectName) {
330+
String rawStateValue = extractor.extractValue(connection, objectName);
331+
String mappedStateValue = stateMapping.getStateValue(rawStateValue);
332+
return key.equals(mappedStateValue) ? 1 : 0;
333+
}
334+
};
335+
}
290336
}

0 commit comments

Comments
 (0)