From f95bb20f86a2e83500d0d4bdda82b67974d7548e Mon Sep 17 00:00:00 2001 From: German Laullon Date: Fri, 8 Jul 2022 11:41:45 +0200 Subject: [PATCH 1/6] Event API change from list to json string --- java-lib/pom.xml | 4 ++-- .../src/main/java/com/wavefront/api/EventAPI.java | 12 ++++++++---- pom.xml | 2 +- yammer-metrics/pom.xml | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/java-lib/pom.xml b/java-lib/pom.xml index 6dac30a..cb4815e 100644 --- a/java-lib/pom.xml +++ b/java-lib/pom.xml @@ -3,12 +3,12 @@ 4.0.0 java-lib - 2022-06.5-SNAPSHOT + proxy-new-SNAPSHOT com.wavefront javalib - 2022-06.5-SNAPSHOT + proxy-new-SNAPSHOT Wavefront Shared Java Library diff --git a/java-lib/src/main/java/com/wavefront/api/EventAPI.java b/java-lib/src/main/java/com/wavefront/api/EventAPI.java index e74f981..a6feffa 100644 --- a/java-lib/src/main/java/com/wavefront/api/EventAPI.java +++ b/java-lib/src/main/java/com/wavefront/api/EventAPI.java @@ -2,10 +2,7 @@ import com.wavefront.dto.Event; -import javax.ws.rs.Consumes; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @@ -25,4 +22,11 @@ public interface EventAPI { @Path("v2/wfproxy/event") Response proxyEvents(@HeaderParam("X-WF-PROXY-ID") final UUID proxyId, final List eventBatch); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + @Path("v2/wfproxy/event") + Response proxyEventsString(@HeaderParam("X-WF-PROXY-ID") final UUID proxyId, + final String eventBatch); } diff --git a/pom.xml b/pom.xml index d34cf96..382a285 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.wavefront javalib - 2022-06.5-SNAPSHOT + proxy-new-SNAPSHOT java-lib yammer-metrics diff --git a/yammer-metrics/pom.xml b/yammer-metrics/pom.xml index c20beaa..622d6aa 100644 --- a/yammer-metrics/pom.xml +++ b/yammer-metrics/pom.xml @@ -3,12 +3,12 @@ javalib com.wavefront - 2022-06.5-SNAPSHOT + proxy-new-SNAPSHOT 4.0.0 yammer-metrics - 2022-06.5-SNAPSHOT + proxy-new-SNAPSHOT Wavefront Yammer Metrics From f7a8d6a8c35ec599a34e7d5e4e2d727aee93367c Mon Sep 17 00:00:00 2001 From: German Laullon Date: Tue, 12 Jul 2022 21:52:13 +0200 Subject: [PATCH 2/6] Logs --- java-lib/src/main/java/com/wavefront/api/LogAPI.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/java-lib/src/main/java/com/wavefront/api/LogAPI.java b/java-lib/src/main/java/com/wavefront/api/LogAPI.java index ae44f95..2dbe03b 100644 --- a/java-lib/src/main/java/com/wavefront/api/LogAPI.java +++ b/java-lib/src/main/java/com/wavefront/api/LogAPI.java @@ -2,10 +2,7 @@ import com.wavefront.dto.Log; -import javax.ws.rs.Consumes; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @@ -23,4 +20,10 @@ public interface LogAPI { @Consumes(MediaType.APPLICATION_JSON) @Path("le-mans/v1/streams/ingestion-pipeline-stream") Response proxyLogs(@HeaderParam("agent") final String agentProxyId, final List logBatch); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.TEXT_PLAIN) + @Path("le-mans/v1/streams/ingestion-pipeline-stream") + Response proxyLogsStr(@HeaderParam("agent") final String agentProxyId, final String logBatch); } From c63c5fcecd022a03a08accfba2fdc6bad6e80601 Mon Sep 17 00:00:00 2001 From: German Laullon Date: Mon, 26 Sep 2022 11:05:37 +0200 Subject: [PATCH 3/6] Correct free port allocation --- .../WavefrontYammerHttpMetricsReporterTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/yammer-metrics/src/test/java/com/wavefront/integrations/metrics/WavefrontYammerHttpMetricsReporterTest.java b/yammer-metrics/src/test/java/com/wavefront/integrations/metrics/WavefrontYammerHttpMetricsReporterTest.java index 4fe3a10..f8b1779 100644 --- a/yammer-metrics/src/test/java/com/wavefront/integrations/metrics/WavefrontYammerHttpMetricsReporterTest.java +++ b/yammer-metrics/src/test/java/com/wavefront/integrations/metrics/WavefrontYammerHttpMetricsReporterTest.java @@ -37,6 +37,7 @@ import java.io.InputStream; import java.net.InetAddress; import java.net.InetSocketAddress; +import java.net.ServerSocket; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -82,7 +83,7 @@ private void innerSetUp(boolean prependGroupName, MetricTranslator metricTransla build(); metricsServer = ServerBootstrap.bootstrap(). setLocalAddress(InetAddress.getLoopbackAddress()). - setListenerPort(0). + setListenerPort(getFreePort()). setServerInfo("Test/1.1"). setIOReactorConfig(metricsIOreactor). registerHandler("*", new HttpAsyncRequestHandler() { @@ -134,10 +135,12 @@ public void handle(HttpRequest httpRequest, HttpAsyncExchange httpAsyncExchange, throw new RuntimeException("Interrupted trying to sleep.", ex); } } + + InetSocketAddress address =(InetSocketAddress) metricsServer.getEndpoint().getAddress(); wavefrontYammerHttpMetricsReporter = new WavefrontYammerHttpMetricsReporter.Builder(). withName("test-http"). withMetricsRegistry(metricsRegistry). - withEndpoint(InetAddress.getLoopbackAddress().getHostAddress(), ((InetSocketAddress) metricsServer.getEndpoint().getAddress()).getPort()). + withEndpoint(address.getHostName(),address.getPort()). withTimeSupplier(() -> stubbedTime). withMetricTranslator(metricTranslator). withPrependedGroupNames(prependGroupName). @@ -558,4 +561,10 @@ private void runReporter() throws InterruptedException { wavefrontYammerHttpMetricsReporter.run(); wavefrontYammerHttpMetricsReporter.flush(); } + + private int getFreePort() throws IOException { + try (ServerSocket serverSocket = new ServerSocket(0)) { + return serverSocket.getLocalPort(); + } + } } From 92fd8c1638c927695f28c23b0c7b5fca2b74f0aa Mon Sep 17 00:00:00 2001 From: German Laullon Date: Tue, 4 Oct 2022 00:47:24 +0200 Subject: [PATCH 4/6] revert proxy name --- java-lib/src/main/java/com/wavefront/api/ProxyV2API.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/java-lib/src/main/java/com/wavefront/api/ProxyV2API.java b/java-lib/src/main/java/com/wavefront/api/ProxyV2API.java index be41d81..38a9bad 100644 --- a/java-lib/src/main/java/com/wavefront/api/ProxyV2API.java +++ b/java-lib/src/main/java/com/wavefront/api/ProxyV2API.java @@ -29,7 +29,6 @@ public interface ProxyV2API { * @param proxyId ID of the proxy. * @param authorization Authorization token. * @param hostname Host name of the proxy. - * @param proxyname Proxy name of the proxy (used as internal metric source). * @param version Build version of the proxy. * @param currentMillis Current time at the proxy (used to calculate clock drift). * @param agentMetrics Proxy metrics. @@ -43,7 +42,6 @@ public interface ProxyV2API { AgentConfiguration proxyCheckin(@HeaderParam("X-WF-PROXY-ID") final UUID proxyId, @HeaderParam("Authorization") String authorization, @QueryParam("hostname") String hostname, - @QueryParam("proxyname") String proxyname, @QueryParam("version") String version, @QueryParam("currentMillis") final Long currentMillis, JsonNode agentMetrics, From 0eafaf24d2fbf5edd4ec7ca82f655b2536e5962f Mon Sep 17 00:00:00 2001 From: German Laullon Date: Mon, 10 Oct 2022 10:47:07 +0200 Subject: [PATCH 5/6] Merge branch 'master' into dev-proxy2 # Conflicts: # java-lib/pom.xml # pom.xml # yammer-metrics/pom.xml --- java-lib/src/main/java/com/wavefront/api/ProxyV2API.java | 2 ++ open_source_licenses.txt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/java-lib/src/main/java/com/wavefront/api/ProxyV2API.java b/java-lib/src/main/java/com/wavefront/api/ProxyV2API.java index 38a9bad..be41d81 100644 --- a/java-lib/src/main/java/com/wavefront/api/ProxyV2API.java +++ b/java-lib/src/main/java/com/wavefront/api/ProxyV2API.java @@ -29,6 +29,7 @@ public interface ProxyV2API { * @param proxyId ID of the proxy. * @param authorization Authorization token. * @param hostname Host name of the proxy. + * @param proxyname Proxy name of the proxy (used as internal metric source). * @param version Build version of the proxy. * @param currentMillis Current time at the proxy (used to calculate clock drift). * @param agentMetrics Proxy metrics. @@ -42,6 +43,7 @@ public interface ProxyV2API { AgentConfiguration proxyCheckin(@HeaderParam("X-WF-PROXY-ID") final UUID proxyId, @HeaderParam("Authorization") String authorization, @QueryParam("hostname") String hostname, + @QueryParam("proxyname") String proxyname, @QueryParam("version") String version, @QueryParam("currentMillis") final Long currentMillis, JsonNode agentMetrics, diff --git a/open_source_licenses.txt b/open_source_licenses.txt index 4f3d516..ccaa0a0 100644 --- a/open_source_licenses.txt +++ b/open_source_licenses.txt @@ -1,6 +1,6 @@ open_source_license.txt -Wavefront by VMware 2022-09.1 GA +Wavefront by VMware 2022-10.1 GA ====================================================================== The following copyright statements and licenses apply to various open @@ -12751,4 +12751,4 @@ a CD or equivalent physical medium. This offer to obtain a copy of the Source Files is valid for three years from the date you acquired or last used this Software product. Alternatively, the Source Files may accompany the VMware service. -[WAVEFRONTHQJAVA2022091GAAT092122] \ No newline at end of file +[WAVEFRONTHQJAVA2022101GAAT100322] \ No newline at end of file From 8d40e4339f73fe8f506d7b55bd222a65582fa544 Mon Sep 17 00:00:00 2001 From: German Laullon Date: Tue, 22 Nov 2022 13:36:02 +0100 Subject: [PATCH 6/6] better version parser --- .../metrics/JsonMetricsGenerator.java | 30 +++++++++---------- .../metrics/JsonMetricsGeneratorTest.java | 12 ++++++++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/java-lib/src/main/java/com/wavefront/metrics/JsonMetricsGenerator.java b/java-lib/src/main/java/com/wavefront/metrics/JsonMetricsGenerator.java index c538296..d572c0c 100644 --- a/java-lib/src/main/java/com/wavefront/metrics/JsonMetricsGenerator.java +++ b/java-lib/src/main/java/com/wavefront/metrics/JsonMetricsGenerator.java @@ -38,8 +38,11 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.SortedMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.annotation.Nullable; +import javax.annotation.RegEx; import static com.wavefront.common.MetricsToTimeseries.sanitize; @@ -146,24 +149,19 @@ private static void writeBuildMetrics(ResourceBundle props, JsonGenerator json, } static int extractVersion(String versionStr) { - int version = 0; - String[] components = versionStr.split("\\."); - for (int i = 0; i < Math.min(3, components.length); i++) { - String component = components[i]; - if (StringUtils.isNotBlank(component) && StringUtils.isNumeric(component)) { - version *= 1000; // we'll assume this will fit. 3.123.0 will become 3123000. - version += Integer.valueOf(component); - } else { - version = 0; // not actually a convertable name (probably something with SNAPSHOT). - break; + final String regex = "^(\\d*)\\.(\\d*)\\.?(\\d*)?"; + final Pattern pattern = Pattern.compile(regex); + final Matcher matcher = pattern.matcher(versionStr); + + int x = 0, y = 0, z = 0; + if (matcher.find()) { + x = Integer.valueOf(matcher.group(1)); + y = Integer.valueOf(matcher.group(2)); + if (!matcher.group(3).equals("")) { + z = Integer.valueOf(matcher.group(3)); } } - if (components.length == 2) { - version *= 1000; - } else if (components.length == 1) { - version *= 1000000; // make sure 3 outputs 3000000 - } - return version; + return (x * 1_000_000 + y * 1_000 + z); } private static void mergeMapIntoJson(JsonGenerator jsonGenerator, Map metrics) throws IOException { diff --git a/java-lib/src/test/java/com/wavefront/metrics/JsonMetricsGeneratorTest.java b/java-lib/src/test/java/com/wavefront/metrics/JsonMetricsGeneratorTest.java index d01d50a..b83f2f6 100644 --- a/java-lib/src/test/java/com/wavefront/metrics/JsonMetricsGeneratorTest.java +++ b/java-lib/src/test/java/com/wavefront/metrics/JsonMetricsGeneratorTest.java @@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicLong; import static com.google.common.truth.Truth.assertThat; +import static com.wavefront.metrics.JsonMetricsGenerator.extractVersion; /** * Basic unit tests around {@link JsonMetricsGenerator} @@ -278,4 +279,15 @@ public void testWavefrontHistogramBulkUpdateHandlesNullParams() throws IOExcepti assertThat(json).isEqualTo("{\"test.metric\":{\"bins\":[]}}"); } + + @Test + public void testExtractVersion(){ + assertThat(extractVersion("12.1")).isEqualTo(12_001_000); + assertThat(extractVersion("12.1.0")).isEqualTo(12_001_000); + assertThat(extractVersion("12.1.1")).isEqualTo(12_001_001); + assertThat(extractVersion("12.1-SNAPSHOT")).isEqualTo(12_001_000); + assertThat(extractVersion("12.1.0-SNAPSHOT")).isEqualTo(12_001_000); + assertThat(extractVersion("12")).isEqualTo(0); + assertThat(extractVersion("SNAPSHOT")).isEqualTo(0); + } }