Skip to content

Commit

Permalink
*: add victoriametrics API (#249)
Browse files Browse the repository at this point in the history
close #248
  • Loading branch information
nolouch authored Jun 20, 2024
1 parent 1f1d885 commit 4c8307f
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 4c8307f

Please sign in to comment.