2021-08-02 05:07:28 +00:00
|
|
|
package features
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2021-10-25 12:27:22 +00:00
|
|
|
"time"
|
2021-08-02 05:07:28 +00:00
|
|
|
|
2023-02-27 06:44:16 +00:00
|
|
|
"github.com/onsi/ginkgo/v2"
|
2022-08-28 17:02:53 +00:00
|
|
|
|
2021-08-02 05:07:28 +00:00
|
|
|
"github.com/fatedier/frp/pkg/util/log"
|
|
|
|
"github.com/fatedier/frp/test/e2e/framework"
|
|
|
|
"github.com/fatedier/frp/test/e2e/framework/consts"
|
|
|
|
"github.com/fatedier/frp/test/e2e/pkg/request"
|
|
|
|
)
|
|
|
|
|
2022-08-28 17:02:53 +00:00
|
|
|
var _ = ginkgo.Describe("[Feature: Monitor]", func() {
|
2021-08-02 05:07:28 +00:00
|
|
|
f := framework.NewDefaultFramework()
|
|
|
|
|
2022-08-28 17:02:53 +00:00
|
|
|
ginkgo.It("Prometheus metrics", func() {
|
2021-08-02 05:07:28 +00:00
|
|
|
dashboardPort := f.AllocPort()
|
|
|
|
serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
|
2023-09-13 08:32:39 +00:00
|
|
|
enablePrometheus = true
|
|
|
|
webServer.addr = "0.0.0.0"
|
|
|
|
webServer.port = %d
|
2021-08-02 05:07:28 +00:00
|
|
|
`, dashboardPort)
|
|
|
|
|
|
|
|
clientConf := consts.DefaultClientConfig
|
|
|
|
remotePort := f.AllocPort()
|
|
|
|
clientConf += fmt.Sprintf(`
|
2023-09-13 08:32:39 +00:00
|
|
|
[[proxies]]
|
|
|
|
name = "tcp"
|
|
|
|
type = "tcp"
|
|
|
|
localPort = {{ .%s }}
|
|
|
|
remotePort = %d
|
2021-08-02 05:07:28 +00:00
|
|
|
`, framework.TCPEchoServerPort, remotePort)
|
|
|
|
|
|
|
|
f.RunProcesses([]string{serverConf}, []string{clientConf})
|
|
|
|
|
|
|
|
framework.NewRequestExpect(f).Port(remotePort).Ensure()
|
2021-10-25 12:27:22 +00:00
|
|
|
time.Sleep(500 * time.Millisecond)
|
2021-08-02 05:07:28 +00:00
|
|
|
|
|
|
|
framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
|
|
|
|
r.HTTP().Port(dashboardPort).HTTPPath("/metrics")
|
|
|
|
}).Ensure(func(resp *request.Response) bool {
|
2024-03-12 05:58:53 +00:00
|
|
|
log.Tracef("prometheus metrics response: \n%s", resp.Content)
|
2021-08-02 05:07:28 +00:00
|
|
|
if resp.Code != 200 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !strings.Contains(string(resp.Content), "traffic_in") {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|