| 1 | package features |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | "time" |
| 7 | |
| 8 | "github.com/onsi/ginkgo/v2" |
| 9 | |
| 10 | "github.com/fatedier/frp/pkg/util/log" |
| 11 | "github.com/fatedier/frp/test/e2e/framework" |
| 12 | "github.com/fatedier/frp/test/e2e/framework/consts" |
| 13 | "github.com/fatedier/frp/test/e2e/pkg/request" |
| 14 | ) |
| 15 | |
| 16 | var _ = ginkgo.Describe("[Feature: Monitor]", func() { |
| 17 | f := framework.NewDefaultFramework() |
| 18 | |
| 19 | ginkgo.It("Prometheus metrics", func() { |
| 20 | dashboardPort := f.AllocPort() |
| 21 | serverConf := consts.LegacyDefaultServerConfig + fmt.Sprintf(` |
| 22 | enable_prometheus = true |
| 23 | dashboard_addr = 0.0.0.0 |
| 24 | dashboard_port = %d |
| 25 | `, dashboardPort) |
| 26 | |
| 27 | clientConf := consts.LegacyDefaultClientConfig |
| 28 | remotePort := f.AllocPort() |
| 29 | clientConf += fmt.Sprintf(` |
| 30 | [tcp] |
| 31 | type = tcp |
| 32 | local_port = {{ .%s }} |
| 33 | remote_port = %d |
| 34 | `, framework.TCPEchoServerPort, remotePort) |
| 35 | |
| 36 | f.RunProcesses(serverConf, []string{clientConf}) |
| 37 | |
| 38 | framework.NewRequestExpect(f).Port(remotePort).Ensure() |
| 39 | time.Sleep(500 * time.Millisecond) |
| 40 | |
| 41 | framework.NewRequestExpect(f).RequestModify(func(r *request.Request) { |
| 42 | r.HTTP().Port(dashboardPort).HTTPPath("/metrics") |
| 43 | }).Ensure(func(resp *request.Response) bool { |
| 44 | log.Tracef("prometheus metrics response: \n%s", resp.Content) |
| 45 | if resp.Code != 200 { |
| 46 | return false |
| 47 | } |
| 48 | if !strings.Contains(string(resp.Content), "traffic_in") { |
| 49 | return false |
| 50 | } |
| 51 | return true |
| 52 | }) |
| 53 | }) |
| 54 | }) |