Skip to content

Commit

Permalink
Merge pull request #135 from kitianFresh/feature/dynamic-klog-level-b…
Browse files Browse the repository at this point in the history
…y-http-serve

dynamic change the klog loglevel by http for easiler debug
  • Loading branch information
qmhu authored Feb 15, 2022
2 parents 945b000 + 23c15a4 commit 5d661ce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,6 @@ github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.1.0-rc.5 h1:QOAag7FoBaBYYHRqzqkhhd8fq5RTubvI4v3Ft/gDVVQ=
github.com/gobwas/ws v1.1.0-rc.5/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
github.com/gocrane/api v0.0.0-20220124113147-be8c412252d3 h1:kUUSM7kQ4jZZC7eHHCrGS4XhbxMbgds2jSPOVStPJo0=
github.com/gocrane/api v0.0.0-20220124113147-be8c412252d3/go.mod h1:RnAori/vZNl5ymrEpyq0FhJ+dyFUfbGaKidzoaoxwy4=
github.com/gocrane/api v0.0.0-20220210031913-ccefc22018e1 h1:4GXNPEXZH0r8P1JwcrCYZbu5G3SuC5LQgImSLHZZLPo=
github.com/gocrane/api v0.0.0-20220210031913-ccefc22018e1/go.mod h1:RnAori/vZNl5ymrEpyq0FhJ+dyFUfbGaKidzoaoxwy4=
github.com/gocrane/api v0.0.0-20220210064400-074bc46801b5 h1:S42iV6iewB12E3WUV0pum45z81TCkuxJmkO4724dMGU=
github.com/gocrane/api v0.0.0-20220210064400-074bc46801b5/go.mod h1:RnAori/vZNl5ymrEpyq0FhJ+dyFUfbGaKidzoaoxwy4=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down Expand Up @@ -726,8 +722,6 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yan234280533/api v0.0.0-20220117025739-a9f8ba724529 h1:eyXVu6ijU0VBgMOw9CkJaa9d5vP1EqOZJtX/4Oopk1A=
github.com/yan234280533/api v0.0.0-20220117025739-a9f8ba724529/go.mod h1:RnAori/vZNl5ymrEpyq0FhJ+dyFUfbGaKidzoaoxwy4=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
7 changes: 6 additions & 1 deletion pkg/controller/timeseriesprediction/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package timeseriesprediction

import (
"context"
"encoding/json"
"fmt"
"sort"
"strings"
Expand Down Expand Up @@ -152,7 +153,11 @@ func (tc *Controller) doPredict(tsPrediction *v1alpha1.TimeSeriesPrediction, sta
return result, err
}
predictedData := CommonTimeSeries2ApiTimeSeries(data)
klog.V(8).Infof("Predicted data details, %+v", predictedData)
if klog.V(6).Enabled() {
apiDataBytes, err1 := json.Marshal(predictedData)
dataBytes, err2 := json.Marshal(data)
klog.V(6).Infof("DoPredict predicted data details, key: %v, queryExpr: %v, apiData: %v, predictData: %v, errs: %+v", klog.KObj(tsPrediction), queryExpr, string(apiDataBytes), string(dataBytes), []error{err1, err2})
}
result = append(result, v1alpha1.PredictionMetricStatus{ResourceIdentifier: metric.ResourceIdentifier, Prediction: predictedData})
}
return result, nil
Expand Down
16 changes: 15 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"flag"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -73,6 +74,19 @@ func (s *apiServer) installGenericAPIs() {
s.GET("/version", func(c *gin.Context) {
ginwrapper.WriteResponse(c, nil, version.GetVersionInfo())
})

s.GET("/klog", func(c *gin.Context) {
v := c.Query("v")
if v != "" {
err := flag.Lookup("v").Value.Set(v)
if err != nil {
ginwrapper.WriteResponse(c, err, nil)
return
}
klog.Infof("set log level to %v", v)
}
ginwrapper.WriteResponse(c, nil, map[string]string{"status": "ok"})
})
}

func (s *apiServer) installDefaultMiddlewares() {
Expand Down Expand Up @@ -119,8 +133,8 @@ func (s *apiServer) initServices() {
func (s *apiServer) Run(ctx context.Context) {
s.initServices()

s.installGenericAPIs()
s.installDefaultMiddlewares()
s.installGenericAPIs()
s.initRouter()

s.startGracefulShutDownManager(ctx)
Expand Down

0 comments on commit 5d661ce

Please sign in to comment.