diff --git a/dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java b/dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java index 9954b9dad..47603d5f2 100644 --- a/dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java +++ b/dfsclient/src/test/java/org/hpccsystems/dfs/client/DFSReadWriteTest.java @@ -65,9 +65,9 @@ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class DFSReadWriteTest extends BaseRemoteTest { - // private static final String[] datasets = { "~benchmark::integer::20kb", "~unit_test::all_types::thor", "~unit_test::all_types::xml", "~unit_test::all_types::json", "~unit_test::all_types::csv" }; - private static final String[] datasets = { "~unit_test::all_types::xml", "~unit_test::all_types::json", "~unit_test::all_types::csv" }; - private static final int[] expectedCounts = { 1250, 100000, 100000, 100000, 100000, 100000}; + // Note: These datasets are generated by dfsclient/src/target/resources/generate-datasets.ecl + private static final String[] datasets = { "~benchmark::integer::20kb", "~unit_test::all_types::thor", "~unit_test::all_types::json", "~unit_test::all_types::csv" }; + private static final int[] expectedCounts = { 1250, 100000, 100000, 100000}; private static final Version newProtocolVersion = new Version(8,12,10); diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java b/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java index 9db3f3145..96239616f 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Utils.java @@ -8,6 +8,7 @@ import java.io.OutputStream; import java.io.PrintStream; import java.io.StringWriter; +import java.lang.management.ManagementFactory; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; @@ -1261,4 +1262,78 @@ static public String getTraceParentHeader(Span span) return traceparent; } + + /** + * Checks if a specified VM argument is present. + * + * This method retrieves the list of VM arguments and searches for the specified argument name. + * If the argument is found, it returns true. If the argument is not found, it returns false. + * + * @param vmArgName the name of the VM argument to search for + * @return {@code true} if the specified VM argument is present, {@code false} otherwise + */ + static public boolean containsVMArgument(String vmArgName) + { + List argslist = ManagementFactory.getRuntimeMXBean().getInputArguments(); + for (String string : argslist) + { + if(string.matches("(?i)(" + vmArgName + "):.*")) + { + return true; + } + } + return false; + } + + /** + * Fetches the value of a specified VM argument. + * + * This method retrieves the list of VM arguments and searches for the specified argument name. + * If the argument is found, it returns the value associated with it. If the argument is not found, + * it returns an empty string. + * + * @param vmArgName the name of the VM argument to search for + * @return the value of the specified VM argument, or an empty string if the argument is not found + */ + static public String fetchVMArgument(String vmArgName) + { + List argslist = ManagementFactory.getRuntimeMXBean().getInputArguments(); + for (String string : argslist) + { + if(string.matches("(?i)(" + vmArgName + "):.*")) + { + String[] keyval = string.split(vmArgName+":"); + + return keyval[1]; + } + } + return ""; + } + + /** + * Checks if the OpenTelemetry Java agent is used by inspecting the VM arguments. + * + * This method fetches the VM argument specified by "-javaagent" and checks if it contains + * the term "opentelemetry". If the argument is found and contains "opentelemetry", it returns true. + * Otherwise, it returns false. + * + * @return {@code true} if the OpenTelemetry Java agent is detected, {@code false} otherwise. + */ + static public boolean isOtelJavaagentUsed() + { + String javaAgentPath = fetchVMArgument("-javaagent"); + if (!javaAgentPath.isEmpty()) + { + System.out.println("javaagent VM argument detected: " + javaAgentPath); + + File jaFile = new File(javaAgentPath); + + if (jaFile.getName().contains("opentelemetry") || jaFile.getName().contains("otel")) + { + System.out.println("Otel javaagent argument detected: " + javaAgentPath); + return true; + } + } + return false; + } } diff --git a/wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java b/wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java index 077fba31e..9718e7215 100644 --- a/wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java +++ b/wsclient/src/test/java/org/hpccsystems/ws/client/BaseRemoteTest.java @@ -33,6 +33,7 @@ HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®. import org.hpccsystems.ws.client.HPCCWsTopologyClient.TopologyGroupQueryKind; import org.hpccsystems.ws.client.platform.Platform; import org.hpccsystems.ws.client.utils.Connection; +import org.hpccsystems.ws.client.utils.Utils; import org.hpccsystems.ws.client.wrappers.gen.wstopology.TpGroupWrapper; import org.hpccsystems.ws.client.wrappers.wsworkunits.WorkunitWrapper; import org.junit.Assert; @@ -135,9 +136,13 @@ public static void initialize() throws Exception System.out.println(" otel.metrics.exporter: "+ System.getProperty("otel.metrics.exporter")); System.out.println(" OTEL_METRICS_EXPORTER Env var: " + System.getenv("OTEL_METRICS_EXPORTER")); - globalOTel = AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk(); + if (!Utils.isOtelJavaagentUsed()) + { + globalOTel = AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk(); + } } - else + + if (globalOTel == null) { globalOTel = GlobalOpenTelemetry.get(); } diff --git a/wsclient/src/test/java/org/hpccsystems/ws/client/platform/test/PlatformTester.java b/wsclient/src/test/java/org/hpccsystems/ws/client/platform/test/PlatformTester.java index 8596fb40b..d9d412152 100644 --- a/wsclient/src/test/java/org/hpccsystems/ws/client/platform/test/PlatformTester.java +++ b/wsclient/src/test/java/org/hpccsystems/ws/client/platform/test/PlatformTester.java @@ -190,21 +190,23 @@ else if (currentParam.matches(WSSQLPORTPATTERN)) System.out.println("If missing dependancies arise, test will halt!"); System.out.println(" otel.traces.exporter sys property: "+System.getProperty("otel.traces.exporter")); System.out.println(" OTEL_TRACES_EXPORTER Env var: " + System.getenv("OTEL_TRACES_EXPORTER")); - System.out.println(" OTEL_TRACES_SAMPLER Env var: " + System.getenv("OTEL_TRACES_SAMPLER")); - System.out.println(" otel.traces.sampler sys property: "+System.getProperty("otel.traces.sampler")); + System.out.println(" OTEL_TRACES_SAMPLER Env var: " + System.getenv("OTEL_TRACES_SAMPLER")); + System.out.println(" otel.traces.sampler sys property: "+System.getProperty("otel.traces.sampler")); System.out.println(" otel.logs.exporter: "+ System.getProperty("otel.logs.exporter")); System.out.println(" OTEL_LOGS_EXPORTER Env var: " + System.getenv("OTEL_LOGS_EXPORTER")); System.out.println(" otel.metrics.exporter: "+ System.getProperty("otel.metrics.exporter")); System.out.println(" OTEL_METRICS_EXPORTER Env var: " + System.getenv("OTEL_METRICS_EXPORTER")); - globalOTel = AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk(); + if (!Utils.isOtelJavaagentUsed()) + { + globalOTel = AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk(); + } } - else - { + + if (globalOTel == null) globalOTel = GlobalOpenTelemetry.get(); - } - Span rootSpan = globalOTel.getTracer("PlatformTester").spanBuilder("rootspan").startSpan(); + Span rootSpan = globalOTel.getTracer("PlatformTester").spanBuilder("PlatformTest").startSpan(); try (Scope scope = rootSpan.makeCurrent()) { Platform platform = Platform.get(prot, hpccServer, port, user, pass);