Skip to content

Commit

Permalink
Adding integration test and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsamuel committed Apr 18, 2017
1 parent 564a0ec commit af0eca7
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
- Adding support for custom http headers and TLS for metricbeat modules {pull}3945[3945]
- Add new MetricSet interfaces for developers (`Closer`, `ReportingFetcher`, and `PushMetricSet`). {pull}3908[3908]
- Add kubelet module {pull}3916[3916]
- Add dropwizard module {pull}4022[4022]

*Packetbeat*
- Add `fields` and `fields_under_root` to packetbeat protocols configurations. {pull}3518[3518]
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ services:
- ${PWD}/module/apache/_meta/env
- ${PWD}/module/ceph/_meta/env
- ${PWD}/module/couchbase/_meta/env
- ${PWD}/module/dropwizard/_meta/env
- ${PWD}/module/elasticsearch/_meta/env
- ${PWD}/module/haproxy/_meta/env
- ${PWD}/module/jolokia/_meta/env
Expand All @@ -42,6 +43,7 @@ services:
apache: { condition: service_healthy }
ceph: { condition: service_healthy }
couchbase: { condition: service_healthy }
dropwizard: { condition: service_healthy }
elasticsearch: { condition: service_healthy }
haproxy: { condition: service_healthy }
jolokia: { condition: service_healthy }
Expand All @@ -67,6 +69,9 @@ services:
couchbase:
build: ${PWD}/module/couchbase/_meta

dropwizard:
build: ${PWD}/module/dropwizard/_meta

elasticsearch:
extends:
file: ${ES_BEATS}/testing/environments/${TESTING_ENVIRONMENT}.yml
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/dropwizard/_meta/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM golang:1.7
RUN apt-get update && apt-get install curl
COPY main.go /go

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

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

import (
"fmt"
"log"
"net/http"
)

var response = `{"version":"4.0.0","gauges":{"my_gauge{this=that}":{"value":565}},"counters":{"my_counter":{"count":565},"my_counter2{this=that}":{"count":565}},"histograms":{"my_hist":{"count":565,"max":564,"mean":563.3148706761577,"min":0,"p50":564.0,"p75":564.0,"p95":564.0,"p98":564.0,"p99":564.0,"p999":564.0,"stddev":1.0747916190718627}},"meters":{"my_meter":{"count":0,"m1_rate":0.0,"m5_rate":0.0,"m15_rate":0.0,"mean_rate":0.0,"units":"events/second"}},"timers":{"my_timer{this=that}":{"count":0,"max":0.0,"mean":0.0,"min":0.0,"p50":0.0,"p75":0.0,"p95":0.0,"p98":0.0,"p99":0.0,"p999":0.0,"stddev":0.0,"m1_rate":0.0,"m5_rate":0.0,"m15_rate":0.0,"mean_rate":0.0,"duration_units":"seconds","rate_units":"calls/second"}}}`

func sendResponse(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, response)
}

func main() {

http.HandleFunc("/metrics/metrics", sendResponse) // set router
err := http.ListenAndServe(":9090", nil) // set listen port
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
2 changes: 1 addition & 1 deletion metricbeat/module/dropwizard/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type MetricSet struct {
// Part of new is also setting up the configuration by processing additional
// configuration entries if needed.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
logp.Warn("BETA: The dropwizard collector metricset is beta")
logp.Beta("The dropwizard collector metricset is beta")
config := struct {
Namespace string `config:"namespace" validate:"required"`
}{}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// +build integration

package collector

import (
"os"
"testing"

"github.com/elastic/beats/libbeat/common"
mbtest "github.com/elastic/beats/metricbeat/mb/testing"
"github.com/stretchr/testify/assert"
)

func TestFetch(t *testing.T) {
f := mbtest.NewEventsFetcher(t, getConfig())
events, err := f.Fetch()

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

ok, _ = event.HasKey("my_counter2")
if ok {
tagsRaw, err := event.GetValue("tags")
if err != nil {
t.Fatal("write", err)
} else {
tags, ok := tagsRaw.(common.MapStr)
if !ok {
t.Fatal("write", "unable to cast tags to common.MapStr")
} else {
assert.Equal(t, len(tags), 1)
}
}
}
}
if !assert.NoError(t, err) {
t.FailNow()
}

t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), events)
}

func TestData(t *testing.T) {
f := mbtest.NewEventsFetcher(t, getConfig())
err := mbtest.WriteEvents(f, t)
if err != nil {
t.Fatal("write", err)
}
}

func getEnvHost() string {
host := os.Getenv("DROPWIZARD_HOST")

if len(host) == 0 {
host = "127.0.0.1"
}
return host
}

func getEnvPort() string {
port := os.Getenv("DROPWIZARD_PORT")

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

func getConfig() map[string]interface{} {
return map[string]interface{}{
"module": "dropwizard",
"metricsets": []string{"collector"},
"hosts": []string{getEnvHost() + ":" + getEnvPort()},
"namespace": "testnamespace",
"enabled": true,
}
}
30 changes: 30 additions & 0 deletions metricbeat/tests/system/test_dropwizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import metricbeat
import unittest


class Test(metricbeat.BaseTest):

@unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test")
def test_dropwizard(self):
"""
dropwizard metricset test
"""

self.render_config_template(modules=[{
"name": "dropwizard",
"metricsets": ["collector"],
"hosts": self.get_hosts(),
"period": "1s",
"namespace": "test",
}])
proc = self.start_beat()
self.wait_until(lambda: self.output_lines() > 0, max_timeout=20)
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')]

0 comments on commit af0eca7

Please sign in to comment.