Skip to content

Commit

Permalink
Don't enable the http endpoint unless used
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Feb 20, 2025
1 parent 1ea5de7 commit fc8c726
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion go/vt/vttablet/tabletmanager/vreplication/vrlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package vreplication
import (
"net/http"
"strconv"
"sync"
"text/template"
"time"

Expand All @@ -35,6 +36,7 @@ var (
vrLogStatsLogger = streamlog.New[*VrLogStats]("VReplication", 50)
vrLogStatsTemplate = template.Must(template.New("vrlog").
Parse("{{.Type}} Event {{.Detail}} {{.LogTime}} {{.DurationNs}}\n"))
enable sync.Once
)

// VrLogStats collects attributes of a vreplication event for logging
Expand All @@ -47,6 +49,9 @@ type VrLogStats struct {
}

func NewVrLogStats(eventType string, startTime time.Time) *VrLogStats {
enable.Do(func() {
enableHttpEndpoint()
})
return &VrLogStats{Type: eventType, StartTime: startTime}
}

Expand All @@ -62,7 +67,7 @@ func (stats *VrLogStats) Send(detail string) {
vrLogStatsLogger.Send(stats)
}

func init() {
func enableHttpEndpoint() {
servenv.HTTPHandleFunc("/debug/vrlog", func(w http.ResponseWriter, r *http.Request) {
ch := vrLogStatsLogger.Subscribe("vrlogstats")
defer vrLogStatsLogger.Unsubscribe(ch)
Expand Down

0 comments on commit fc8c726

Please sign in to comment.