-
Notifications
You must be signed in to change notification settings - Fork 726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scheduler: add debug log #907
Changes from 8 commits
b34289e
0a2255a
a3b2e5b
3ec9aba
9f92af1
9b7754e
bd4b5a8
0858b95
ff975d6
e61ef23
3bc9446
452c693
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2018 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package command | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
logPrefix = "pd/api/v1/log" | ||
) | ||
|
||
// NewLogCommand New a log subcommand of the rootCmd | ||
func NewLogCommand() *cobra.Command { | ||
conf := &cobra.Command{ | ||
Use: "log [fatal|error|warn|info|debug]", | ||
Short: "set log level", | ||
Run: logCommandFunc, | ||
} | ||
return conf | ||
} | ||
|
||
func logCommandFunc(cmd *cobra.Command, args []string) { | ||
var err error | ||
if len(args) != 1 { | ||
fmt.Println(cmd.UsageString()) | ||
return | ||
} | ||
|
||
data, err := json.Marshal(args[0]) | ||
if err != nil { | ||
fmt.Printf("Failed to set log level: %s\n", err) | ||
return | ||
} | ||
req, err := getRequest(cmd, logPrefix, http.MethodPost, "application/json", bytes.NewBuffer(data)) | ||
if err != nil { | ||
fmt.Printf("Failed to set log level: %s\n", err) | ||
return | ||
} | ||
_, err = dail(req) | ||
if err != nil { | ||
fmt.Printf("Failed to set log level: %s\n", err) | ||
return | ||
} | ||
fmt.Println("Success!") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2018 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
"github.com/pingcap/pd/pkg/logutil" | ||
"github.com/pingcap/pd/server" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/unrolled/render" | ||
) | ||
|
||
type logHandler struct { | ||
svr *server.Server | ||
rd *render.Render | ||
} | ||
|
||
func newlogHandler(svr *server.Server, rd *render.Render) *logHandler { | ||
return &logHandler{ | ||
svr: svr, | ||
rd: rd, | ||
} | ||
} | ||
|
||
func (h *logHandler) Handle(w http.ResponseWriter, r *http.Request) { | ||
var level string | ||
data, err := ioutil.ReadAll(r.Body) | ||
r.Body.Close() | ||
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
err = json.Unmarshal(data, &level) | ||
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
return | ||
} | ||
|
||
h.svr.SetLogLevel(level) | ||
log.SetLevel(logutil.StringToLogLevel(level)) | ||
|
||
h.rd.JSON(w, http.StatusOK, nil) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ func scheduleTransferLeader(cluster schedule.Cluster, schedulerName string, s sc | |
|
||
mostLeaderStore := s.SelectSource(cluster, stores, filters...) | ||
leastLeaderStore := s.SelectTarget(cluster, stores, filters...) | ||
log.Debugf("[%s] mostLeaderStore is %v, leastLeaderStore is %v", schedulerName, mostLeaderStore, leastLeaderStore) | ||
|
||
var mostLeaderDistance, leastLeaderDistance float64 | ||
if mostLeaderStore != nil { | ||
|
@@ -47,6 +48,7 @@ func scheduleTransferLeader(cluster schedule.Cluster, schedulerName string, s sc | |
if leastLeaderStore != nil { | ||
leastLeaderDistance = math.Abs(leastLeaderStore.LeaderScore() - averageLeader) | ||
} | ||
log.Debugf("[%s] mostLeaderDistance is %v, leastLeaderDistance is %v", schedulerName, mostLeaderDistance, leastLeaderDistance) | ||
if mostLeaderDistance == 0 && leastLeaderDistance == 0 { | ||
schedulerCounter.WithLabelValues(schedulerName, "already_balanced").Inc() | ||
return nil, nil | ||
|
@@ -63,7 +65,11 @@ func scheduleTransferLeader(cluster schedule.Cluster, schedulerName string, s sc | |
region, peer = scheduleRemoveLeader(cluster, schedulerName, mostLeaderStore.GetId(), s) | ||
} | ||
} | ||
|
||
if region == nil { | ||
log.Debugf("[%v] select no region", schedulerName) | ||
} else { | ||
log.Debugf("[region %v][%v] select %v to be new leader", schedulerName, region.GetId(), peer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the parameter does not correspond. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, I mistake the order |
||
} | ||
return region, peer | ||
} | ||
|
||
|
@@ -173,6 +179,7 @@ func shouldBalance(source, target *core.StoreInfo, avgScore float64, kind core.R | |
sourceScore := source.ResourceScore(kind) | ||
targetScore := target.ResourceScore(kind) | ||
if targetScore >= sourceScore { | ||
log.Debugf("should balance return false cause targetScore %v >= sourceScore %v", targetScore, sourceScore) | ||
return false | ||
} | ||
|
||
|
@@ -183,6 +190,7 @@ func shouldBalance(source, target *core.StoreInfo, avgScore float64, kind core.R | |
sourceSizeDiff := (sourceScore - avgScore) * source.ResourceWeight(kind) | ||
targetSizeDiff := (avgScore - targetScore) * target.ResourceWeight(kind) | ||
|
||
log.Debugf("size diff is %v and region size is %v", math.Min(sourceSizeDiff, targetSizeDiff), float64(region.ApproximateSize)*tolerantRatio) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. region size -> tolerable size?better to indicate region id. |
||
return math.Min(sourceSizeDiff, targetSizeDiff) >= float64(region.ApproximateSize)*tolerantRatio | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%T will output all the fields of the filter, is it ok here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it outputs like "*schedule.excludedFilter"