Skip to content

Commit e9a3df1

Browse files
authored
convert libbeat system pprof tests to go (#49505)
1 parent 3a992db commit e9a3df1

File tree

2 files changed

+85
-39
lines changed

2 files changed

+85
-39
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
//go:build integration
19+
20+
package integration
21+
22+
import (
23+
"net/http"
24+
"testing"
25+
"time"
26+
27+
"github.com/stretchr/testify/require"
28+
)
29+
30+
var pprofCfg = `
31+
mockbeat:
32+
name:
33+
queue.mem:
34+
events: 4096
35+
flush.min_events: 8
36+
flush.timeout: 0.1s
37+
output.console:
38+
code.json:
39+
pretty: false
40+
`
41+
42+
func TestHttpPProfIndex(t *testing.T) {
43+
mockbeat := NewBeat(t, "mockbeat", "../../libbeat.test",
44+
"-E", "http.enabled=true",
45+
"-E", "http.pprof.enabled=true",
46+
)
47+
mockbeat.WriteConfigFile(pprofCfg)
48+
mockbeat.Start()
49+
mockbeat.WaitLogsContains("Starting stats endpoint", 60*time.Second)
50+
51+
r, err := http.Get("http://localhost:5066/debug/pprof/") //nolint:noctx // fine for tests
52+
require.NoError(t, err)
53+
_ = r.Body.Close()
54+
require.Equal(t, http.StatusOK, r.StatusCode, "incorrect status code")
55+
}
56+
57+
func TestHttpPProfCmdline(t *testing.T) {
58+
mockbeat := NewBeat(t, "mockbeat", "../../libbeat.test",
59+
"-E", "http.enabled=true",
60+
"-E", "http.pprof.enabled=true",
61+
)
62+
mockbeat.WriteConfigFile(pprofCfg)
63+
mockbeat.Start()
64+
mockbeat.WaitLogsContains("Starting stats endpoint", 60*time.Second)
65+
66+
r, err := http.Get("http://localhost:5066/debug/pprof/cmdline") //nolint:noctx // fine for tests
67+
require.NoError(t, err)
68+
_ = r.Body.Close()
69+
require.Equal(t, http.StatusOK, r.StatusCode, "incorrect status code")
70+
}
71+
72+
func TestHttpPProfNotFound(t *testing.T) {
73+
mockbeat := NewBeat(t, "mockbeat", "../../libbeat.test",
74+
"-E", "http.enabled=true",
75+
"-E", "http.pprof.enabled=true",
76+
)
77+
mockbeat.WriteConfigFile(pprofCfg)
78+
mockbeat.Start()
79+
mockbeat.WaitLogsContains("Starting stats endpoint", 60*time.Second)
80+
81+
r, err := http.Get("http://localhost:5066/debug/pprof/not-exist") //nolint:noctx // fine for tests
82+
require.NoError(t, err)
83+
_ = r.Body.Close()
84+
require.Equal(t, http.StatusNotFound, r.StatusCode, "incorrect status code")
85+
}

libbeat/tests/system/test_http_pprof.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)