Skip to content

Commit c632ea2

Browse files
jmx gatherer: Remove manual exporter flush (#190)
* jmx: Add missing tomcat target system * jmx: tear down gatherer test container * jmx: remove manual flush and rely on `otel.metric.export.interval` property
1 parent 65dcda9 commit c632ea2

File tree

7 files changed

+16
-28
lines changed

7 files changed

+16
-28
lines changed

jmx-metrics/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mutually exclusive with `otel.jmx.groovy.script`. The currently supported target
7373
| [`kafka`](./docs/target-systems/kafka.md) |
7474
| [`kafka-consumer`](./docs/target-systems/kafka-consumer.md) |
7575
| [`kafka-producer`](./docs/target-systems/kafka-producer.md) |
76+
| [`tomcat`](./docs/target-systems/tomcat.md) |
7677

7778
### JMX Query Helpers
7879

@@ -218,7 +219,7 @@ file contents can also be provided via stdin on startup when using `-config -` a
218219
| `otel.jmx.service.url` | **yes** | The service URL for the JMX RMI/JMXMP endpoint (generally of the form `service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi` or `service:jmx:jmxmp://<host>:<port>`).|
219220
| `otel.jmx.groovy.script` | if not using `otel.jmx.target.system` | The path for the desired Groovy script. |
220221
| `otel.jmx.target.system` | if not using `otel.jmx.groovy.script` | A comma-separated list of the supported target applications with built in Groovy scripts. |
221-
| `otel.jmx.interval.milliseconds` | no | How often, in milliseconds, the Groovy script should be run and its resulting metrics exported. 10000 by default. |
222+
| `otel.jmx.interval.milliseconds` | no | How often, in milliseconds, the Groovy script should be run. Value will also be used for `otel.metric.export.interval`, if unset, to control asynchronous updates and metric exporting. 10000 by default. |
222223
| `otel.jmx.username` | no | Username for JMX authentication, if applicable. |
223224
| `otel.jmx.password` | no | Password for JMX authentication, if applicable. |
224225
| `otel.jmx.remote.profile` | no | Supported JMX remote profiles are TLS in combination with SASL profiles: SASL/PLAIN, SASL/DIGEST-MD5 and SASL/CRAM-MD5. Thus valid `jmxRemoteProfiles` values are: `SASL/PLAIN`, `SASL/DIGEST-MD5`, `SASL/CRAM-MD5`, `TLS SASL/PLAIN`, `TLS SASL/DIGEST-MD5` and `TLS SASL/CRAM-MD5`. |

jmx-metrics/src/integrationTest/java/io/opentelemetry/contrib/jmxmetrics/AbstractIntegrationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ void beforeAll() {
104104
@SuppressWarnings("FutureReturnValueIgnored")
105105
void afterAll() {
106106
otlpServer.stop();
107+
scraper.stop();
107108
}
108109

109110
@BeforeEach

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/GroovyRunner.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,6 @@ public void run() {
135135
for (final Script script : scripts) {
136136
script.run();
137137
}
138-
flush();
139-
}
140-
141-
public void flush() {
142-
groovyMetricEnvironment.flush();
143-
}
144-
145-
public void shutdown() {
146-
flush();
147138
}
148139

149140
// Visible for testing

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/JmxConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class JmxConfig {
2020
static final String METRICS_EXPORTER_TYPE = PREFIX + "metrics.exporter";
2121
static final String EXPORTER = PREFIX + "exporter.";
2222

23-
static final String EXPORTER_INTERVAL = PREFIX + "imr.export.interval";
23+
static final String EXPORTER_INTERVAL = PREFIX + "metric.export.interval";
2424

2525
static final String OTLP_ENDPOINT = EXPORTER + "otlp.endpoint";
2626

jmx-metrics/src/main/groovy/io/opentelemetry/contrib/jmxmetrics/JmxMetrics.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public void run() {
5858
private void shutdown() {
5959
logger.info("Shutting down JmxMetrics Groovy runner and exporting final metrics.");
6060
exec.shutdown();
61-
runner.shutdown();
6261
}
6362

6463
private static JmxConfig getConfigFromArgs(final String[] args) {

jmx-metrics/src/test/java/io/opentelemetry/contrib/jmxmetrics/GroovyRunnerTest.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import java.util.Collections;
1313
import java.util.List;
14-
import java.util.concurrent.atomic.AtomicBoolean;
1514
import javax.management.ObjectName;
1615
import org.junit.jupiter.api.Test;
1716
import org.junitpioneer.jupiter.SetSystemProperty;
@@ -28,8 +27,6 @@ void loadTargetScript() throws Exception {
2827

2928
assertThatCode(config::validate).doesNotThrowAnyException();
3029

31-
AtomicBoolean exportCalled = new AtomicBoolean();
32-
3330
JmxClient stub =
3431
new JmxClient(config) {
3532
@Override
@@ -38,20 +35,10 @@ public List<ObjectName> query(ObjectName objectName) {
3835
}
3936
};
4037

41-
GroovyRunner runner =
42-
new GroovyRunner(
43-
config,
44-
stub,
45-
new GroovyMetricEnvironment(config) {
46-
@Override
47-
public void flush() {
48-
exportCalled.set(true);
49-
}
50-
});
38+
GroovyRunner runner = new GroovyRunner(config, stub, new GroovyMetricEnvironment(config));
5139

5240
assertThat(runner.getScripts()).hasSize(1);
5341
runner.run();
54-
assertThat(exportCalled).isTrue();
5542
}
5643

5744
@Test

jmx-metrics/src/test/java/io/opentelemetry/contrib/jmxmetrics/JmxConfigTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1010

1111
import org.junit.jupiter.api.Test;
12+
import org.junitpioneer.jupiter.ClearSystemProperty;
1213
import org.junitpioneer.jupiter.SetSystemProperty;
1314

1415
class JmxConfigTest {
@@ -20,13 +21,12 @@ void staticValues() {
2021
}
2122

2223
@Test
24+
@ClearSystemProperty(key = "otel.metric.export.interval")
2325
void defaultValues() {
2426
JmxConfig config = new JmxConfig();
2527

2628
assertThat(config.serviceUrl).isNull();
27-
;
2829
assertThat(config.groovyScript).isNull();
29-
;
3030
assertThat(config.targetSystem).isEmpty();
3131
assertThat(config.targetSystems).isEmpty();
3232
assertThat(config.intervalMilliseconds).isEqualTo(10000);
@@ -38,6 +38,7 @@ void defaultValues() {
3838
assertThat(config.password).isNull();
3939
assertThat(config.remoteProfile).isNull();
4040
assertThat(config.realm).isNull();
41+
assertThat(config.properties.getProperty("otel.metric.export.interval")).isEqualTo("10000");
4142
}
4243

4344
@Test
@@ -116,4 +117,12 @@ void invalidTargetSystem() {
116117
"[jvm, unavailabletargetsystem] must specify targets from "
117118
+ "[cassandra, jvm, kafka, kafka-consumer, kafka-producer, tomcat]");
118119
}
120+
121+
@Test
122+
@SetSystemProperty(key = "otel.metric.export.interval", value = "123")
123+
void otelMetricExportIntervalRespected() {
124+
JmxConfig config = new JmxConfig();
125+
assertThat(config.intervalMilliseconds).isEqualTo(10000);
126+
assertThat(config.properties.getProperty("otel.metric.export.interval")).isEqualTo("123");
127+
}
119128
}

0 commit comments

Comments
 (0)