-
Notifications
You must be signed in to change notification settings - Fork 726
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* scheduler: add debug log (#907)
- Loading branch information
1 parent
776bcd9
commit 1a878c9
Showing
11 changed files
with
154 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
log "github.com/Sirupsen/logrus" | ||
"github.com/pingcap/pd/pkg/logutil" | ||
"github.com/pingcap/pd/server" | ||
"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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters