Skip to content

Commit

Permalink
Adding dropwizard docker container for integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel committed Apr 19, 2017
1 parent af0eca7 commit 85ba381
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 52 deletions.
2 changes: 1 addition & 1 deletion metricbeat/docs/modules/dropwizard.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This file is generated! See scripts/docs_collector.py
[[metricbeat-module-dropwizard]]
== dropwizard Module

This is the dropwizard Module.
This is the http://dropwizard.io[Dropwizard] Module.



Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/dropwizard/_meta/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/target
12 changes: 6 additions & 6 deletions metricbeat/module/dropwizard/_meta/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM golang:1.7
RUN apt-get update && apt-get install curl
COPY main.go /go
FROM maven:3.3-jdk-8
COPY test /test

HEALTHCHECK CMD curl -f http://localhost:9090/metrics/metrics
EXPOSE 9090
HEALTHCHECK CMD curl -f http://localhost:8080/test/helloworld
EXPOSE 8080

CMD go run /go/main.go
WORKDIR /test
CMD mvn jetty:run
2 changes: 1 addition & 1 deletion metricbeat/module/dropwizard/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
== dropwizard Module

This is the dropwizard Module.
This is the http://dropwizard.io[Dropwizard] Module.

2 changes: 1 addition & 1 deletion metricbeat/module/dropwizard/_meta/env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DROPWIZARD_HOST=dropwizard
DROPWIZARD_PORT=9090
DROPWIZARD_PORT=8080
22 changes: 0 additions & 22 deletions metricbeat/module/dropwizard/_meta/main.go

This file was deleted.

1 change: 1 addition & 0 deletions metricbeat/module/dropwizard/_meta/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
40 changes: 40 additions & 0 deletions metricbeat/module/dropwizard/_meta/test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.test.dropwizard</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Test Webapp for dropwizard metrics</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-servlets</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.test.dropwizard;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.codahale.metrics.servlets.MetricsServlet;

/**
*
* MetricsServletContextListener is a listener class that needs to be added to all assertion
* web application's web.xml in order to expose the MetricsRegistry which maintains all the
* metrics that are being tracked.
*
*/

public class MetricsServletContextListener extends MetricsServlet.ContextListener {

public static MetricRegistry METRIC_REGISTRY = new MetricRegistry();

static {
Counter c = new Counter();
c.inc();
METRIC_REGISTRY.register("my_counter{this=that}", c);
METRIC_REGISTRY.register("my_meter{this=that}", new Meter());

METRIC_REGISTRY.register("my_timer", new Timer());
METRIC_REGISTRY.histogram("my_histogram");
METRIC_REGISTRY.register("my_gauge", new Gauge<Integer>() {

@Override
public Integer getValue() {
// TODO Auto-generated method stub
return null;
}

});

}

@Override
protected MetricRegistry getMetricRegistry() {
return METRIC_REGISTRY;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.test.dropwizard;

import java.io.Closeable;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@SuppressWarnings("serial")
public class TestServlet extends HttpServlet {
@SuppressWarnings("unchecked")
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = null;
try {
out = new PrintWriter(resp.getWriter());
out.println("hello world");
out.flush();
} finally {
close(out);
}
}

private static void close(Closeable c) {
if (c == null) {
return;
}

try {
c.close();
} catch (IOException ignore) {
/* ignore */
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Test Dropwizard</display-name>

<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>io.test.dropwizard.TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/helloworld</url-pattern>
</servlet-mapping>

<listener>
<listener-class>io.test.dropwizard.MetricsServletContextListener</listener-class>
</listener>

<servlet>
<servlet-name>CodahaleMetrics</servlet-name>
<servlet-class>com.codahale.metrics.servlets.MetricsServlet</servlet-class>
<init-param>
<param-name>metrics-uri</param-name>
<param-value>/metrics</param-value>
</init-param>
<init-param>
<param-name>ping-uri</param-name>
<param-value>/ping</param-value>
</init-param>
<init-param>
<param-name>healthcheck-uri</param-name>
<param-value>/health</param-value>
</init-param>
<init-param>
<param-name>threads-uri</param-name>
<param-value>/threads</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>CodahaleMetrics</servlet-name>
<url-pattern>/metrics/*</url-pattern>
</servlet-mapping>


</web-app>
12 changes: 1 addition & 11 deletions metricbeat/module/dropwizard/collector/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@
"version": "6.0.0-alpha1"
},
"dropwizard": {
"test": {
"counter1": {
"count": 1337
},
"gauge1": {
"value": 1337
},
"tags": {
"this": "that"
}
}
"test": {}
},
"metricset": {
"host": "localhost:8080",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ func TestFetch(t *testing.T) {
f := mbtest.NewEventsFetcher(t, getConfig())
events, err := f.Fetch()

hasTag := false
doesntHaveTag := false
for _, event := range events {
ok, _ := event.HasKey("my_counter")

ok, _ := event.HasKey("my_histogram")
if ok {
_, err := event.GetValue("tags")
if err == nil {
t.Fatal("write", "my_counter not supposed to have tags")
}
doesntHaveTag = true
}

ok, _ = event.HasKey("my_counter2")
ok, _ = event.HasKey("my_counter")
if ok {
tagsRaw, err := event.GetValue("tags")
if err != nil {
Expand All @@ -35,10 +39,13 @@ func TestFetch(t *testing.T) {
t.Fatal("write", "unable to cast tags to common.MapStr")
} else {
assert.Equal(t, len(tags), 1)
hasTag = true
}
}
}
}
assert.Equal(t, hasTag, true)
assert.Equal(t, doesntHaveTag, true)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down Expand Up @@ -67,17 +74,18 @@ func getEnvPort() string {
port := os.Getenv("DROPWIZARD_PORT")

if len(port) == 0 {
port = "9090"
port = "8080"
}
return port
}

func getConfig() map[string]interface{} {
return map[string]interface{}{
"module": "dropwizard",
"metricsets": []string{"collector"},
"hosts": []string{getEnvHost() + ":" + getEnvPort()},
"namespace": "testnamespace",
"enabled": true,
"module": "dropwizard",
"metricsets": []string{"collector"},
"hosts": []string{getEnvHost() + ":" + getEnvPort()},
"namespace": "testnamespace",
"metrics_path": "/test/metrics",
"enabled": true,
}
}
4 changes: 4 additions & 0 deletions metricbeat/tests/system/config/metricbeat.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ metricbeat.modules:
period: {{ m.period }}
{% endif -%}

{% if m.path -%}
metrics_path: {{ m.path }}
{% endif -%}

{% if m.timeout -%}
timeout: {{ m.timeout }}
{% endif -%}
Expand Down
5 changes: 3 additions & 2 deletions metricbeat/tests/system/test_dropwizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ def test_dropwizard(self):
"name": "dropwizard",
"metricsets": ["collector"],
"hosts": self.get_hosts(),
"path": "/test/metrics",
"period": "1s",
"namespace": "test",
}])
proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, max_timeout=20)
self.wait_until(lambda: self.output_lines() > 0, max_timeout=10)
proc.check_kill_and_wait()

output = self.read_output_json()
self.assertTrue(len(output) >= 1)

def get_hosts(self):
return [os.getenv('DROPWIZARD_HOST', 'localhost') + ':' +
os.getenv('DROPWIZARD_PORT', '9090')]
os.getenv('DROPWIZARD_PORT', '8080')]

0 comments on commit 85ba381

Please sign in to comment.