-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding integration test and changelog
- Loading branch information
Showing
8 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROPWIZARD_HOST=dropwizard | ||
DROPWIZARD_PORT=9090 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
metricbeat/module/dropwizard/collector/collector_integration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')] |