Change JSON tag name on WireQueryResponse from execution-time to exec_time (#2394)

* Change JSON response name from exec_time to execution-time

Execution time stopped working in the CLI because it uses the latest
json tag.

* Wait, don't break the interface.

* Add a test for the sql response json tags.

This is to make sure that if someone like Travis just goes and changes a
tag name to be more consistent, that we perhaps catch that before it
gets to the end user.

* Change exec_time to execution-time after all

(cherry picked from commit b5dd3ea02e)
This commit is contained in:
Travis Turner 2023-01-05 18:34:01 -06:00 committed by Joe Friedrich
parent 5ec31d4159
commit 01cae92d96
3 changed files with 62 additions and 3 deletions

View file

@ -1439,9 +1439,9 @@ func (h *Handler) handlePostSQL(w http.ResponseWriter, r *http.Request) {
var value []byte
value, err = json.Marshal(execTime)
if err != nil {
w.Write([]byte(`,"exec_time": 0`))
w.Write([]byte(`,"execution-time": 0`))
} else {
w.Write([]byte(`,"exec_time":`))
w.Write([]byte(`,"execution-time":`))
w.Write(value)
}
w.Write([]byte("}"))
@ -1489,7 +1489,7 @@ func (h *Handler) handlePostSQL(w http.ResponseWriter, r *http.Request) {
if err != nil {
planBytes = []byte(`"PROBLEM ENCODING QUERY PLAN"`)
}
w.Write([]byte(`,"queryPlan":`))
w.Write([]byte(`,"query-plan":`))
w.Write(planBytes)
}
}

View file

@ -545,6 +545,64 @@ func TestGetViewAndDelete(t *testing.T) {
}
}
// TestHandlerSQL tests that the json coming back from a POST /sql request has
// the expected json tags.
func TestHandlerSQL(t *testing.T) {
cfg := server.NewConfig()
cfg.SQL.EndpointEnabled = true
c := test.MustRunCluster(t, 1, []server.CommandOption{
server.OptCommandConfig(cfg),
})
defer c.Close()
m := c.GetPrimary()
tests := []struct {
name string
url string
sql string
expKeys []string
}{
{
name: "sql",
url: "/sql",
sql: "show tables",
expKeys: []string{"schema", "data", "execution-time"},
},
{
name: "sql-with-plan",
url: "/sql?plan=1",
sql: "show tables",
expKeys: []string{"schema", "data", "query-plan", "execution-time"},
},
{
name: "invalid-sql",
url: "/sql",
sql: "invalid sql",
expKeys: []string{"error", "execution-time"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sqlURL := fmt.Sprintf("%s%s", m.URL(), tt.url)
resp := test.Do(t, "POST", sqlURL, tt.sql)
if resp.StatusCode != http.StatusOK {
t.Errorf("post sql, status: %d, body=%s", resp.StatusCode, resp.Body)
}
out := make(map[string]interface{})
assert.NoError(t, json.Unmarshal([]byte(resp.Body), &out))
keys := make([]string, 0, len(out))
for k := range out {
keys = append(keys, k)
}
assert.ElementsMatch(t, tt.expKeys, keys)
})
}
}
func TestTranslationHandlers(t *testing.T) {
// reusable data for the tests
nameBytes, err := json.Marshal([]string{"a", "b", "c"})

View file

@ -128,6 +128,7 @@ func OptCommandConfig(config *Config) CommandOption {
c.Config.TLS = config.TLS
c.Config.MDSAddress = config.MDSAddress
c.Config.WriteLogger = config.WriteLogger
c.Config.SQL.EndpointEnabled = config.SQL.EndpointEnabled
return nil
}
c.Config = config