Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laullon committed Oct 9, 2023
1 parent ed56718 commit 9ce2216
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions tests/dataDog/Makefile
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tests/dataDog/README.md
Original file line number Diff line number Diff line change
@@ -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.
51 changes: 51 additions & 0 deletions tests/dataDog/compose.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/dataDog/preprocessor_rules.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 9ce2216

Please sign in to comment.