TUN-6357: Add connector id to ready check endpoint

This commit is contained in:
Devin Carr
2022-06-07 23:09:26 -07:00
parent cc8aa0efb5
commit e3aad7799e
3 changed files with 25 additions and 11 deletions

View File

@@ -5,21 +5,24 @@ import (
"fmt"
"net/http"
"github.com/google/uuid"
"github.com/rs/zerolog"
conn "github.com/cloudflare/cloudflared/connection"
"github.com/cloudflare/cloudflared/tunnelstate"
"github.com/rs/zerolog"
)
// ReadyServer serves HTTP 200 if the tunnel can serve traffic. Intended for k8s readiness checks.
type ReadyServer struct {
tracker *tunnelstate.ConnTracker
clientID uuid.UUID
tracker *tunnelstate.ConnTracker
}
// NewReadyServer initializes a ReadyServer and starts listening for dis/connection events.
func NewReadyServer(log *zerolog.Logger) *ReadyServer {
func NewReadyServer(log *zerolog.Logger, clientID uuid.UUID) *ReadyServer {
return &ReadyServer{
tracker: tunnelstate.NewConnTracker(log),
clientID: clientID,
tracker: tunnelstate.NewConnTracker(log),
}
}
@@ -28,8 +31,9 @@ func (rs *ReadyServer) OnTunnelEvent(c conn.Event) {
}
type body struct {
Status int `json:"status"`
ReadyConnections uint `json:"readyConnections"`
Status int `json:"status"`
ReadyConnections uint `json:"readyConnections"`
ConnectorID uuid.UUID `json:"connectorId"`
}
// ServeHTTP responds with HTTP 200 if the tunnel is connected to the edge.
@@ -39,6 +43,7 @@ func (rs *ReadyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
body := body{
Status: statusCode,
ReadyConnections: readyConnections,
ConnectorID: rs.clientID,
}
msg, err := json.Marshal(body)
if err != nil {