Skip to content

Commit

Permalink
*: add victoriametrics API
Browse files Browse the repository at this point in the history
Signed-off-by: Shuning Chen <[email protected]>
  • Loading branch information
Shuning Chen authored and Shuning Chen committed Jun 20, 2024
1 parent 1f1d885 commit 5184fdb
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion service/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -63,15 +66,33 @@ 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 {
log.Warn("failed to serve http service", zap.Error(err))
}
}

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"`
}
Expand Down

0 comments on commit 5184fdb

Please sign in to comment.