Skip to content

Commit

Permalink
Merge pull request #5120 from HubSpot/vtgate-query-plans-endpoint-json
Browse files Browse the repository at this point in the history
make vtgate query_plans endpoint return json; also fix comment typos
  • Loading branch information
sougou authored Aug 29, 2019
2 parents 8e58f49 + 9e58664 commit 92095f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
4 changes: 2 additions & 2 deletions go/cache/lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
22 changes: 8 additions & 14 deletions go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,20 +1416,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(), "", " ")
Expand All @@ -1455,7 +1450,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.
Expand Down

0 comments on commit 92095f1

Please sign in to comment.