-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
vttablet: debug/env page to change variables in real-time #7189
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1cde63e
vttablet: debug/env initial cut
sougou 557df6d
vttablet: debug/env test PoolSize
sougou 6af21be
vttablet: debug/env add more vars
sougou 1533644
vttablet: debug/env add link to debug/status
sougou a4b5e7e
vttablet: debug/env enforce POST
sougou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,137 @@ | ||
/* | ||
Copyright 2020 The Vitess Authors. | ||
|
||
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, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tabletserver | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"html" | ||
"net/http" | ||
"strconv" | ||
"text/template" | ||
|
||
"vitess.io/vitess/go/acl" | ||
"vitess.io/vitess/go/vt/log" | ||
) | ||
|
||
var ( | ||
debugEnvHeader = []byte(` | ||
<thead><tr> | ||
<th>Variable Name</th> | ||
<th>Value</th> | ||
<th>Action</th> | ||
</tr></thead> | ||
`) | ||
debugEnvRow = template.Must(template.New("debugenv").Parse(` | ||
<tr><form method="POST"> | ||
<td>{{.VarName}}</td> | ||
<td> | ||
<input type="hidden" name="varname" value="{{.VarName}}"></input> | ||
<input type="text" name="value" value="{{.Value}}"></input> | ||
</td> | ||
<td><input type="submit" name="Action" value="Modify"></input></td> | ||
</form></tr> | ||
`)) | ||
) | ||
|
||
type envValue struct { | ||
VarName string | ||
Value string | ||
} | ||
|
||
func debugEnvHandler(tsv *TabletServer, w http.ResponseWriter, r *http.Request) { | ||
if err := acl.CheckAccessHTTP(r, acl.ADMIN); err != nil { | ||
acl.SendError(w, err) | ||
return | ||
} | ||
|
||
var msg string | ||
if r.Method == "POST" { | ||
varname := r.FormValue("varname") | ||
value := r.FormValue("value") | ||
setIntVal := func(f func(int)) { | ||
ival, err := strconv.Atoi(value) | ||
if err != nil { | ||
msg = fmt.Sprintf("Failed setting value for %v: %v", varname, err) | ||
return | ||
} | ||
f(ival) | ||
msg = fmt.Sprintf("Setting %v to: %v", varname, value) | ||
} | ||
switch varname { | ||
case "PoolSize": | ||
setIntVal(tsv.SetPoolSize) | ||
case "StreamPoolSize": | ||
setIntVal(tsv.SetStreamPoolSize) | ||
case "TxPoolSize": | ||
setIntVal(tsv.SetTxPoolSize) | ||
case "QueryCacheCapacity": | ||
setIntVal(tsv.SetQueryPlanCacheCap) | ||
case "MaxResultSize": | ||
setIntVal(tsv.SetMaxResultSize) | ||
case "WarnResultSize": | ||
setIntVal(tsv.SetWarnResultSize) | ||
case "Consolidator": | ||
tsv.SetConsolidatorMode(value) | ||
msg = fmt.Sprintf("Setting %v to: %v", varname, value) | ||
} | ||
} | ||
|
||
var vars []envValue | ||
addIntVar := func(varname string, f func() int) { | ||
vars = append(vars, envValue{ | ||
VarName: varname, | ||
Value: fmt.Sprintf("%v", f()), | ||
}) | ||
} | ||
addIntVar("PoolSize", tsv.PoolSize) | ||
addIntVar("StreamPoolSize", tsv.StreamPoolSize) | ||
addIntVar("TxPoolSize", tsv.TxPoolSize) | ||
addIntVar("QueryCacheCapacity", tsv.QueryPlanCacheCap) | ||
addIntVar("MaxResultSize", tsv.MaxResultSize) | ||
addIntVar("WarnResultSize", tsv.WarnResultSize) | ||
vars = append(vars, envValue{ | ||
VarName: "Consolidator", | ||
Value: tsv.ConsolidatorMode(), | ||
}) | ||
|
||
format := r.FormValue("format") | ||
if format == "json" { | ||
mvars := make(map[string]string) | ||
for _, v := range vars { | ||
mvars[v.VarName] = v.Value | ||
} | ||
w.Header().Set("Content-Type", "application/json") | ||
_ = json.NewEncoder(w).Encode(mvars) | ||
return | ||
} | ||
|
||
// gridTable is reused from twopcz.go. | ||
w.Write(gridTable) | ||
w.Write([]byte("<h3>Internal Variables</h3>\n")) | ||
if msg != "" { | ||
w.Write([]byte(fmt.Sprintf("<b>%s</b><br /><br />\n", html.EscapeString(msg)))) | ||
} | ||
w.Write(startTable) | ||
w.Write(debugEnvHeader) | ||
for _, v := range vars { | ||
if err := debugEnvRow.Execute(w, v); err != nil { | ||
log.Errorf("queryz: couldn't execute template: %v", err) | ||
} | ||
} | ||
w.Write(endTable) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Probably we should reject the request if the method is not POST
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.
I actually rely on this for my tests, by using GET. Is there a reason to disallow? Also, we seem to be allowing it in other places.
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.
I saw that, If you change this, you will have to update the tests.
I think the reason is general HTTP conventions. In theory,
GET
requests could be cached and shouldn't mutate state.I think that ideally, we should stop propagating this pattern. Once people start relying on the get will become even more difficult to change it.