Allow globs in FPM unix socket paths (#7089)
This commit is contained in:
@@ -148,6 +148,71 @@ func TestPhpFpmGeneratesMetrics_From_Socket(t *testing.T) {
|
||||
acc.AssertContainsTaggedFields(t, "phpfpm", fields, tags)
|
||||
}
|
||||
|
||||
func TestPhpFpmGeneratesMetrics_From_Multiple_Sockets_With_Glob(t *testing.T) {
|
||||
// Create a socket in /tmp because we always have write permission and if the
|
||||
// removing of socket fail when system restart /tmp is clear so
|
||||
// we don't have junk files around
|
||||
var randomNumber int64
|
||||
binary.Read(rand.Reader, binary.LittleEndian, &randomNumber)
|
||||
socket1 := fmt.Sprintf("/tmp/test-fpm%d.sock", randomNumber)
|
||||
tcp1, err := net.Listen("unix", socket1)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot initialize server on port ")
|
||||
}
|
||||
defer tcp1.Close()
|
||||
|
||||
binary.Read(rand.Reader, binary.LittleEndian, &randomNumber)
|
||||
socket2 := fmt.Sprintf("/tmp/test-fpm%d.sock", randomNumber)
|
||||
tcp2, err := net.Listen("unix", socket2)
|
||||
if err != nil {
|
||||
t.Fatal("Cannot initialize server on port ")
|
||||
}
|
||||
defer tcp2.Close()
|
||||
|
||||
s := statServer{}
|
||||
go fcgi.Serve(tcp1, s)
|
||||
go fcgi.Serve(tcp2, s)
|
||||
|
||||
r := &phpfpm{
|
||||
Urls: []string{"/tmp/test-fpm[\\-0-9]*.sock"},
|
||||
}
|
||||
|
||||
var acc1, acc2 testutil.Accumulator
|
||||
|
||||
err = acc1.GatherError(r.Gather)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = acc2.GatherError(r.Gather)
|
||||
require.NoError(t, err)
|
||||
|
||||
tags1 := map[string]string{
|
||||
"pool": "www",
|
||||
"url": socket1,
|
||||
}
|
||||
|
||||
tags2 := map[string]string{
|
||||
"pool": "www",
|
||||
"url": socket2,
|
||||
}
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"start_since": int64(1991),
|
||||
"accepted_conn": int64(3),
|
||||
"listen_queue": int64(1),
|
||||
"max_listen_queue": int64(0),
|
||||
"listen_queue_len": int64(0),
|
||||
"idle_processes": int64(1),
|
||||
"active_processes": int64(1),
|
||||
"total_processes": int64(2),
|
||||
"max_active_processes": int64(1),
|
||||
"max_children_reached": int64(2),
|
||||
"slow_requests": int64(1),
|
||||
}
|
||||
|
||||
acc1.AssertContainsTaggedFields(t, "phpfpm", fields, tags1)
|
||||
acc2.AssertContainsTaggedFields(t, "phpfpm", fields, tags2)
|
||||
}
|
||||
|
||||
func TestPhpFpmGeneratesMetrics_From_Socket_Custom_Status_Path(t *testing.T) {
|
||||
// Create a socket in /tmp because we always have write permission. If the
|
||||
// removing of socket fail we won't have junk files around. Cuz when system
|
||||
@@ -227,7 +292,7 @@ func TestPhpFpmGeneratesMetrics_Throw_Error_When_Socket_Path_Is_Invalid(t *testi
|
||||
|
||||
err := acc.GatherError(r.Gather)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, `Socket doesn't exist '/tmp/invalid.sock': stat /tmp/invalid.sock: no such file or directory`, err.Error())
|
||||
assert.Equal(t, `dial unix /tmp/invalid.sock: connect: no such file or directory`, err.Error())
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user