Skip to content

Commit

Permalink
move the redact-debug-ui and querylog-format flags into streamlog
Browse files Browse the repository at this point in the history
As suggested by sougou, the servenv package is too generic for these
flags which are actually just specific to vttablet and vtgate in the
future, so move them to the streamlog package instead.
  • Loading branch information
demmer committed Dec 21, 2017
1 parent 12984a5 commit 0a7818b
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 37 deletions.
7 changes: 7 additions & 0 deletions go/streamlog/streamlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package streamlog

import (
"flag"
"fmt"
"io"
"net/http"
Expand All @@ -33,6 +34,12 @@ import (
)

var (
// RedactDebugUIQueries controls whether full queries and bind variables are suppressed from debug UIs.
RedactDebugUIQueries = flag.Bool("redact-debug-ui-queries", false, "redact full queries and bind variables from debug UI")

// QueryLogFormat controls the format of the query log (either text or json)
QueryLogFormat = flag.String("querylog-format", "text", "format for query logs (\"text\" or \"json\")")

sendCount = stats.NewCounters("StreamlogSend")
deliveredCount = stats.NewMultiCounters("StreamlogDelivered", []string{"Log", "Subscriber"})
deliveryDropCount = stats.NewMultiCounters("StreamlogDeliveryDroppedMessages", []string{"Log", "Subscriber"})
Expand Down
13 changes: 0 additions & 13 deletions go/vt/servenv/servenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ var (
onTermTimeout = flag.Duration("onterm_timeout", 10*time.Second, "wait no more than this for OnTermSync handlers before stopping")
memProfileRate = flag.Int("mem-profile-rate", 512*1024, "profile every n bytes allocated")

// RedactDebugUIQueries controls whether full queries and bind variables are suppressed from debug UIs.
RedactDebugUIQueries = flag.Bool("redact-debug-ui-queries", false, "redact full queries and bind variables from debug UI")

// QueryLogFormat controls the format of the query log (either text or json)
QueryLogFormat = flag.String("querylog-format", "text", "format for query logs (\"text\" or \"json\")")

// mutex used to protect the Init function
mu sync.Mutex

Expand Down Expand Up @@ -92,13 +86,6 @@ func Init() {
log.Exitf("servenv.Init: running this as root makes no sense")
}

switch *QueryLogFormat {
case "text":
case "json":
default:
log.Exitf("servenv.Init: Invalid querylog-format value %v: must be either text or json")
}

runtime.MemProfileRate = *memProfileRate

// We used to set this limit directly, but you pretty much have to
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vttablet/filelogger/filelogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"
"time"

"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/vt/vttablet/tabletserver/tabletenv"
)

Expand Down Expand Up @@ -72,9 +72,9 @@ func TestFileLog(t *testing.T) {

// TestFileLog sends a stream of five query records to the plugin, and verifies that they are logged.
func TestFileLogRedacted(t *testing.T) {
*servenv.RedactDebugUIQueries = true
*streamlog.RedactDebugUIQueries = true
defer func() {
*servenv.RedactDebugUIQueries = false
*streamlog.RedactDebugUIQueries = false
}()

dir, err := ioutil.TempDir("", "filelogger_test")
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vttablet/sysloglogger/sysloglogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"golang.org/x/net/context"

"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/vt/vttablet/tabletserver/tabletenv"
)

Expand Down Expand Up @@ -141,9 +141,9 @@ func TestSyslog(t *testing.T) {
// when redaction is enabled.
func TestSyslogRedacted(t *testing.T) {
// Overwrite the usual syslog writer and StatsLogger subscription channel with mocks
*servenv.RedactDebugUIQueries = true
*streamlog.RedactDebugUIQueries = true
defer func() {
*servenv.RedactDebugUIQueries = false
*streamlog.RedactDebugUIQueries = false
}()
mock := newFakeWriter()
writer = mock
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/tabletserver/query_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import (
"github.com/youtube/vitess/go/cache"
"github.com/youtube/vitess/go/mysql"
"github.com/youtube/vitess/go/stats"
"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/sync2"
"github.com/youtube/vitess/go/trace"
"github.com/youtube/vitess/go/vt/dbconfigs"
"github.com/youtube/vitess/go/vt/dbconnpool"
"github.com/youtube/vitess/go/vt/logutil"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/sqlparser"
"github.com/youtube/vitess/go/vt/tableacl"
tacl "github.com/youtube/vitess/go/vt/tableacl/acl"
Expand Down Expand Up @@ -557,7 +557,7 @@ func (qe *QueryEngine) handleHTTPQueryRules(response http.ResponseWriter, reques

// ServeHTTP lists the most recent, cached queries and their count.
func (qe *QueryEngine) handleHTTPConsolidations(response http.ResponseWriter, request *http.Request) {
if *servenv.RedactDebugUIQueries {
if *streamlog.RedactDebugUIQueries {
response.Write([]byte(`
<!DOCTYPE html>
<html>
Expand Down
9 changes: 9 additions & 0 deletions go/vt/vttablet/tabletserver/tabletenv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"fmt"
"time"

log "github.com/golang/glog"

"github.com/golang/protobuf/proto"

"github.com/youtube/vitess/go/flagutil"
Expand Down Expand Up @@ -89,6 +91,13 @@ func init() {

// Init must be called after flag.Parse, and before doing any other operations.
func Init() {
switch *streamlog.QueryLogFormat {
case "text":
case "json":
default:
log.Exitf("Invalid querylog-format value %v: must be either text or json")
}

if *queryLogHandler != "" {
StatsLogger.ServeLogs(*queryLogHandler, streamlog.GetFormatter(StatsLogger))
}
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vttablet/tabletserver/tabletenv/logstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"golang.org/x/net/context"

"github.com/youtube/vitess/go/sqltypes"
"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/vt/callerid"
"github.com/youtube/vitess/go/vt/callinfo"
"github.com/youtube/vitess/go/vt/servenv"

querypb "github.com/youtube/vitess/go/vt/proto/query"
)
Expand Down Expand Up @@ -203,7 +203,7 @@ func (stats *LogStats) Format(params url.Values) string {
rewrittenSQL := "[REDACTED]"
formattedBindVars := "[REDACTED]"

if !*servenv.RedactDebugUIQueries {
if !*streamlog.RedactDebugUIQueries {
_, fullBindParams := params["full"]
rewrittenSQL = stats.RewrittenSQL()
formattedBindVars = stats.FmtBindVariables(fullBindParams)
Expand All @@ -214,7 +214,7 @@ func (stats *LogStats) Format(params url.Values) string {

// Valid options for the QueryLogFormat are text or json
var fmtString string
switch *servenv.QueryLogFormat {
switch *streamlog.QueryLogFormat {
case "text":
fmtString = "%v\t%v\t%v\t'%v'\t'%v'\t%v\t%v\t%.6f\t%v\t%q\t%v\t%v\t%q\t%v\t%.6f\t%.6f\t%v\t%v\t%q\t\n"
case "json":
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vttablet/tabletserver/tabletenv/logstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
"golang.org/x/net/context"

"github.com/youtube/vitess/go/sqltypes"
"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/vt/callinfo"
"github.com/youtube/vitess/go/vt/callinfo/fakecallinfo"
querypb "github.com/youtube/vitess/go/vt/proto/query"
"github.com/youtube/vitess/go/vt/servenv"
)

func TestLogStats(t *testing.T) {
Expand Down Expand Up @@ -71,14 +71,14 @@ func TestLogStatsFormat(t *testing.T) {
t.Errorf("logstats text format: got:\n%q\nwant:\n%q\n", got, want)
}

*servenv.QueryLogFormat = "json"
*streamlog.QueryLogFormat = "json"
got = logStats.Format(url.Values(params))
want = "{\"Method\": \"test\", \"RemoteAddr\": \"\", \"Username\": \"\", \"ImmediateCaller\": \"\", \"Effective Caller\": \"\", \"Start\": \"Jan 1 01:02:03.000000\", \"End\": \"Jan 1 01:02:04.000000\", \"TotalTime\": 1.000000, \"PlanType\": \"\", \"OriginalSQL\": \"sql1\", \"BindVars\": \"map[]\", \"Queries\": 1, \"RewrittenSQL\": \"sql1\", \"QuerySources\": \"mysql\", \"MysqlTime\": 0.000000, \"ConnWaitTime\": 0.000000, \"RowsAffected\": 0, \"ResponseSize\": 1, \"Error\": \"\"}\n"
if got != want {
t.Errorf("logstats text format: got:\n%v\nwant:\n%v\n", got, want)
}

*servenv.QueryLogFormat = "text"
*streamlog.QueryLogFormat = "text"
}

func TestLogStatsFormatBindVariables(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/tabletserver/txlogz.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (

log "github.com/golang/glog"
"github.com/youtube/vitess/go/acl"
"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/vt/callerid"
"github.com/youtube/vitess/go/vt/logz"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/vttablet/tabletserver/tabletenv"

querypb "github.com/youtube/vitess/go/vt/proto/query"
Expand Down Expand Up @@ -86,7 +86,7 @@ func txlogzHandler(w http.ResponseWriter, req *http.Request) {
return
}

if *servenv.RedactDebugUIQueries {
if *streamlog.RedactDebugUIQueries {
io.WriteString(w, `
<!DOCTYPE html>
<html>
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vttablet/tabletserver/txlogz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"testing"
"time"

"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/sync2"
"github.com/youtube/vitess/go/vt/callerid"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/vttablet/tabletserver/tabletenv"
)

Expand Down Expand Up @@ -72,10 +72,10 @@ func testHandler(req *http.Request, t *testing.T) {
tabletenv.TxLogger.Send(txConn)
txlogzHandler(response, req)
testNotRedacted(t, response)
*servenv.RedactDebugUIQueries = true
*streamlog.RedactDebugUIQueries = true
txlogzHandler(response, req)
testRedacted(t, response)
*servenv.RedactDebugUIQueries = false
*streamlog.RedactDebugUIQueries = false

}

Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/tabletserver/txserializer/tx_serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (

"github.com/youtube/vitess/go/acl"
"github.com/youtube/vitess/go/stats"
"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/sync2"
"github.com/youtube/vitess/go/vt/logutil"
"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/vterrors"

vtrpcpb "github.com/youtube/vitess/go/vt/proto/vtrpc"
Expand Down Expand Up @@ -282,7 +282,7 @@ func (t *TxSerializer) Pending(key string) int {

// ServeHTTP lists the most recent, cached queries and their count.
func (t *TxSerializer) ServeHTTP(response http.ResponseWriter, request *http.Request) {
if *servenv.RedactDebugUIQueries {
if *streamlog.RedactDebugUIQueries {
response.Write([]byte(`
<!DOCTYPE html>
<html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"golang.org/x/net/context"

"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/streamlog"
"github.com/youtube/vitess/go/vt/vterrors"

vtrpcpb "github.com/youtube/vitess/go/vt/proto/vtrpc"
Expand Down Expand Up @@ -67,9 +67,9 @@ func TestTxSerializer_NoHotRow(t *testing.T) {

func TestTxSerializerRedactDebugUI(t *testing.T) {
resetVariables()
*servenv.RedactDebugUIQueries = true
*streamlog.RedactDebugUIQueries = true
defer func() {
*servenv.RedactDebugUIQueries = false
*streamlog.RedactDebugUIQueries = false
}()

txs := New(false, 1, 1, 5)
Expand Down

0 comments on commit 0a7818b

Please sign in to comment.