From 99fb9a7c848bba4023d63d6c6c6e6347ad88a771 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 26 Oct 2022 13:10:30 +0530 Subject: [PATCH 1/3] add req headers to send req --- .../apptuit/metrics/client/ApptuitPutClient.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java b/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java index 01748c4..21662fc 100644 --- a/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java +++ b/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java @@ -16,6 +16,8 @@ package ai.apptuit.metrics.client; +import org.graalvm.compiler.api.replacements.Snippet; + import static ai.apptuit.metrics.client.Sanitizer.DEFAULT_SANITIZER; import java.io.BufferedOutputStream; @@ -31,10 +33,7 @@ import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.GZIPOutputStream; @@ -96,11 +95,17 @@ public void send(Collection dataPoints) throws ConnectException, Resp } public void send(Collection dataPoints, Sanitizer sanitizer) throws ConnectException, ResponseStatusException, IOException { + send(dataPoints, sanitizer, new HashMap<>()); + } + public void send(Collection dataPoints, Sanitizer sanitizer, Map reqHeaders) throws ConnectException, ResponseStatusException, IOException { if (dataPoints.isEmpty()) { return; } + if (reqHeaders == null) { + reqHeaders = new HashMap<>(); + } DatapointsHttpEntity entity = new DatapointsHttpEntity(dataPoints, globalTags, sanitizer); @@ -118,6 +123,7 @@ public void send(Collection dataPoints, Sanitizer sanitizer) throws C urlConnection.setRequestProperty(CONTENT_ENCODING, CONTENT_ENCODING_GZIP); } urlConnection.setRequestProperty("Authorization", generateAuthHeader()); + reqHeaders.forEach(urlConnection::setRequestProperty); urlConnection.setRequestMethod("POST"); urlConnection.setDoInput(true); urlConnection.setDoOutput(true); From 5ccde18cf821e8e3b937d12a6910dc1293eb88b3 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 26 Oct 2022 13:15:00 +0530 Subject: [PATCH 2/3] removed unnecessary import --- .../main/java/ai/apptuit/metrics/client/ApptuitPutClient.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java b/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java index 21662fc..a487807 100644 --- a/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java +++ b/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java @@ -16,8 +16,6 @@ package ai.apptuit.metrics.client; -import org.graalvm.compiler.api.replacements.Snippet; - import static ai.apptuit.metrics.client.Sanitizer.DEFAULT_SANITIZER; import java.io.BufferedOutputStream; From 84a2fb6b297ba457e349bde62052e51b04eebd7a Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 26 Oct 2022 13:17:32 +0530 Subject: [PATCH 3/3] dont create empty object --- .../java/ai/apptuit/metrics/client/ApptuitPutClient.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java b/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java index a487807..a0085f1 100644 --- a/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java +++ b/send-client/src/main/java/ai/apptuit/metrics/client/ApptuitPutClient.java @@ -93,7 +93,7 @@ public void send(Collection dataPoints) throws ConnectException, Resp } public void send(Collection dataPoints, Sanitizer sanitizer) throws ConnectException, ResponseStatusException, IOException { - send(dataPoints, sanitizer, new HashMap<>()); + send(dataPoints, sanitizer, null); } public void send(Collection dataPoints, Sanitizer sanitizer, Map reqHeaders) throws ConnectException, ResponseStatusException, IOException { @@ -101,9 +101,6 @@ public void send(Collection dataPoints, Sanitizer sanitizer, Map(); - } DatapointsHttpEntity entity = new DatapointsHttpEntity(dataPoints, globalTags, sanitizer); @@ -121,7 +118,9 @@ public void send(Collection dataPoints, Sanitizer sanitizer, Map