From 5184fdbe5c634890c98f4c61fcaae2760cf1d371 Mon Sep 17 00:00:00 2001 From: Shuning Chen Date: Mon, 17 Jun 2024 19:32:15 +0800 Subject: [PATCH] *: add victoriametrics API Signed-off-by: Shuning Chen --- service/http/http.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/service/http/http.go b/service/http/http.go index 2e8b6c0..9360c5a 100644 --- a/service/http/http.go +++ b/service/http/http.go @@ -7,6 +7,9 @@ import ( "path" "time" + "github.com/VictoriaMetrics/VictoriaMetrics/app/vminsert" + "github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect" + "github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage" conprofhttp "github.com/pingcap/ng-monitoring/component/conprof/http" "github.com/pingcap/ng-monitoring/component/topsql" "github.com/pingcap/ng-monitoring/config" @@ -63,8 +66,9 @@ func ServeHTTP(l *config.Log, listener net.Listener) { promHandler.ServeHTTP(c.Writer, c.Request) }) + wh := &wrapHeander{ngHanlder: ng} httpServer = &http.Server{ - Handler: ng, + Handler: wh, ReadHeaderTimeout: 5 * time.Second, } if err = httpServer.Serve(listener); err != nil && err != http.ErrServerClosed { @@ -72,6 +76,23 @@ func ServeHTTP(l *config.Log, listener net.Listener) { } } +type wrapHeander struct { + ngHanlder http.Handler +} + +func (wrap *wrapHeander) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if vminsert.RequestHandler(w, r) { + return + } + if vmselect.RequestHandler(w, r) { + return + } + if vmstorage.RequestHandler(w, r) { + return + } + wrap.ngHanlder.ServeHTTP(w, r) +} + type Status struct { Health bool `json:"health"` }