Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

queryserving, observability: instrument vttablet query cache plan hits/misses #14947

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions changelog/20.0/20.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
- **[Query Serving](#query-serving)**
- [Vindex Hints](#vindex-hints)
- **[Minor Changes](#minor-changes)**

- **[New Stats](#new-stats)**
- [VTTablet Query Cache Hits and Misses](#vttablet-query-cache-hits-and-misses)

## <a id="major-changes"/>Major Changes


### <a id="query-serving"/>Query Serving

#### <a id="vindex-hints"/> Vindex Hints
Expand All @@ -27,3 +27,11 @@ For more information about Vindex hints and its usage, please consult the docume

## <a id="minor-changes"/>Minor Changes

### <a id="new-stats"/>New Stats

#### <a id="vttablet-query-cache-hits-and-misses"/>VTTablet Query Cache Hits and Misses

VTTablet exposes two new counter stats:

* `QueryCacheHits`: Query engine query cache hits
* `QueryCacheMisses`: Query engine query cache misses
7 changes: 7 additions & 0 deletions go/vt/vttablet/tabletserver/query_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ type QueryEngine struct {
// stats
// Note: queryErrorCountsWithCode is similar to queryErrorCounts except it contains error code as an additional dimension
queryCounts, queryCountsWithTabletType, queryTimes, queryErrorCounts, queryErrorCountsWithCode, queryRowsAffected, queryRowsReturned *stats.CountersWithMultiLabels
queryCacheHits, queryCacheMisses *stats.CounterFunc

// stats flags
enablePerWorkloadTableMetrics bool
Expand Down Expand Up @@ -280,6 +281,12 @@ func NewQueryEngine(env tabletenv.Env, se *schema.Engine) *QueryEngine {
env.Exporter().NewCounterFunc("QueryCacheEvictions", "Query engine query cache evictions", func() int64 {
return qe.plans.Metrics.Evicted()
})
qe.queryCacheHits = env.Exporter().NewCounterFunc("QueryCacheHits", "Query engine query cache hits", func() int64 {
return qe.plans.Metrics.Hits()
})
qe.queryCacheMisses = env.Exporter().NewCounterFunc("QueryCacheMisses", "Query engine query cache misses", func() int64 {
return qe.plans.Metrics.Misses()
})

labels := []string{"Table", "Plan"}
if config.EnablePerWorkloadTableMetrics {
Expand Down
16 changes: 16 additions & 0 deletions go/vt/vttablet/tabletserver/query_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,27 @@ func TestQueryPlanCache(t *testing.T) {
ctx := context.Background()
logStats := tabletenv.NewLogStats(ctx, "GetPlanStats")

initialHits := qe.queryCacheHits.Get()
initialMisses := qe.queryCacheMisses.Get()

firstPlan, err := qe.GetPlan(ctx, logStats, firstQuery, false)
require.NoError(t, err)
require.NotNil(t, firstPlan, "plan should not be nil")

assertPlanCacheSize(t, qe, 1)

require.Equal(t, int64(0), qe.queryCacheHits.Get()-initialHits)
require.Equal(t, int64(1), qe.queryCacheMisses.Get()-initialMisses)

secondPlan, err := qe.GetPlan(ctx, logStats, firstQuery, false)
require.NoError(t, err)
require.NotNil(t, secondPlan, "plan should not be nil")

assertPlanCacheSize(t, qe, 1)

require.Equal(t, int64(1), qe.queryCacheHits.Get()-initialHits)
require.Equal(t, int64(1), qe.queryCacheMisses.Get()-initialMisses)

qe.ClearQueryPlanCache()
}

Expand Down
Loading