Skip to content

Commit

Permalink
api: Fix the api to ensure it works correctly. (#256)
Browse files Browse the repository at this point in the history
close #255
  • Loading branch information
nolouch authored Aug 5, 2024
1 parent 4c8307f commit 71c1639
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions service/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,36 @@ func ServeHTTP(l *config.Log, listener net.Listener) {
promGroup.Any("", func(c *gin.Context) {
promHandler.ServeHTTP(c.Writer, c.Request)
})

wh := &wrapHeander{ngHanlder: ng}
// compatible with victoria-metrics handlers
ng.NoRoute(func(c *gin.Context) {
handlerNoRouter(c)
})
httpServer = &http.Server{
Handler: wh,
Handler: ng,
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) {
// Try Victoria-Metrics' handlers first. If not handled, then return a 404 error.
func handlerNoRouter(c *gin.Context) {
//reset to default
c.Writer.WriteHeader(http.StatusOK)
if vminsert.RequestHandler(c.Writer, c.Request) {
return
}
if vmselect.RequestHandler(w, r) {

if vmselect.RequestHandler(c.Writer, c.Request) {
return
}
if vmstorage.RequestHandler(w, r) {

if vmstorage.RequestHandler(c.Writer, c.Request) {
return
}
wrap.ngHanlder.ServeHTTP(w, r)

c.String(http.StatusNotFound, "404 page not found")
}

type Status struct {
Expand Down

0 comments on commit 71c1639

Please sign in to comment.