TUN-7553: Add flag to enable management diagnostic services

With the new flag --management-diagnostics (an opt-in flag)
cloudflared's will be able to report additional diagnostic information
over the management.argotunnel.com request path.
Additions include the /metrics prometheus endpoint; which is already
bound to a local port via --metrics.
/debug/pprof/(goroutine|heap) are also provided to allow for remotely
retrieving heap information from a running cloudflared connector.
This commit is contained in:
Devin Carr
2023-07-05 13:28:30 -07:00
parent 39847a70f2
commit 8a3eade6d3
6 changed files with 77 additions and 20 deletions

View File

@@ -3,9 +3,13 @@ package management
import (
"context"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/google/uuid"
"github.com/rs/zerolog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -15,9 +19,23 @@ import (
)
var (
noopLogger = zerolog.New(io.Discard)
noopLogger = zerolog.New(io.Discard)
managementHostname = "https://management.argotunnel.com"
)
func TestDisableDiagnosticRoutes(t *testing.T) {
mgmt := New("management.argotunnel.com", false, "1.1.1.1:80", uuid.Nil, "", &noopLogger, nil)
for _, path := range []string{"/metrics", "/debug/pprof/goroutine", "/debug/pprof/heap"} {
t.Run(strings.Replace(path, "/", "_", -1), func(t *testing.T) {
req := httptest.NewRequest("GET", managementHostname+path+"?access_token="+validToken, nil)
recorder := httptest.NewRecorder()
mgmt.ServeHTTP(recorder, req)
resp := recorder.Result()
require.Equal(t, http.StatusNotFound, resp.StatusCode)
})
}
}
func TestReadEventsLoop(t *testing.T) {
sentEvent := EventStartStreaming{
ClientEvent: ClientEvent{Type: StartStreaming},