mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-29 01:08:56 +01:00
Concurrent history requests could race while publishing a lazily created chart service. Use the same guarded initialization in the constructor and handlers so requests share one service without crossing router boundaries. Add concurrent-call regression coverage and retain tenant-isolation proof under the race detector.
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/api/chartapi"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/monitoring"
|
|
)
|
|
|
|
type routerChartMonitorResolver struct {
|
|
router *Router
|
|
}
|
|
|
|
func (r routerChartMonitorResolver) MonitorForContext(ctx context.Context) *monitoring.Monitor {
|
|
if r.router == nil {
|
|
return nil
|
|
}
|
|
return r.router.getTenantMonitor(ctx)
|
|
}
|
|
|
|
func (r *Router) ensureChartService() *chartapi.Service {
|
|
r.chartServiceOnce.Do(func() {
|
|
if r.chartService == nil {
|
|
r.chartService = chartapi.NewService(routerChartMonitorResolver{router: r})
|
|
}
|
|
})
|
|
return r.chartService
|
|
}
|
|
|
|
func (r *Router) handleCharts(w http.ResponseWriter, req *http.Request) {
|
|
r.ensureChartService().HandleCharts(w, req)
|
|
}
|
|
|
|
func (r *Router) handleWorkloadCharts(w http.ResponseWriter, req *http.Request) {
|
|
r.ensureChartService().HandleWorkloadCharts(w, req)
|
|
}
|
|
|
|
func (r *Router) handleInfrastructureCharts(w http.ResponseWriter, req *http.Request) {
|
|
r.ensureChartService().HandleInfrastructureCharts(w, req)
|
|
}
|
|
|
|
func (r *Router) handleStorageCharts(w http.ResponseWriter, req *http.Request) {
|
|
r.ensureChartService().HandleStorageCharts(w, req)
|
|
}
|