Skip to content

Commit

Permalink
Refactored integration tests to get the build info name from a common…
Browse files Browse the repository at this point in the history
… location (#1094)

Signed-off-by: dhoard <doug.hoard@gmail.com>
  • Loading branch information
dhoard authored Dec 10, 2024
1 parent e4a4f45 commit 41540dc
Show file tree
Hide file tree
Showing 27 changed files with 54 additions and 91 deletions.
2 changes: 1 addition & 1 deletion docs/content/1.1.0/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "JMX Exporter 1.1.0"
weight: 1
weight: 2
geekdocCollapseSection: true
---

Expand Down
2 changes: 1 addition & 1 deletion docs/content/older-versions/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Versions < 1.1.0"
weight: 2
weight: 100
---

Documentation for previous JMX Exporter versions can be found in associated release branches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public static Collection<Metric> parseCollection(HttpResponse httpResponse) {
* @return a Collection of Metrics
*/
private static Collection<Metric> parseTextMetrics(String body) {
// System.out.println("DEBUG parseTextMetrics()");

Collection<Metric> metrics = new ArrayList<>();

try (LineReader lineReader = new LineReader(new StringReader(body))) {
Expand Down Expand Up @@ -124,8 +122,6 @@ private static Collection<Metric> parseTextMetrics(String body) {
}

private static Collection<Metric> parseOpenMetricsTextMetrics(String body) {
// System.out.println("DEBUG parseOpenMetricsTextMetrics()");

Collection<Metric> metrics = new ArrayList<>();

String line;
Expand All @@ -141,8 +137,6 @@ private static Collection<Metric> parseOpenMetricsTextMetrics(String body) {
break;
}

// System.out.printf("LINE > %s%n", line);

if (line.startsWith("# EOF")) {
break;
}
Expand Down Expand Up @@ -173,21 +167,11 @@ private static Collection<Metric> parseOpenMetricsTextMetrics(String body) {
lineReader.unreadLine(line);
break;
} else {
// System.out.printf("LINE > %s%n", line);
/*
System.out.println("CREATE METRIC");
System.out.printf(" > %s%n", typeLine);
System.out.printf(" > %s%n", helpLine);
System.out.printf(" > %s%n", line);
*/

if (type.equals("INFO")) {
type = "GAUGE";
}

Metric metric = createMetric(type, help, line);
// System.out.printf(" > %s%n", metric);
metrics.add(metric);
metrics.add(createMetric(type, help, line));
}
}
}
Expand All @@ -205,8 +189,6 @@ private static Collection<Metric> parseOpenMetricsTextMetrics(String body) {
* @return a Collection of metrics
*/
private static Collection<Metric> parseProtobufMetrics(byte[] bytes) {
// System.out.println("DEBUG parseProtobufMetrics()");

Collection<Metric> collection = new ArrayList<>();

try (InputStream inputStream = new ByteArrayInputStream(bytes)) {
Expand Down Expand Up @@ -265,15 +247,26 @@ private static Collection<Metric> parseProtobufMetrics(byte[] bytes) {

break;
}
case SUMMARY:
{
// TODO refactor to support Summary metrics
break;
}
default:
{
// TODO ignore?
throw new MetricsParserException(
format(
"Exception parsing Protobuf metrics. MetricsParser"
+ " doesn't support metric type [%s]",
metricType));
}
}
}
}

return collection;
} catch (MetricsParserException e) {
throw e;
} catch (Throwable t) {
throw new MetricsParserException("Exception parsing Protobuf metrics", t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ private void assertMetricsResponse(
openTelemetryTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(openTelemetryTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ private void assertMetricsResponse(
exporterTestEnvironment.getJmxExporterMode() == JmxExporterMode.JavaAgent;

String buildInfoName =
isJmxExporterModeJavaAgent
? "jmx_prometheus_javaagent"
: "jmx_prometheus_standalone";
TestSupport.getBuildInfoName(exporterTestEnvironment.getJmxExporterMode());

assertMetric(metrics)
.ofType(Metric.Type.GAUGE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class TestSupport {
/** Network configuration constant */
public static final String NETWORK = "network";

private static final String BUILD_INFO_JAVAAGENT = "jmx_prometheus_javaagent";

private static final String BUILD_INFO_STANDALONE = "jmx_prometheus_standalone";

/** Constructor */
private TestSupport() {
// INTENTIONALLY BLANK
Expand Down Expand Up @@ -124,4 +128,16 @@ public static void destroyNetwork(ClassContext classContext) {
Optional.ofNullable(classContext.map().removeAs(NETWORK, Network.class))
.ifPresent(Network::close);
}

/**
* Method to get the build info name based on the JMX exporter mode
*
* @param jmxExporterMode jmxExporterMode
* @return the build info name
*/
public static String getBuildInfoName(JmxExporterMode jmxExporterMode) {
return jmxExporterMode == JmxExporterMode.JavaAgent
? BUILD_INFO_JAVAAGENT
: BUILD_INFO_STANDALONE;
}
}

0 comments on commit 41540dc

Please sign in to comment.