Skip to content

Commit

Permalink
fix low cap bindvars keys; add query log test with binary value which…
Browse files Browse the repository at this point in the history
… breaks JSON

Signed-off-by: Vilius Okockis <[email protected]>
  • Loading branch information
DeathBorn committed Apr 17, 2024
1 parent 65b4bd9 commit a774f11
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
8 changes: 4 additions & 4 deletions go/logstats/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func (log *Logger) appendBVarsJSON(b []byte, bvars map[string]*querypb.BindVaria
b = append(b, ',', ' ')
}
b = strconv.AppendQuote(b, bv.Name)
b = append(b, `: {"type": `...)
b = append(b, `: {"Type": `...)
b = strconv.AppendQuote(b, querypb.Type_name[int32(bv.BVar.Type)])
b = append(b, `, "value": `...)
b = append(b, `, "Value": `...)

if sqltypes.IsIntegral(bv.BVar.Type) || sqltypes.IsFloat(bv.BVar.Type) {
b = append(b, bv.BVar.Value...)
Expand Down Expand Up @@ -101,9 +101,9 @@ func (log *Logger) appendBVarsJSONV2(b []byte, bvars map[string]*querypb.BindVar
b = append(b, ',', ' ')
}
b = strconv.AppendQuote(b, bv.Name)
b = append(b, `: {"type": `...)
b = append(b, `: {"Type": `...)
b = strconv.AppendQuote(b, querypb.Type_name[int32(bv.BVar.Type)])
b = append(b, `, "value": `...)
b = append(b, `, "Value": `...)

if sqltypes.IsIntegral(bv.BVar.Type) || sqltypes.IsFloat(bv.BVar.Type) {
b = append(b, bv.BVar.Value...)
Expand Down
37 changes: 20 additions & 17 deletions go/vt/vtgate/logstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestLogStatsFormat(t *testing.T) {
{ // 0
redact: false,
format: "text",
expected: "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1\"\t{\"intVal\": {\"type\": \"INT64\", \"value\": 1}}\t0\t0\t\"\"\t\"MASTER\"\t\"suuid\"\tfalse\t\"ks1.tbl1,ks2.tbl2\"\t\"db\"\n",
expected: "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1\"\t{\"intVal\": {\"Type\": \"INT64\", \"Value\": 1}}\t0\t0\t\"\"\t\"MASTER\"\t\"suuid\"\tfalse\t\"ks1.tbl1,ks2.tbl2\"\t\"db\"\n",
bindVars: intBindVar,
}, { // 1
redact: true,
Expand All @@ -88,7 +88,7 @@ func TestLogStatsFormat(t *testing.T) {
}, { // 2
redact: false,
format: "json",
expected: "{\"BindVars\":{\"intVal\":{\"type\":\"INT64\",\"value\":1}},\"CommitTime\":0,\"Effective Caller\":\"\",\"End\":\"2017-01-01 01:02:04.000001\",\"Error\":\"\",\"ExecuteTime\":0,\"ImmediateCaller\":\"\",\"InTransaction\":false,\"Keyspace\":\"db\",\"Method\":\"test\",\"PlanTime\":0,\"RemoteAddr\":\"\",\"RowsAffected\":0,\"SQL\":\"sql1\",\"SessionUUID\":\"suuid\",\"ShardQueries\":0,\"Start\":\"2017-01-01 01:02:03.000000\",\"StmtType\":\"\",\"Table\":\"ks1.tbl1,ks2.tbl2\",\"TabletType\":\"MASTER\",\"TotalTime\":1.000001,\"Username\":\"\"}",
expected: "{\"BindVars\":{\"intVal\":{\"Type\":\"INT64\",\"Value\":1}},\"CommitTime\":0,\"Effective Caller\":\"\",\"End\":\"2017-01-01 01:02:04.000001\",\"Error\":\"\",\"ExecuteTime\":0,\"ImmediateCaller\":\"\",\"InTransaction\":false,\"Keyspace\":\"db\",\"Method\":\"test\",\"PlanTime\":0,\"RemoteAddr\":\"\",\"RowsAffected\":0,\"SQL\":\"sql1\",\"SessionUUID\":\"suuid\",\"ShardQueries\":0,\"Start\":\"2017-01-01 01:02:03.000000\",\"StmtType\":\"\",\"Table\":\"ks1.tbl1,ks2.tbl2\",\"TabletType\":\"MASTER\",\"TotalTime\":1.000001,\"Username\":\"\"}",
bindVars: intBindVar,
}, { // 3
redact: true,
Expand All @@ -98,7 +98,7 @@ func TestLogStatsFormat(t *testing.T) {
}, { // 4
redact: false,
format: "text",
expected: "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1\"\t{\"strVal\": {\"type\": \"VARBINARY\", \"value\": \"abc\"}}\t0\t0\t\"\"\t\"MASTER\"\t\"suuid\"\tfalse\t\"ks1.tbl1,ks2.tbl2\"\t\"db\"\n",
expected: "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1\"\t{\"strVal\": {\"Type\": \"VARBINARY\", \"Value\": \"abc\"}}\t0\t0\t\"\"\t\"MASTER\"\t\"suuid\"\tfalse\t\"ks1.tbl1,ks2.tbl2\"\t\"db\"\n",
bindVars: stringBindVar,
}, { // 5
redact: true,
Expand All @@ -108,7 +108,7 @@ func TestLogStatsFormat(t *testing.T) {
}, { // 6
redact: false,
format: "json",
expected: "{\"BindVars\":{\"strVal\":{\"type\":\"VARBINARY\",\"value\":\"abc\"}},\"CommitTime\":0,\"Effective Caller\":\"\",\"End\":\"2017-01-01 01:02:04.000001\",\"Error\":\"\",\"ExecuteTime\":0,\"ImmediateCaller\":\"\",\"InTransaction\":false,\"Keyspace\":\"db\",\"Method\":\"test\",\"PlanTime\":0,\"RemoteAddr\":\"\",\"RowsAffected\":0,\"SQL\":\"sql1\",\"SessionUUID\":\"suuid\",\"ShardQueries\":0,\"Start\":\"2017-01-01 01:02:03.000000\",\"StmtType\":\"\",\"Table\":\"ks1.tbl1,ks2.tbl2\",\"TabletType\":\"MASTER\",\"TotalTime\":1.000001,\"Username\":\"\"}",
expected: "{\"BindVars\":{\"strVal\":{\"Type\":\"VARBINARY\",\"Value\":\"abc\"}},\"CommitTime\":0,\"Effective Caller\":\"\",\"End\":\"2017-01-01 01:02:04.000001\",\"Error\":\"\",\"ExecuteTime\":0,\"ImmediateCaller\":\"\",\"InTransaction\":false,\"Keyspace\":\"db\",\"Method\":\"test\",\"PlanTime\":0,\"RemoteAddr\":\"\",\"RowsAffected\":0,\"SQL\":\"sql1\",\"SessionUUID\":\"suuid\",\"ShardQueries\":0,\"Start\":\"2017-01-01 01:02:03.000000\",\"StmtType\":\"\",\"Table\":\"ks1.tbl1,ks2.tbl2\",\"TabletType\":\"MASTER\",\"TotalTime\":1.000001,\"Username\":\"\"}",
bindVars: stringBindVar,
}, { // 7
redact: true,
Expand Down Expand Up @@ -155,12 +155,12 @@ func TestLogStatsFilter(t *testing.T) {
params := map[string][]string{"full": {}}

got := testFormat(t, logStats, params)
want := "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1 /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"type\": \"INT64\", \"value\": 1}}\t0\t0\t\"\"\t\"\"\t\"\"\tfalse\t\"\"\t\"\"\n"
want := "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1 /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"Type\": \"INT64\", \"Value\": 1}}\t0\t0\t\"\"\t\"\"\t\"\"\tfalse\t\"\"\t\"\"\n"
assert.Equal(t, want, got)

*streamlog.QueryLogFilterTag = "LOG_THIS_QUERY"
got = testFormat(t, logStats, params)
want = "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1 /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"type\": \"INT64\", \"value\": 1}}\t0\t0\t\"\"\t\"\"\t\"\"\tfalse\t\"\"\t\"\"\n"
want = "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1 /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"Type\": \"INT64\", \"Value\": 1}}\t0\t0\t\"\"\t\"\"\t\"\"\tfalse\t\"\"\t\"\"\n"
assert.Equal(t, want, got)

*streamlog.QueryLogFilterTag = "NOT_THIS_QUERY"
Expand All @@ -178,12 +178,12 @@ func TestLogStatsRowThreshold(t *testing.T) {
params := map[string][]string{"full": {}}

got := testFormat(t, logStats, params)
want := "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1 /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"type\": \"INT64\", \"value\": 1}}\t0\t0\t\"\"\t\"\"\t\"\"\tfalse\t\"\"\t\"\"\n"
want := "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1 /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"Type\": \"INT64\", \"Value\": 1}}\t0\t0\t\"\"\t\"\"\t\"\"\tfalse\t\"\"\t\"\"\n"
assert.Equal(t, want, got)

*streamlog.QueryLogRowThreshold = 0
got = testFormat(t, logStats, params)
want = "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1 /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"type\": \"INT64\", \"value\": 1}}\t0\t0\t\"\"\t\"\"\t\"\"\tfalse\t\"\"\t\"\"\n"
want = "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t0.000000\t0.000000\t0.000000\t\t\"sql1 /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"Type\": \"INT64\", \"Value\": 1}}\t0\t0\t\"\"\t\"\"\t\"\"\tfalse\t\"\"\t\"\"\n"
assert.Equal(t, want, got)
*streamlog.QueryLogRowThreshold = 1
got = testFormat(t, logStats, params)
Expand Down Expand Up @@ -257,9 +257,9 @@ func TestLogStatsFormatJSONV2(t *testing.T) {
bindVar *querypb.BindVariable
expected string
}{
{
&querypb.BindVariable{Type: querypb.Type_BINARY, Value: []byte("abc")},
"YWJj",
{ // {"Type": "BINARY", "Value": "\x16k@\xb4J\xbaK\xd6"} breaks JSON, so we base64 endcode the value
&querypb.BindVariable{Type: querypb.Type_BINARY, Value: []byte("\x16k@\xb4J\xbaK\xd6")},
"FmtAtEq6S9Y=",
}, {
&querypb.BindVariable{Type: querypb.Type_BIT, Value: []byte("134")},
"MTM0",
Expand Down Expand Up @@ -305,8 +305,9 @@ func TestLogStatsFormatJSONV2(t *testing.T) {
err := json.Unmarshal([]byte(got), &parsed)
assert.NoError(t, err)
assert.NotNil(t, parsed)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["value"]

bindType := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Type"].(string)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Value"]
assert.Equal(t, test.bindVar.Type.String(), bindType)
assert.Equal(t, test.expected, bindVal)
})
}
Expand Down Expand Up @@ -363,8 +364,9 @@ func TestLogStatsFormatJSONV2(t *testing.T) {
err := json.Unmarshal([]byte(got), &parsed)
assert.NoError(t, err)
assert.NotNil(t, parsed)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["value"]

bindType := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Type"].(string)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Value"]
assert.Equal(t, test.bindVar.Type.String(), bindType)
assert.Equal(t, test.expected, bindVal)
})
}
Expand Down Expand Up @@ -415,8 +417,9 @@ func TestLogStatsFormatJSONV2(t *testing.T) {
err := json.Unmarshal([]byte(got), &parsed)
assert.NoError(t, err)
assert.NotNil(t, parsed)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["value"]

bindType := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Type"].(string)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Value"]
assert.Equal(t, test.bindVar.Type.String(), bindType)
assert.Equal(t, test.expected, bindVal)
})
}
Expand Down
39 changes: 21 additions & 18 deletions go/vt/vttablet/tabletserver/tabletenv/logstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestLogStatsFormat(t *testing.T) {
*streamlog.RedactDebugUIQueries = false
*streamlog.QueryLogFormat = "text"
got := testFormat(logStats, url.Values(params))
want := "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t\t\"sql\"\t{\"intVal\": {\"type\": \"INT64\", \"value\": 1}}\t1\t\"sql with pii\"\tmysql\t0.000000\t0.000000\t0\t12345\t1\t\"\"\t\n"
want := "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t\t\"sql\"\t{\"intVal\": {\"Type\": \"INT64\", \"Value\": 1}}\t1\t\"sql with pii\"\tmysql\t0.000000\t0.000000\t0\t12345\t1\t\"\"\t\n"
if got != want {
t.Errorf("logstats format: got:\n%q\nwant:\n%q\n", got, want)
}
Expand All @@ -101,7 +101,7 @@ func TestLogStatsFormat(t *testing.T) {
if err != nil {
t.Errorf("logstats format: error marshaling json: %v -- got:\n%v", err, got)
}
want = "{\n \"BindVars\": {\n \"intVal\": {\n \"type\": \"INT64\",\n \"value\": 1\n }\n },\n \"CallInfo\": \"\",\n \"ConnWaitTime\": 0,\n \"Effective Caller\": \"\",\n \"End\": \"2017-01-01 01:02:04.000001\",\n \"Error\": \"\",\n \"ImmediateCaller\": \"\",\n \"Method\": \"test\",\n \"MysqlTime\": 0,\n \"OriginalSQL\": \"sql\",\n \"PlanType\": \"\",\n \"Queries\": 1,\n \"QuerySources\": \"mysql\",\n \"ResponseSize\": 1,\n \"RewrittenSQL\": \"sql with pii\",\n \"RowsAffected\": 0,\n \"Start\": \"2017-01-01 01:02:03.000000\",\n \"TotalTime\": 1.000001,\n \"TransactionID\": 12345,\n \"Username\": \"\"\n}"
want = "{\n \"BindVars\": {\n \"intVal\": {\n \"Type\": \"INT64\",\n \"Value\": 1\n }\n },\n \"CallInfo\": \"\",\n \"ConnWaitTime\": 0,\n \"Effective Caller\": \"\",\n \"End\": \"2017-01-01 01:02:04.000001\",\n \"Error\": \"\",\n \"ImmediateCaller\": \"\",\n \"Method\": \"test\",\n \"MysqlTime\": 0,\n \"OriginalSQL\": \"sql\",\n \"PlanType\": \"\",\n \"Queries\": 1,\n \"QuerySources\": \"mysql\",\n \"ResponseSize\": 1,\n \"RewrittenSQL\": \"sql with pii\",\n \"RowsAffected\": 0,\n \"Start\": \"2017-01-01 01:02:03.000000\",\n \"TotalTime\": 1.000001,\n \"TransactionID\": 12345,\n \"Username\": \"\"\n}"
if string(formatted) != want {
t.Errorf("logstats format: got:\n%q\nwant:\n%v\n", string(formatted), want)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestLogStatsFormat(t *testing.T) {

*streamlog.QueryLogFormat = "text"
got = testFormat(logStats, url.Values(params))
want = "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t\t\"sql\"\t{\"strVal\": {\"type\": \"VARBINARY\", \"value\": \"abc\"}}\t1\t\"sql with pii\"\tmysql\t0.000000\t0.000000\t0\t12345\t1\t\"\"\t\n"
want = "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t\t\"sql\"\t{\"strVal\": {\"Type\": \"VARBINARY\", \"Value\": \"abc\"}}\t1\t\"sql with pii\"\tmysql\t0.000000\t0.000000\t0\t12345\t1\t\"\"\t\n"
if got != want {
t.Errorf("logstats format: got:\n%q\nwant:\n%q\n", got, want)
}
Expand All @@ -145,7 +145,7 @@ func TestLogStatsFormat(t *testing.T) {
if err != nil {
t.Errorf("logstats format: error marshaling json: %v -- got:\n%v", err, got)
}
want = "{\n \"BindVars\": {\n \"strVal\": {\n \"type\": \"VARBINARY\",\n \"value\": \"abc\"\n }\n },\n \"CallInfo\": \"\",\n \"ConnWaitTime\": 0,\n \"Effective Caller\": \"\",\n \"End\": \"2017-01-01 01:02:04.000001\",\n \"Error\": \"\",\n \"ImmediateCaller\": \"\",\n \"Method\": \"test\",\n \"MysqlTime\": 0,\n \"OriginalSQL\": \"sql\",\n \"PlanType\": \"\",\n \"Queries\": 1,\n \"QuerySources\": \"mysql\",\n \"ResponseSize\": 1,\n \"RewrittenSQL\": \"sql with pii\",\n \"RowsAffected\": 0,\n \"Start\": \"2017-01-01 01:02:03.000000\",\n \"TotalTime\": 1.000001,\n \"TransactionID\": 12345,\n \"Username\": \"\"\n}"
want = "{\n \"BindVars\": {\n \"strVal\": {\n \"Type\": \"VARBINARY\",\n \"Value\": \"abc\"\n }\n },\n \"CallInfo\": \"\",\n \"ConnWaitTime\": 0,\n \"Effective Caller\": \"\",\n \"End\": \"2017-01-01 01:02:04.000001\",\n \"Error\": \"\",\n \"ImmediateCaller\": \"\",\n \"Method\": \"test\",\n \"MysqlTime\": 0,\n \"OriginalSQL\": \"sql\",\n \"PlanType\": \"\",\n \"Queries\": 1,\n \"QuerySources\": \"mysql\",\n \"ResponseSize\": 1,\n \"RewrittenSQL\": \"sql with pii\",\n \"RowsAffected\": 0,\n \"Start\": \"2017-01-01 01:02:03.000000\",\n \"TotalTime\": 1.000001,\n \"TransactionID\": 12345,\n \"Username\": \"\"\n}"
if string(formatted) != want {
t.Errorf("logstats format: got:\n%q\nwant:\n%v\n", string(formatted), want)
}
Expand All @@ -167,14 +167,14 @@ func TestLogStatsFilter(t *testing.T) {
params := map[string][]string{"full": {}}

got := testFormat(logStats, url.Values(params))
want := "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t\t\"sql /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"type\": \"INT64\", \"value\": 1}}\t1\t\"sql with pii\"\tmysql\t0.000000\t0.000000\t0\t0\t1\t\"\"\t\n"
want := "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t\t\"sql /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"Type\": \"INT64\", \"Value\": 1}}\t1\t\"sql with pii\"\tmysql\t0.000000\t0.000000\t0\t0\t1\t\"\"\t\n"
if got != want {
t.Errorf("logstats format: got:\n%q\nwant:\n%q\n", got, want)
}

*streamlog.QueryLogFilterTag = "LOG_THIS_QUERY"
got = testFormat(logStats, url.Values(params))
want = "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t\t\"sql /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"type\": \"INT64\", \"value\": 1}}\t1\t\"sql with pii\"\tmysql\t0.000000\t0.000000\t0\t0\t1\t\"\"\t\n"
want = "test\t\t\t''\t''\t2017-01-01 01:02:03.000000\t2017-01-01 01:02:04.000001\t1.000001\t\t\"sql /* LOG_THIS_QUERY */\"\t{\"intVal\": {\"Type\": \"INT64\", \"Value\": 1}}\t1\t\"sql with pii\"\tmysql\t0.000000\t0.000000\t0\t0\t1\t\"\"\t\n"
if got != want {
t.Errorf("logstats format: got:\n%q\nwant:\n%q\n", got, want)
}
Expand Down Expand Up @@ -274,9 +274,9 @@ func TestLogStatsFormatJSONV2(t *testing.T) {
bindVar *querypb.BindVariable
expected string
}{
{
&querypb.BindVariable{Type: querypb.Type_BINARY, Value: []byte("abc")},
"YWJj",
{ // {"Type": "BINARY", "Value": "\x16k@\xb4J\xbaK\xd6"} breaks JSON, so we base64 endcode the value
&querypb.BindVariable{Type: querypb.Type_BINARY, Value: []byte("\x16k@\xb4J\xbaK\xd6")},
"FmtAtEq6S9Y=",
}, {
&querypb.BindVariable{Type: querypb.Type_BIT, Value: []byte("134")},
"MTM0",
Expand Down Expand Up @@ -316,14 +316,15 @@ func TestLogStatsFormatJSONV2(t *testing.T) {
for i, test := range testsEncoded {
t.Run(strconv.Itoa(i), func(t *testing.T) {
logStats.BindVariables["vtg"] = test.bindVar
got := testFormat(logStats, url.Values(params))
got := testFormat(logStats, params)
t.Logf("got: %s", got)
var parsed map[string]interface{}
err := json.Unmarshal([]byte(got), &parsed)
assert.NoError(t, err)
assert.NotNil(t, parsed)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["value"]

bindType := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Type"].(string)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Value"]
assert.Equal(t, test.bindVar.Type.String(), bindType)
assert.Equal(t, test.expected, bindVal)
})
}
Expand Down Expand Up @@ -374,14 +375,15 @@ func TestLogStatsFormatJSONV2(t *testing.T) {
for i, test := range testsUnchanged {
t.Run(strconv.Itoa(i), func(t *testing.T) {
logStats.BindVariables["vtg"] = test.bindVar
got := testFormat(logStats, url.Values(params))
got := testFormat(logStats, params)
t.Logf("got: %s", got)
var parsed map[string]interface{}
err := json.Unmarshal([]byte(got), &parsed)
assert.NoError(t, err)
assert.NotNil(t, parsed)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["value"]

bindType := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Type"].(string)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Value"]
assert.Equal(t, test.bindVar.Type.String(), bindType)
assert.Equal(t, test.expected, bindVal)
})
}
Expand Down Expand Up @@ -426,14 +428,15 @@ func TestLogStatsFormatJSONV2(t *testing.T) {
for i, test := range testsUnchangedTuples {
t.Run(strconv.Itoa(i), func(t *testing.T) {
logStats.BindVariables["vtg"] = test.bindVar
got := testFormat(logStats, url.Values(params))
got := testFormat(logStats, params)
t.Logf("got: %s", got)
var parsed map[string]interface{}
err := json.Unmarshal([]byte(got), &parsed)
assert.NoError(t, err)
assert.NotNil(t, parsed)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["value"]

bindType := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Type"].(string)
bindVal := parsed["BindVars"].(map[string]interface{})["vtg"].(map[string]interface{})["Value"]
assert.Equal(t, test.bindVar.Type.String(), bindType)
assert.Equal(t, test.expected, bindVal)
})
}
Expand Down

0 comments on commit a774f11

Please sign in to comment.