From 322bb70f02b75621506067ab838ad4e3e42f9014 Mon Sep 17 00:00:00 2001 From: yusing Date: Fri, 13 Feb 2026 22:12:19 +0800 Subject: [PATCH] feat(monitor): add display name support for health monitor logging Add a DisplayNameKey struct to pass display names from routes through the task parent hierarchy to the health monitor. This allows the health monitor to use more descriptive names for logging instead of internal task names. BREAKING CHANGE: The monitor.DisplayNameKey struct is now part of the public API --- internal/health/monitor/monitor.go | 8 +++++++- internal/route/fileserver.go | 1 + internal/route/reverse_proxy.go | 1 + internal/route/route.go | 1 + internal/route/stream.go | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/health/monitor/monitor.go b/internal/health/monitor/monitor.go index 3effb0d8..13213bb7 100644 --- a/internal/health/monitor/monitor.go +++ b/internal/health/monitor/monitor.go @@ -21,6 +21,8 @@ import ( ) type ( + DisplayNameKey struct{} + HealthCheckFunc func(url *url.URL) (result types.HealthCheckResult, err error) monitor struct { service string @@ -85,9 +87,13 @@ func (mon *monitor) Start(parent task.Parent) error { return ErrNegativeInterval } - mon.service = parent.Name() mon.task = parent.Subtask("health_monitor", true) + mon.service = parent.Name() + if displayName, ok := parent.GetValue(DisplayNameKey{}).(string); ok { + mon.service = displayName + } + go func() { logger := log.With().Str("name", mon.service).Logger() diff --git a/internal/route/fileserver.go b/internal/route/fileserver.go index e3a6cc10..169d3eca 100644 --- a/internal/route/fileserver.go +++ b/internal/route/fileserver.go @@ -80,6 +80,7 @@ func NewFileServer(base *Route) (*FileServer, error) { // Start implements task.TaskStarter. func (s *FileServer) Start(parent task.Parent) error { s.task = parent.Subtask("fileserver."+s.Name(), false) + s.task.SetValue(monitor.DisplayNameKey{}, s.DisplayName()) pathPatterns := s.PathPatterns switch { diff --git a/internal/route/reverse_proxy.go b/internal/route/reverse_proxy.go index 0fc29dcd..7264244c 100755 --- a/internal/route/reverse_proxy.go +++ b/internal/route/reverse_proxy.go @@ -126,6 +126,7 @@ func (r *ReveseProxyRoute) ReverseProxy() *reverseproxy.ReverseProxy { // Start implements task.TaskStarter. func (r *ReveseProxyRoute) Start(parent task.Parent) error { r.task = parent.Subtask("http."+r.Name(), false) + r.task.SetValue(monitor.DisplayNameKey{}, r.DisplayName()) switch { case r.UseIdleWatcher(): diff --git a/internal/route/route.go b/internal/route/route.go index 1c233644..1260e0eb 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -514,6 +514,7 @@ func (r *Route) start(parent task.Parent) error { } r.task = parent.Subtask("excluded."+r.Name(), false) + r.task.SetValue(monitor.DisplayNameKey{}, r.DisplayName()) ep.ExcludedRoutes().Add(r.impl) r.task.OnCancel("remove_route_from_excluded", func() { ep.ExcludedRoutes().Del(r.impl) diff --git a/internal/route/stream.go b/internal/route/stream.go index 00282b72..cdaa6158 100755 --- a/internal/route/stream.go +++ b/internal/route/stream.go @@ -47,6 +47,7 @@ func (r *StreamRoute) Start(parent task.Parent) error { r.stream = stream r.task = parent.Subtask("stream."+r.Name(), !r.ShouldExclude()) + r.task.SetValue(monitor.DisplayNameKey{}, r.DisplayName()) switch { case r.UseIdleWatcher():