Skip to content

Commit

Permalink
[Metricbeat] Add TestFetch method to php_fpm tests
Browse files Browse the repository at this point in the history
This makes sure proper integration tests are run.
  • Loading branch information
ruflin committed Jan 29, 2019
1 parent ded12e4 commit 67d4fba
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 32 deletions.
24 changes: 15 additions & 9 deletions metricbeat/module/php_fpm/pool/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"beat": {
"agent": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"event": {
"dataset": "php_fpm.pool",
"duration": 115000,
"module": "php_fpm"
},
"metricset": {
"host": "phpfpm:81",
"module": "php_fpm",
"name": "pool",
"rtt": 115
"name": "pool"
},
"php_fpm": {
"pool": {
"connections": {
"accepted": 1,
"accepted": 5,
"listen_queue_len": 0,
"max_listen_queue": 0,
"queued": 0
Expand All @@ -28,8 +30,12 @@
"total": 2
},
"slow_requests": 0,
"start_since": 670,
"start_time": 1512631228
"start_since": 57,
"start_time": 1548678234
}
},
"service": {
"address": "127.0.0.1:81",
"type": "php_fpm"
}
}
}
17 changes: 17 additions & 0 deletions metricbeat/module/php_fpm/pool/pool_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,27 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/libbeat/tests/compose"
mbtest "github.com/elastic/beats/metricbeat/mb/testing"
)

func TestFetch(t *testing.T) {
compose.EnsureUp(t, "phpfpm")

f := mbtest.NewReportingMetricSetV2(t, getConfig())
events, errs := mbtest.ReportingFetchV2(f)

assert.Empty(t, errs)
if !assert.NotEmpty(t, events) {
t.FailNow()
}

t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(),
events[0].BeatEvent("haproxy", "info").Fields.StringToPrint())

}
func TestData(t *testing.T) {
compose.EnsureUp(t, "phpfpm")
f := mbtest.NewReportingMetricSetV2(t, getConfig())
Expand Down
48 changes: 25 additions & 23 deletions metricbeat/module/php_fpm/process/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
{
"@timestamp": "2018-09-25T16:47:04.998Z",
"@timestamp": "2017-10-12T08:05:34.853Z",
"agent": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"event": {
"dataset": "php_fpm.process",
"duration": 115000,
"module": "php_fpm"
},
"metricset": {
"module": "php_fpm",
"host": "phpfpm:81",
"rtt": 24681267,
"name": "process"
},
"php_fpm": {
"pool": {
"name": "www"
},
"process": {
"content_length": 0,
"last_request_cpu": 0,
"last_request_memory": 2097152,
"request_duration": 1404,
"script": "-",
"pid": 6,
"start_time": 1537974596,
"user": "-",
"state": "Idle",
"start_since": 3946,
"requests": 28,
"last_request_memory": 0,
"pid": 27,
"request_duration": 133,
"request_method": "GET",
"request_uri": "/status?json=",
"content_length": 0
"request_uri": "/status?full=\u0026json=",
"requests": 4,
"script": "-",
"start_since": 59,
"start_time": 1548678234,
"state": "Running",
"user": "-"
}
},
"beat": {
"name": "host.example.com",
"hostname": "host.example.com",
"version": "7.0.0-alpha1"
},
"host": {
"name": "DESKTOP-RFOOE09"
"service": {
"address": "127.0.0.1:81",
"type": "php_fpm"
}
}
}
18 changes: 18 additions & 0 deletions metricbeat/module/php_fpm/process/process_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,28 @@ import (
"os"
"testing"

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/libbeat/tests/compose"
mbtest "github.com/elastic/beats/metricbeat/mb/testing"
)

func TestFetch(t *testing.T) {
compose.EnsureUp(t, "phpfpm")

f := mbtest.NewReportingMetricSetV2(t, getConfig())
events, errs := mbtest.ReportingFetchV2(f)

assert.Empty(t, errs)
if !assert.NotEmpty(t, events) {
t.FailNow()
}

t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(),
events[0].BeatEvent("haproxy", "info").Fields.StringToPrint())

}

func TestData(t *testing.T) {
compose.EnsureUp(t, "phpfpm")
f := mbtest.NewReportingMetricSetV2(t, getConfig())
Expand Down

0 comments on commit 67d4fba

Please sign in to comment.