make vtgate query_plans endpoint return json; also fix comment typos

Signed-off-by: Alex Charis <acharis@hubspot.com>
This commit is contained in:
Alex Charis 2019-08-21 10:41:02 -04:00
Родитель 08650b54c6
Коммит 9e58664e5d
2 изменённых файлов: 10 добавлений и 16 удалений

4
go/cache/lru_cache.go поставляемый
Просмотреть файл

@ -222,7 +222,7 @@ func (lru *LRUCache) Oldest() (oldest time.Time) {
}
// Keys returns all the keys for the cache, ordered from most recently
// used to last recently used.
// used to least recently used.
func (lru *LRUCache) Keys() []string {
lru.mu.Lock()
defer lru.mu.Unlock()
@ -235,7 +235,7 @@ func (lru *LRUCache) Keys() []string {
}
// Items returns all the values for the cache, ordered from most recently
// used to last recently used.
// used to least recently used.
func (lru *LRUCache) Items() []Item {
lru.mu.Lock()
defer lru.mu.Unlock()

Просмотреть файл

@ -1345,20 +1345,15 @@ func (e *Executor) ServeHTTP(response http.ResponseWriter, request *http.Request
return
}
if request.URL.Path == "/debug/query_plans" {
keys := e.plans.Keys()
response.Header().Set("Content-Type", "text/plain")
response.Write([]byte(fmt.Sprintf("Length: %d\n", len(keys))))
for _, v := range keys {
response.Write([]byte(fmt.Sprintf("%#v\n", sqlparser.TruncateForUI(v))))
if plan, ok := e.plans.Peek(v); ok {
if b, err := json.MarshalIndent(plan, "", " "); err != nil {
response.Write([]byte(err.Error()))
} else {
response.Write(b)
}
response.Write(([]byte)("\n\n"))
}
response.Header().Set("Content-Type", "application/json; charset=utf-8")
buf, err := json.MarshalIndent(e.plans.Items(), "", " ")
if err != nil {
response.Write([]byte(err.Error()))
return
}
ebuf := bytes.NewBuffer(nil)
json.HTMLEscape(ebuf, buf)
response.Write(ebuf.Bytes())
} else if request.URL.Path == "/debug/vschema" {
response.Header().Set("Content-Type", "application/json; charset=utf-8")
b, err := json.MarshalIndent(e.VSchema(), "", " ")
@ -1384,7 +1379,6 @@ func (e *Executor) updateQueryCounts(planType, keyspace, tableName string, shard
queriesRouted.Add(planType, shardQueries)
queriesProcessedByTable.Add([]string{planType, keyspace, tableName}, 1)
queriesRoutedByTable.Add([]string{planType, keyspace, tableName}, shardQueries)
return
}
// VSchemaStats returns the loaded vschema stats.