From 0cf1fdb0e95a40bedd7f758f7349d45a112e9ad1 Mon Sep 17 00:00:00 2001 From: beats-jenkins Date: Tue, 5 Mar 2019 15:21:15 +0100 Subject: [PATCH] [Metricbeat] Add http endpoint tests for php_fpm module This adds also support for query params to the testing framework. --- metricbeat/mb/testing/data_test.go | 10 +- .../module/php_fpm/pool/_meta/data.json | 14 +-- .../php_fpm/pool/_meta/testdata/config.yml | 2 + .../php_fpm/pool/_meta/testdata/docs.json | 1 + .../_meta/testdata/docs.json-expected.json | 38 +++++++ .../php_fpm/pool/pool_integration_test.go | 8 -- .../module/php_fpm/process/_meta/data.json | 24 ++--- .../php_fpm/process/_meta/testdata/config.yml | 2 + .../php_fpm/process/_meta/testdata/docs.json | 1 + .../_meta/testdata/docs.json-expected.json | 98 +++++++++++++++++++ .../process/process_integration_test.go | 9 -- 11 files changed, 166 insertions(+), 41 deletions(-) create mode 100644 metricbeat/module/php_fpm/pool/_meta/testdata/config.yml create mode 100644 metricbeat/module/php_fpm/pool/_meta/testdata/docs.json create mode 100644 metricbeat/module/php_fpm/pool/_meta/testdata/docs.json-expected.json create mode 100644 metricbeat/module/php_fpm/process/_meta/testdata/config.yml create mode 100644 metricbeat/module/php_fpm/process/_meta/testdata/docs.json create mode 100644 metricbeat/module/php_fpm/process/_meta/testdata/docs.json-expected.json diff --git a/metricbeat/mb/testing/data_test.go b/metricbeat/mb/testing/data_test.go index bc8cc8ab6396..aa0c3c6f18b9 100644 --- a/metricbeat/mb/testing/data_test.go +++ b/metricbeat/mb/testing/data_test.go @@ -37,6 +37,8 @@ import ( // TODO: generate include file for these tests automatically moving forward _ "github.com/elastic/beats/metricbeat/module/kibana/status" + _ "github.com/elastic/beats/metricbeat/module/php_fpm/pool" + _ "github.com/elastic/beats/metricbeat/module/php_fpm/process" _ "github.com/elastic/beats/metricbeat/module/rabbitmq/connection" _ "github.com/elastic/beats/metricbeat/module/traefik/health" ) @@ -174,7 +176,13 @@ func server(t *testing.T, path string, url string) *httptest.Server { } server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == url { + query := "" + v := r.URL.Query() + if len(v) > 0 { + query += "?" + v.Encode() + } + + if r.URL.Path+query == url { w.Header().Set("Content-Type", "application/json;") w.WriteHeader(200) w.Write(body) diff --git a/metricbeat/module/php_fpm/pool/_meta/data.json b/metricbeat/module/php_fpm/pool/_meta/data.json index 0fa62df18697..06dcb35eb619 100644 --- a/metricbeat/module/php_fpm/pool/_meta/data.json +++ b/metricbeat/module/php_fpm/pool/_meta/data.json @@ -1,9 +1,5 @@ { - "@timestamp": "2017-10-12T08:05:34.853Z", - "agent": { - "hostname": "host.example.com", - "name": "host.example.com" - }, + "@timestamp": "2019-03-01T08:05:34.853Z", "event": { "dataset": "php_fpm.pool", "duration": 115000, @@ -15,7 +11,7 @@ "php_fpm": { "pool": { "connections": { - "accepted": 10, + "accepted": 18, "listen_queue_len": 0, "max_listen_queue": 0, "queued": 0 @@ -30,12 +26,12 @@ "total": 2 }, "slow_requests": 0, - "start_since": 600, - "start_time": 1548749474 + "start_since": 3589, + "start_time": 1551792028 } }, "service": { - "address": "127.0.0.1:81", + "address": "127.0.0.1:55555", "type": "php_fpm" } } \ No newline at end of file diff --git a/metricbeat/module/php_fpm/pool/_meta/testdata/config.yml b/metricbeat/module/php_fpm/pool/_meta/testdata/config.yml new file mode 100644 index 000000000000..7ff4a86bf677 --- /dev/null +++ b/metricbeat/module/php_fpm/pool/_meta/testdata/config.yml @@ -0,0 +1,2 @@ +type: http +url: "/status?json=" diff --git a/metricbeat/module/php_fpm/pool/_meta/testdata/docs.json b/metricbeat/module/php_fpm/pool/_meta/testdata/docs.json new file mode 100644 index 000000000000..34495c80aa17 --- /dev/null +++ b/metricbeat/module/php_fpm/pool/_meta/testdata/docs.json @@ -0,0 +1 @@ +{"pool":"www","process manager":"dynamic","start time":1551792028,"start since":3589,"accepted conn":18,"listen queue":0,"max listen queue":0,"listen queue len":0,"idle processes":1,"active processes":1,"total processes":2,"max active processes":1,"max children reached":0,"slow requests":0} diff --git a/metricbeat/module/php_fpm/pool/_meta/testdata/docs.json-expected.json b/metricbeat/module/php_fpm/pool/_meta/testdata/docs.json-expected.json new file mode 100644 index 000000000000..9bd020139803 --- /dev/null +++ b/metricbeat/module/php_fpm/pool/_meta/testdata/docs.json-expected.json @@ -0,0 +1,38 @@ +[ + { + "event": { + "dataset": "php_fpm.pool", + "duration": 115000, + "module": "php_fpm" + }, + "metricset": { + "name": "pool" + }, + "php_fpm": { + "pool": { + "connections": { + "accepted": 18, + "listen_queue_len": 0, + "max_listen_queue": 0, + "queued": 0 + }, + "name": "www", + "process_manager": "dynamic", + "processes": { + "active": 1, + "idle": 1, + "max_active": 1, + "max_children_reached": 0, + "total": 2 + }, + "slow_requests": 0, + "start_since": 3589, + "start_time": 1551792028 + } + }, + "service": { + "address": "127.0.0.1:55555", + "type": "php_fpm" + } + } +] \ No newline at end of file diff --git a/metricbeat/module/php_fpm/pool/pool_integration_test.go b/metricbeat/module/php_fpm/pool/pool_integration_test.go index 0fc2e43e10d1..9ace6ed2391c 100644 --- a/metricbeat/module/php_fpm/pool/pool_integration_test.go +++ b/metricbeat/module/php_fpm/pool/pool_integration_test.go @@ -44,14 +44,6 @@ func TestFetch(t *testing.T) { events[0].BeatEvent("haproxy", "info").Fields.StringToPrint()) } -func TestData(t *testing.T) { - compose.EnsureUp(t, "phpfpm") - f := mbtest.NewReportingMetricSetV2(t, getConfig()) - err := mbtest.WriteEventsReporterV2(f, t, "") - if err != nil { - t.Fatal("write", err) - } -} func getConfig() map[string]interface{} { return map[string]interface{}{ diff --git a/metricbeat/module/php_fpm/process/_meta/data.json b/metricbeat/module/php_fpm/process/_meta/data.json index 612fa24f87f2..ff5a2cf35893 100644 --- a/metricbeat/module/php_fpm/process/_meta/data.json +++ b/metricbeat/module/php_fpm/process/_meta/data.json @@ -1,9 +1,5 @@ { - "@timestamp": "2017-10-12T08:05:34.853Z", - "agent": { - "hostname": "host.example.com", - "name": "host.example.com" - }, + "@timestamp": "2019-03-01T08:05:34.853Z", "event": { "dataset": "php_fpm.process", "duration": 115000, @@ -28,24 +24,24 @@ }, "process": { "last_request_cpu": 0, - "last_request_memory": 2097152, - "request_duration": 204, - "requests": 6, + "last_request_memory": 0, + "request_duration": 135, + "requests": 9, "script": "-", - "start_since": 128, - "start_time": 1548769887, - "state": "Idle" + "start_since": 3471, + "start_time": 1551792028, + "state": "Running" } }, "process": { - "pid": 17 + "pid": 24 }, "service": { - "address": "127.0.0.1:81", + "address": "127.0.0.1:55555", "type": "php_fpm" }, "url": { - "original": "/status?full=\u0026json=" + "original": "/status?full\u0026json" }, "user": { "name": "-" diff --git a/metricbeat/module/php_fpm/process/_meta/testdata/config.yml b/metricbeat/module/php_fpm/process/_meta/testdata/config.yml new file mode 100644 index 000000000000..1c6cb1189d16 --- /dev/null +++ b/metricbeat/module/php_fpm/process/_meta/testdata/config.yml @@ -0,0 +1,2 @@ +type: http +url: "/status?full=&json=" diff --git a/metricbeat/module/php_fpm/process/_meta/testdata/docs.json b/metricbeat/module/php_fpm/process/_meta/testdata/docs.json new file mode 100644 index 000000000000..0965497a01cd --- /dev/null +++ b/metricbeat/module/php_fpm/process/_meta/testdata/docs.json @@ -0,0 +1 @@ +{"pool":"www","process manager":"dynamic","start time":1551792028,"start since":3471,"accepted conn":17,"listen queue":0,"max listen queue":0,"listen queue len":0,"idle processes":1,"active processes":1,"total processes":2,"max active processes":1,"max children reached":0,"slow requests":0, "processes":[{"pid":24,"state":"Running","start time":1551792028,"start since":3471,"requests":9,"request duration":135,"request method":"GET","request uri":"/status?full&json","content length":0,"user":"-","script":"-","last request cpu":0.00,"last request memory":0},{"pid":25,"state":"Idle","start time":1551792028,"start since":3471,"requests":8,"request duration":811,"request method":"GET","request uri":"/status?full","content length":0,"user":"-","script":"-","last request cpu":0.00,"last request memory":2097152}]} diff --git a/metricbeat/module/php_fpm/process/_meta/testdata/docs.json-expected.json b/metricbeat/module/php_fpm/process/_meta/testdata/docs.json-expected.json new file mode 100644 index 000000000000..308b0cf64dcf --- /dev/null +++ b/metricbeat/module/php_fpm/process/_meta/testdata/docs.json-expected.json @@ -0,0 +1,98 @@ +[ + { + "event": { + "dataset": "php_fpm.process", + "duration": 115000, + "module": "php_fpm" + }, + "http": { + "request": { + "method": "get" + }, + "response": { + "body": { + "bytes": 0 + } + } + }, + "metricset": { + "name": "process" + }, + "php_fpm": { + "pool": { + "name": "www" + }, + "process": { + "last_request_cpu": 0, + "last_request_memory": 0, + "request_duration": 135, + "requests": 9, + "script": "-", + "start_since": 3471, + "start_time": 1551792028, + "state": "Running" + } + }, + "process": { + "pid": 24 + }, + "service": { + "address": "127.0.0.1:55555", + "type": "php_fpm" + }, + "url": { + "original": "/status?full\u0026json" + }, + "user": { + "name": "-" + } + }, + { + "event": { + "dataset": "php_fpm.process", + "duration": 115000, + "module": "php_fpm" + }, + "http": { + "request": { + "method": "get" + }, + "response": { + "body": { + "bytes": 0 + } + } + }, + "metricset": { + "name": "process" + }, + "php_fpm": { + "pool": { + "name": "www" + }, + "process": { + "last_request_cpu": 0, + "last_request_memory": 2097152, + "request_duration": 811, + "requests": 8, + "script": "-", + "start_since": 3471, + "start_time": 1551792028, + "state": "Idle" + } + }, + "process": { + "pid": 25 + }, + "service": { + "address": "127.0.0.1:55555", + "type": "php_fpm" + }, + "url": { + "original": "/status?full" + }, + "user": { + "name": "-" + } + } +] \ No newline at end of file diff --git a/metricbeat/module/php_fpm/process/process_integration_test.go b/metricbeat/module/php_fpm/process/process_integration_test.go index 6894b2c0e96f..a523648c9adf 100644 --- a/metricbeat/module/php_fpm/process/process_integration_test.go +++ b/metricbeat/module/php_fpm/process/process_integration_test.go @@ -45,15 +45,6 @@ func TestFetch(t *testing.T) { } -func TestData(t *testing.T) { - compose.EnsureUp(t, "phpfpm") - f := mbtest.NewReportingMetricSetV2(t, getConfig()) - err := mbtest.WriteEventsReporterV2(f, t, ".") - if err != nil { - t.Fatal("write", err) - } -} - func getConfig() map[string]interface{} { return map[string]interface{}{ "module": "php_fpm",