Skip to content

Commit

Permalink
[Metricbeat] Add http endpoint tests for php_fpm module (#11088)
Browse files Browse the repository at this point in the history
This change is based on #10648 to migrate to golden files instead of the dynamically generated data files.

This adds also support for query params to the testing framework.
  • Loading branch information
ruflin authored Mar 6, 2019
1 parent aac95c1 commit af9e048
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 41 deletions.
10 changes: 9 additions & 1 deletion metricbeat/mb/testing/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 5 additions & 9 deletions metricbeat/module/php_fpm/pool/_meta/data.json
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -15,7 +11,7 @@
"php_fpm": {
"pool": {
"connections": {
"accepted": 10,
"accepted": 18,
"listen_queue_len": 0,
"max_listen_queue": 0,
"queued": 0
Expand All @@ -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"
}
}
2 changes: 2 additions & 0 deletions metricbeat/module/php_fpm/pool/_meta/testdata/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: http
url: "/status?json="
1 change: 1 addition & 0 deletions metricbeat/module/php_fpm/pool/_meta/testdata/docs.json
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
8 changes: 0 additions & 8 deletions metricbeat/module/php_fpm/pool/pool_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down
24 changes: 10 additions & 14 deletions metricbeat/module/php_fpm/process/_meta/data.json
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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": "-"
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/module/php_fpm/process/_meta/testdata/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type: http
url: "/status?full=&json="
1 change: 1 addition & 0 deletions metricbeat/module/php_fpm/process/_meta/testdata/docs.json
Original file line number Diff line number Diff line change
@@ -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}]}
Original file line number Diff line number Diff line change
@@ -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": "-"
}
}
]
9 changes: 0 additions & 9 deletions metricbeat/module/php_fpm/process/process_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit af9e048

Please sign in to comment.