From 9ce2216d9a506a11f84a1c1ad59414714b0acf1c Mon Sep 17 00:00:00 2001 From: German Laullon Date: Tue, 10 Oct 2023 00:12:01 +0200 Subject: [PATCH] tests --- .../DataDogPortUnificationHandler.java | 19 ++++--- tests/dataDog/Makefile | 15 ++++++ tests/dataDog/README.md | 24 +++++++++ tests/dataDog/compose.yaml | 51 +++++++++++++++++++ tests/dataDog/preprocessor_rules.yaml | 11 ++++ 5 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 tests/dataDog/Makefile create mode 100644 tests/dataDog/README.md create mode 100644 tests/dataDog/compose.yaml create mode 100644 tests/dataDog/preprocessor_rules.yaml diff --git a/proxy/src/main/java/com/wavefront/agent/listeners/DataDogPortUnificationHandler.java b/proxy/src/main/java/com/wavefront/agent/listeners/DataDogPortUnificationHandler.java index dba742bc7..73522a448 100644 --- a/proxy/src/main/java/com/wavefront/agent/listeners/DataDogPortUnificationHandler.java +++ b/proxy/src/main/java/com/wavefront/agent/listeners/DataDogPortUnificationHandler.java @@ -49,7 +49,6 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.util.CharsetUtil; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -69,7 +68,6 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import wavefront.report.ReportPoint; @@ -230,10 +228,13 @@ protected void handleHttpMessage(final ChannelHandlerContext ctx, final FullHttp String outgoingUrl = requestRelayTarget.replaceFirst("/*$", "") + request.uri(); HttpPost outgoingRequest = new HttpPost(outgoingUrl); - request.headers().forEach(header -> { - if (!header.getKey().equalsIgnoreCase("Content-Length")) - outgoingRequest.addHeader(header.getKey(), header.getValue()); - }); + request + .headers() + .forEach( + header -> { + if (!header.getKey().equalsIgnoreCase("Content-Length")) + outgoingRequest.addHeader(header.getKey(), header.getValue()); + }); outgoingRequest.setEntity(new ByteArrayEntity(bodyBytes)); if (synchronousMode) { @@ -266,8 +267,10 @@ protected void handleHttpMessage(final ChannelHandlerContext ctx, final FullHttp httpStatusCounterCache.get(httpStatusCode).inc(); EntityUtils.consumeQuietly(response.getEntity()); } catch (IOException e) { - logger.log(Level.WARNING, - "Unable to relay request to " + requestRelayTarget + ": " + e.getMessage(), e); + logger.log( + Level.WARNING, + "Unable to relay request to " + requestRelayTarget + ": " + e.getMessage(), + e); Metrics.newCounter( new TaggedMetricName("listeners", "http-relay.failed", "port", handle)) .inc(); diff --git a/tests/dataDog/Makefile b/tests/dataDog/Makefile new file mode 100644 index 000000000..e3a7ecc6d --- /dev/null +++ b/tests/dataDog/Makefile @@ -0,0 +1,15 @@ +all: testDD + +.check-env: +ifndef WF_SERVER + $(error WF_SERVER is undefined) +endif +ifndef WF_TOKEN + $(error WF_TOKEN is undefined) +endif +ifndef DD_API_KEY + $(error DD_API_KEY is undefined) +endif + +testDD: .check-env + WF_SERVER=${WF_SERVER} WF_TOKEN=${WF_TOKEN} DD_API_KEY=${DD_API_KEY} docker compose up --build --attach wf-proxy diff --git a/tests/dataDog/README.md b/tests/dataDog/README.md new file mode 100644 index 000000000..30ffcc8e2 --- /dev/null +++ b/tests/dataDog/README.md @@ -0,0 +1,24 @@ +# "DataDog Agent -> WFProxy -> DataDog" Tests + +## Build Proxy + +On Proxy repo home run: + +``` +MVN_ARGS="-DskipTests" make build-jar docker +``` + +## Run test + +On `tests/ddaget/` run: + +``` +WF_SERVER=nimba \ +WF_TOKEN=XXXXX \ +DD_API_KEY=XXXX \ +make +``` + +## Test if working + +Go to you WF server, and serach for a metric `docker.cpu.usage`, you shoul get some series with a `dd_agent_version=7` tag, and other with a `dd_agent_version=6` tag. diff --git a/tests/dataDog/compose.yaml b/tests/dataDog/compose.yaml new file mode 100644 index 000000000..f9771b514 --- /dev/null +++ b/tests/dataDog/compose.yaml @@ -0,0 +1,51 @@ +services: + wf-proxy: + hostname: wf-proxy + build: ../../docker + environment: + WAVEFRONT_URL: https://${WF_SERVER}.wavefront.com/api/ + WAVEFRONT_TOKEN: ${WF_TOKEN} + WAVEFRONT_PROXY_ARGS: > + --dataDogJsonPorts 2879,2880 + --dataDogProcessSystemMetrics true + --dataDogProcessServiceChecks true + --dataDogRequestRelayTarget https://api.datadoghq.com + --preprocessorConfigFile /tmp/preprocessor_rules.yaml + volumes: + - ${PWD}/preprocessor_rules.yaml:/tmp/preprocessor_rules.yaml + + ports: + - "2878:2878" + - "2879:2879" + - "2880:2880" + + dd-agent-7: + hostname: dd-agent-7 + image: gcr.io/datadoghq/agent:7 + environment: + DD_DD_URL: http://host.docker.internal:2879 + DD_API_KEY: ${DD_API_KEY} + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - /proc/:/host/proc/:ro + - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro + + dd-agent-6: + hostname: dd-agent-6 + image: gcr.io/datadoghq/agent:6 + environment: + DD_DD_URL: http://host.docker.internal:2880 + DD_API_KEY: ${DD_API_KEY} + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + - /proc/:/host/proc/:ro + - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro + + # docker run -it --rm --cgroupns host --pid host \ + # -v /var/run/docker.sock:/var/run/docker.sock:ro \ + # -v /proc/:/host/proc/:ro \ + # -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \ + # -e DD_DD_URL=http://host.docker.internal:2879 \ + # -e DD_API_KEY=fa5ab76533cdd581bb23f7e6794a77f2 \ + # -e DD_PROXY_HTTP=http://host.docker.internal:9090 \ + # gcr.io/datadoghq/agent:7 diff --git a/tests/dataDog/preprocessor_rules.yaml b/tests/dataDog/preprocessor_rules.yaml new file mode 100644 index 000000000..3b50e0bf4 --- /dev/null +++ b/tests/dataDog/preprocessor_rules.yaml @@ -0,0 +1,11 @@ +'2879': + - rule : ddv7 + action : addTag + tag : dd_agent_version + value : "7" + +'2880': + - rule : ddv6 + action : addTag + tag : dd_agent_version + value : "6"