-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for HTTPServer's SampleNameFilter
Signed-off-by: Davi Arnaut <[email protected]>
- Loading branch information
Showing
8 changed files
with
275 additions
and
0 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
.../java/io/prometheus/jmx/test/http/sampleNameFilter/SampleNameFilterConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (C) 2024 The Prometheus jmx_exporter Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.prometheus.jmx.test.http.sampleNameFilter; | ||
|
||
import static io.prometheus.jmx.test.support.MetricsAssertions.assertThatMetricIn; | ||
import static io.prometheus.jmx.test.support.RequestResponseAssertions.assertThatResponseForRequest; | ||
|
||
import io.prometheus.jmx.test.BaseTest; | ||
import io.prometheus.jmx.test.Metric; | ||
import io.prometheus.jmx.test.MetricsParser; | ||
import io.prometheus.jmx.test.Mode; | ||
import io.prometheus.jmx.test.support.ContentConsumer; | ||
import io.prometheus.jmx.test.support.HealthyRequest; | ||
import io.prometheus.jmx.test.support.HealthyResponse; | ||
import io.prometheus.jmx.test.support.MetricsRequest; | ||
import io.prometheus.jmx.test.support.MetricsResponse; | ||
import io.prometheus.jmx.test.support.OpenMetricsRequest; | ||
import io.prometheus.jmx.test.support.OpenMetricsResponse; | ||
import io.prometheus.jmx.test.support.PrometheusMetricsRequest; | ||
import io.prometheus.jmx.test.support.PrometheusMetricsResponse; | ||
import java.util.Collection; | ||
import org.antublue.test.engine.api.TestEngine; | ||
|
||
public class SampleNameFilterConfigurationTest extends BaseTest implements ContentConsumer { | ||
|
||
@TestEngine.Test | ||
public void testHealthy() throws InterruptedException { | ||
assertThatResponseForRequest(new HealthyRequest(testState.httpClient())) | ||
.isSuperset(HealthyResponse.RESULT_200); | ||
} | ||
|
||
@TestEngine.Test | ||
public void testMetrics() { | ||
assertThatResponseForRequest(new MetricsRequest(testState.httpClient())) | ||
.isSuperset(MetricsResponse.RESULT_200) | ||
.dispatch(this); | ||
} | ||
|
||
@TestEngine.Test | ||
public void testMetricsOpenMetricsFormat() { | ||
assertThatResponseForRequest(new OpenMetricsRequest(testState.httpClient())) | ||
.isSuperset(OpenMetricsResponse.RESULT_200) | ||
.dispatch(this); | ||
} | ||
|
||
@TestEngine.Test | ||
public void testMetricsPrometheusFormat() { | ||
assertThatResponseForRequest(new PrometheusMetricsRequest(testState.httpClient())) | ||
.isSuperset(PrometheusMetricsResponse.RESULT_200) | ||
.dispatch(this); | ||
} | ||
|
||
@Override | ||
public void accept(String content) { | ||
Collection<Metric> metrics = MetricsParser.parse(content); | ||
|
||
String buildInfoName = | ||
testArgument.mode() == Mode.JavaAgent | ||
? "jmx_prometheus_javaagent" | ||
: "jmx_prometheus_httpserver"; | ||
|
||
assertThatMetricIn(metrics) | ||
.withName("jmx_exporter_build_info") | ||
.withLabel("name", buildInfoName) | ||
.exists(); | ||
|
||
assertThatMetricIn(metrics) | ||
.withName("java_lang_Memory_NonHeapMemoryUsage_committed") | ||
.exists(); | ||
|
||
assertThatMetricIn(metrics) | ||
.withName("io_prometheus_jmx_tabularData_Server_1_Disk_Usage_Table_size") | ||
.withLabel("source", "/dev/sda1") | ||
.withValue(7.516192768E9) | ||
.exists(); | ||
|
||
assertThatMetricIn(metrics) | ||
.withName("io_prometheus_jmx_tabularData_Server_2_Disk_Usage_Table_pcent") | ||
.withLabel("source", "/dev/sda2") | ||
.withValue(0.8) | ||
.exists(); | ||
|
||
assertThatMetricIn(metrics).withName("jvm_threads_state").doesNotExist(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...jmx/test/http/sampleNameFilter/SampleNameFilterConfigurationTest/JavaAgent/application.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
java \ | ||
-Xmx128M \ | ||
-javaagent:jmx_prometheus_javaagent.jar=8888:exporter.yaml \ | ||
-jar jmx_example_application.jar |
6 changes: 6 additions & 0 deletions
6
.../jmx/test/http/sampleNameFilter/SampleNameFilterConfigurationTest/JavaAgent/exporter.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
httpServer: | ||
sampleNameFilter: | ||
name-must-not-be-equal-to: | ||
- jvm_threads_state | ||
rules: | ||
- pattern: ".*" |
13 changes: 13 additions & 0 deletions
13
...mx/test/http/sampleNameFilter/SampleNameFilterConfigurationTest/Standalone/application.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
java \ | ||
-Xmx128M \ | ||
-Dcom.sun.management.jmxremote=true \ | ||
-Dcom.sun.management.jmxremote.authenticate=false \ | ||
-Dcom.sun.management.jmxremote.local.only=false \ | ||
-Dcom.sun.management.jmxremote.port=9999 \ | ||
-Dcom.sun.management.jmxremote.registry.ssl=false \ | ||
-Dcom.sun.management.jmxremote.rmi.port=9999 \ | ||
-Dcom.sun.management.jmxremote.ssl.need.client.auth=false \ | ||
-Dcom.sun.management.jmxremote.ssl=false \ | ||
-jar jmx_example_application.jar |
5 changes: 5 additions & 0 deletions
5
...s/jmx/test/http/sampleNameFilter/SampleNameFilterConfigurationTest/Standalone/exporter.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
java \ | ||
-Xmx128M \ | ||
-jar jmx_prometheus_httpserver.jar 8888 exporter.yaml |
7 changes: 7 additions & 0 deletions
7
...jmx/test/http/sampleNameFilter/SampleNameFilterConfigurationTest/Standalone/exporter.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
httpServer: | ||
sampleNameFilter: | ||
name-must-not-be-equal-to: | ||
- jvm_threads_state | ||
hostPort: application:9999 | ||
rules: | ||
- pattern: ".*" |
56 changes: 56 additions & 0 deletions
56
...heus_common/src/main/java/io/prometheus/jmx/common/configuration/ConvertToStringList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2023 The Prometheus jmx_exporter Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.prometheus.jmx.common.configuration; | ||
|
||
import io.prometheus.jmx.common.util.Precondition; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public class ConvertToStringList implements Function<Object, List<String>> { | ||
|
||
private final Supplier<? extends RuntimeException> supplier; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param supplier supplier | ||
*/ | ||
public ConvertToStringList(Supplier<? extends RuntimeException> supplier) { | ||
Precondition.notNull(supplier); | ||
this.supplier = supplier; | ||
} | ||
|
||
/** | ||
* Method to apply a function | ||
* | ||
* @param value value | ||
* @return the return value | ||
*/ | ||
@Override | ||
public List<String> apply(Object value) { | ||
if (value == null) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
try { | ||
return (List<String>) value; | ||
} catch (Throwable t) { | ||
throw supplier.get(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters