@@ -26,13 +26,14 @@ import (
2626 "github.com/gin-gonic/gin"
2727 prometheus "github.com/prometheus/client_golang/prometheus/promhttp"
2828
29+ "github.com/arangodb/kube-arangodb/pkg/logging"
2930 "github.com/arangodb/kube-arangodb/pkg/util/errors"
3031 operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http"
3132 "github.com/arangodb/kube-arangodb/pkg/util/probe"
3233 "github.com/arangodb/kube-arangodb/pkg/version"
3334)
3435
35- func buildHTTPHandler (cfg ServerConfig , auth * authorization ) (http.Handler , error ) {
36+ func buildHTTPHandler (s * Server , cfg ServerConfig , auth * authorization ) (http.Handler , error ) {
3637 gin .SetMode (gin .ReleaseMode )
3738 r := gin .New ()
3839 r .Use (gin .Recovery ())
@@ -61,6 +62,8 @@ func buildHTTPHandler(cfg ServerConfig, auth *authorization) (http.Handler, erro
6162 r .GET ("/ready" , gin .WrapF (handleGetReady (readyProbes ... )))
6263
6364 r .GET ("/metrics" , auth .ensureHTTPAuth , gin .WrapH (prometheus .Handler ()))
65+ r .GET ("/log/level" , auth .ensureHTTPAuth , s .handleGetLogLevel )
66+ r .POST ("/log/level" , auth .ensureHTTPAuth , s .handlePostLogLevel )
6467
6568 return r , nil
6669}
@@ -77,3 +80,43 @@ func handleGetReady(probes ...*probe.ReadyProbe) func(w http.ResponseWriter, r *
7780 w .WriteHeader (http .StatusOK )
7881 }
7982}
83+
84+ func (s * Server ) handleGetLogLevel (c * gin.Context ) {
85+ logLevels := s .getLogLevelsByTopics ()
86+ topics := make (map [string ]string , len (logLevels ))
87+ for topic , level := range logLevels {
88+ topics [topic ] = level .String ()
89+ }
90+ c .JSON (http .StatusOK , gin.H {
91+ "topics" : topics ,
92+ })
93+ }
94+
95+ func (s * Server ) handlePostLogLevel (c * gin.Context ) {
96+ var req = struct {
97+ Topics map [string ]string `json:"topics"`
98+ }{}
99+
100+ err := c .BindJSON (& req )
101+ if err != nil {
102+ c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {
103+ "msg" : err .Error (),
104+ })
105+ return
106+ }
107+
108+ logLevels := make (map [string ]logging.Level , len (req .Topics ))
109+ for topic , levelStr := range req .Topics {
110+ l , err := logging .ParseLogLevel (levelStr )
111+ if err != nil {
112+ c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {
113+ "msg" : err .Error (),
114+ })
115+ return
116+ }
117+ logLevels [topic ] = l
118+ }
119+
120+ s .setLogLevelsByTopics (logLevels )
121+ c .JSON (http .StatusOK , gin.H {})
122+ }
0 commit comments