From 8545e655a82d0c41618e52b13d86a0f4be3ac741 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Tue, 4 Jun 2024 06:43:26 +0200 Subject: [PATCH] Add sql text counts stats to `vtcombo`,`vtgate`+`vttablet` (#15897) Signed-off-by: Tim Vaillancourt Signed-off-by: Harshit Gangal Co-authored-by: Harshit Gangal Co-authored-by: Deepthi Sigireddi --- go/vt/vtgate/vtgate.go | 10 +- go/vt/vttablet/tabletserver/query_engine.go | 6 +- .../tabletserver/query_engine_test.go | 328 +++++++++--------- 3 files changed, 172 insertions(+), 172 deletions(-) diff --git a/go/vt/vtgate/vtgate.go b/go/vt/vtgate/vtgate.go index ccffa853000..aa6ea4e4ff0 100644 --- a/go/vt/vtgate/vtgate.go +++ b/go/vt/vtgate/vtgate.go @@ -184,10 +184,10 @@ type VTGate struct { // stats objects. // TODO(sougou): This needs to be cleaned up. There // are global vars that depend on this member var. - timings *stats.MultiTimings - rowsReturned *stats.CountersWithMultiLabels - rowsAffected *stats.CountersWithMultiLabels - sqlTextCounts *stats.CountersWithMultiLabels + timings *stats.MultiTimings + rowsReturned *stats.CountersWithMultiLabels + rowsAffected *stats.CountersWithMultiLabels + queryTextCharsProcessed *stats.CountersWithMultiLabels // the throttled loggers for all errors, one per API entry logExecute *logutil.ThrottledLogger @@ -438,7 +438,7 @@ func (vtg *VTGate) Execute(ctx context.Context, session *vtgatepb.Session, sql s if err == nil { vtg.rowsReturned.Add(statsKey, int64(len(qr.Rows))) vtg.rowsAffected.Add(statsKey, int64(qr.RowsAffected)) - vtg.sqlTextCounts.Add(statsKey, int64(len(sql))) + vtg.queryTextCharsProcessed.Add(statsKey, int64(len(sql))) return session, qr, nil } diff --git a/go/vt/vttablet/tabletserver/query_engine.go b/go/vt/vttablet/tabletserver/query_engine.go index 9c306bc447f..41d6192dffb 100644 --- a/go/vt/vttablet/tabletserver/query_engine.go +++ b/go/vt/vttablet/tabletserver/query_engine.go @@ -171,7 +171,7 @@ type QueryEngine struct { consolidatorMode sync2.AtomicString // stats - queryCounts, queryTimes, queryRowCounts, queryErrorCounts, queryRowsAffected, queryRowsReturned, querySQLTextCounts *stats.CountersWithMultiLabels + queryCounts, queryTimes, queryRowCounts, queryErrorCounts, queryRowsAffected, queryRowsReturned, queryTextCharsProcessed *stats.CountersWithMultiLabels // stats flags enablePerWorkloadTableMetrics bool @@ -261,7 +261,7 @@ func NewQueryEngine(env tabletenv.Env, se *schema.Engine) *QueryEngine { qe.queryRowCounts = env.Exporter().NewCountersWithMultiLabels("QueryRowCounts", "(DEPRECATED - use QueryRowsAffected and QueryRowsReturned instead) query row counts", labels) qe.queryRowsAffected = env.Exporter().NewCountersWithMultiLabels("QueryRowsAffected", "query rows affected", labels) qe.queryRowsReturned = env.Exporter().NewCountersWithMultiLabels("QueryRowsReturned", "query rows returned", labels) - qe.querySQLTextCounts = env.Exporter().NewCountersWithMultiLabels("QuerySQLTextCounts", "query sql text counts", labels) + qe.queryTextCharsProcessed = env.Exporter().NewCountersWithMultiLabels("QueryTextCharactersProcessed", "query text characters processed", labels) qe.queryErrorCounts = env.Exporter().NewCountersWithMultiLabels("QueryErrorCounts", "query error counts", labels) env.Exporter().HandleFunc("/debug/hotrows", qe.txSerializer.ServeHTTP) @@ -502,7 +502,7 @@ func (qe *QueryEngine) AddStats(plan *TabletPlan, tableName, workload string, qu qe.queryRowCounts.Add(keys, rowsAffected) qe.queryErrorCounts.Add(keys, errorCount) if plan.FullQuery != nil { - qe.querySQLTextCounts.Add(keys, int64(len(plan.FullQuery.Query))) + qe.queryTextCharsProcessed.Add(keys, int64(len(plan.FullQuery.Query))) } // For certain plan types like select, we only want to add their metrics to rows returned diff --git a/go/vt/vttablet/tabletserver/query_engine_test.go b/go/vt/vttablet/tabletserver/query_engine_test.go index 093f8971141..8681ee7dc2b 100644 --- a/go/vt/vttablet/tabletserver/query_engine_test.go +++ b/go/vt/vttablet/tabletserver/query_engine_test.go @@ -586,178 +586,178 @@ func TestAddQueryStats(t *testing.T) { }, } testcases := []struct { - name string - plan *TabletPlan - tableName string - queryCount int64 - duration time.Duration - mysqlTime time.Duration - rowsAffected int64 - rowsReturned int64 - errorCount int64 - errorCode string - enablePerWorkloadTableMetrics bool - workload string - expectedQueryCounts string - expectedQueryTimes string - expectedQueryRowsAffected string - expectedQueryRowsReturned string - expectedQuerySQLTextCounts string - expectedQueryErrorCounts string - expectedQueryRowCounts string + name string + plan *TabletPlan + tableName string + queryCount int64 + duration time.Duration + mysqlTime time.Duration + rowsAffected int64 + rowsReturned int64 + errorCount int64 + errorCode string + enablePerWorkloadTableMetrics bool + workload string + expectedQueryCounts string + expectedQueryTimes string + expectedQueryRowsAffected string + expectedQueryRowsReturned string + expectedQueryTextCharsProcessed string + expectedQueryErrorCounts string + expectedQueryRowCounts string }{ { - name: "select query", - plan: fakeSelectPlan, - tableName: "A", - queryCount: 1, - duration: 10, - rowsAffected: 0, - rowsReturned: 15, - errorCount: 0, - errorCode: "OK", - enablePerWorkloadTableMetrics: false, - workload: "some-workload", - expectedQueryCounts: `{"A.Select": 1}`, - expectedQueryTimes: `{"A.Select": 10}`, - expectedQueryRowsAffected: `{}`, - expectedQueryRowsReturned: `{"A.Select": 15}`, - expectedQuerySQLTextCounts: `{"A.Select": 43}`, - expectedQueryRowCounts: `{"A.Select": 0}`, - expectedQueryErrorCounts: `{"A.Select": 0}`, + name: "select query", + plan: fakeSelectPlan, + tableName: "A", + queryCount: 1, + duration: 10, + rowsAffected: 0, + rowsReturned: 15, + errorCount: 0, + errorCode: "OK", + enablePerWorkloadTableMetrics: false, + workload: "some-workload", + expectedQueryCounts: `{"A.Select": 1}`, + expectedQueryTimes: `{"A.Select": 10}`, + expectedQueryRowsAffected: `{}`, + expectedQueryRowsReturned: `{"A.Select": 15}`, + expectedQueryTextCharsProcessed: `{"A.Select": 43}`, + expectedQueryRowCounts: `{"A.Select": 0}`, + expectedQueryErrorCounts: `{"A.Select": 0}`, }, { - name: "select into query", - plan: fakeSelectPlan, - tableName: "A", - queryCount: 1, - duration: 10, - rowsAffected: 15, - rowsReturned: 0, - errorCount: 0, - errorCode: "OK", - enablePerWorkloadTableMetrics: false, - workload: "some-workload", - expectedQueryCounts: `{"A.Select": 1}`, - expectedQueryTimes: `{"A.Select": 10}`, - expectedQueryRowsAffected: `{"A.Select": 15}`, - expectedQueryRowsReturned: `{"A.Select": 0}`, - expectedQuerySQLTextCounts: `{"A.Select": 43}`, - expectedQueryRowCounts: `{"A.Select": 15}`, - expectedQueryErrorCounts: `{"A.Select": 0}`, + name: "select into query", + plan: fakeSelectPlan, + tableName: "A", + queryCount: 1, + duration: 10, + rowsAffected: 15, + rowsReturned: 0, + errorCount: 0, + errorCode: "OK", + enablePerWorkloadTableMetrics: false, + workload: "some-workload", + expectedQueryCounts: `{"A.Select": 1}`, + expectedQueryTimes: `{"A.Select": 10}`, + expectedQueryRowsAffected: `{"A.Select": 15}`, + expectedQueryRowsReturned: `{"A.Select": 0}`, + expectedQueryTextCharsProcessed: `{"A.Select": 43}`, + expectedQueryRowCounts: `{"A.Select": 15}`, + expectedQueryErrorCounts: `{"A.Select": 0}`, }, { - name: "error", - plan: fakeSelectPlan, - tableName: "A", - queryCount: 1, - duration: 10, - rowsAffected: 0, - rowsReturned: 0, - errorCount: 1, - errorCode: "RESOURCE_EXHAUSTED", - enablePerWorkloadTableMetrics: false, - workload: "some-workload", - expectedQueryCounts: `{"A.Select": 1}`, - expectedQueryTimes: `{"A.Select": 10}`, - expectedQueryRowsAffected: `{}`, - expectedQueryRowsReturned: `{"A.Select": 0}`, - expectedQuerySQLTextCounts: `{"A.Select": 43}`, - expectedQueryRowCounts: `{"A.Select": 0}`, - expectedQueryErrorCounts: `{"A.Select": 1}`, + name: "error", + plan: fakeSelectPlan, + tableName: "A", + queryCount: 1, + duration: 10, + rowsAffected: 0, + rowsReturned: 0, + errorCount: 1, + errorCode: "RESOURCE_EXHAUSTED", + enablePerWorkloadTableMetrics: false, + workload: "some-workload", + expectedQueryCounts: `{"A.Select": 1}`, + expectedQueryTimes: `{"A.Select": 10}`, + expectedQueryRowsAffected: `{}`, + expectedQueryRowsReturned: `{"A.Select": 0}`, + expectedQueryTextCharsProcessed: `{"A.Select": 43}`, + expectedQueryRowCounts: `{"A.Select": 0}`, + expectedQueryErrorCounts: `{"A.Select": 1}`, }, { - name: "insert query", - plan: fakeInsertPlan, - tableName: "A", - queryCount: 1, - duration: 10, - rowsAffected: 15, - rowsReturned: 0, - errorCount: 0, - errorCode: "OK", - enablePerWorkloadTableMetrics: false, - workload: "some-workload", - expectedQueryCounts: `{"A.Insert": 1}`, - expectedQueryTimes: `{"A.Insert": 10}`, - expectedQueryRowsAffected: `{"A.Insert": 15}`, - expectedQueryRowsReturned: `{}`, - expectedQuerySQLTextCounts: `{"A.Insert": 59}`, - expectedQueryRowCounts: `{"A.Insert": 15}`, - expectedQueryErrorCounts: `{"A.Insert": 0}`, + name: "insert query", + plan: fakeInsertPlan, + tableName: "A", + queryCount: 1, + duration: 10, + rowsAffected: 15, + rowsReturned: 0, + errorCount: 0, + errorCode: "OK", + enablePerWorkloadTableMetrics: false, + workload: "some-workload", + expectedQueryCounts: `{"A.Insert": 1}`, + expectedQueryTimes: `{"A.Insert": 10}`, + expectedQueryRowsAffected: `{"A.Insert": 15}`, + expectedQueryRowsReturned: `{}`, + expectedQueryTextCharsProcessed: `{"A.Insert": 59}`, + expectedQueryRowCounts: `{"A.Insert": 15}`, + expectedQueryErrorCounts: `{"A.Insert": 0}`, }, { - name: "select query with per workload metrics", - plan: fakeSelectPlan, - tableName: "A", - queryCount: 1, - duration: 10, - rowsAffected: 0, - rowsReturned: 15, - errorCount: 0, - errorCode: "OK", - enablePerWorkloadTableMetrics: true, - workload: "some-workload", - expectedQueryCounts: `{"A.Select.some-workload": 1}`, - expectedQueryTimes: `{"A.Select.some-workload": 10}`, - expectedQueryRowsAffected: `{}`, - expectedQueryRowsReturned: `{"A.Select.some-workload": 15}`, - expectedQuerySQLTextCounts: `{"A.Select.some-workload": 43}`, - expectedQueryRowCounts: `{"A.Select.some-workload": 0}`, - expectedQueryErrorCounts: `{"A.Select.some-workload": 0}`, + name: "select query with per workload metrics", + plan: fakeSelectPlan, + tableName: "A", + queryCount: 1, + duration: 10, + rowsAffected: 0, + rowsReturned: 15, + errorCount: 0, + errorCode: "OK", + enablePerWorkloadTableMetrics: true, + workload: "some-workload", + expectedQueryCounts: `{"A.Select.some-workload": 1}`, + expectedQueryTimes: `{"A.Select.some-workload": 10}`, + expectedQueryRowsAffected: `{}`, + expectedQueryRowsReturned: `{"A.Select.some-workload": 15}`, + expectedQueryTextCharsProcessed: `{"A.Select.some-workload": 43}`, + expectedQueryRowCounts: `{"A.Select.some-workload": 0}`, + expectedQueryErrorCounts: `{"A.Select.some-workload": 0}`, }, { - name: "select into query with per workload metrics", - plan: fakeSelectPlan, - tableName: "A", - queryCount: 1, - duration: 10, - rowsAffected: 15, - rowsReturned: 0, - errorCount: 0, - errorCode: "OK", - enablePerWorkloadTableMetrics: true, - workload: "some-workload", - expectedQueryCounts: `{"A.Select.some-workload": 1}`, - expectedQueryTimes: `{"A.Select.some-workload": 10}`, - expectedQueryRowsAffected: `{"A.Select.some-workload": 15}`, - expectedQueryRowsReturned: `{"A.Select.some-workload": 0}`, - expectedQuerySQLTextCounts: `{"A.Select.some-workload": 43}`, - expectedQueryRowCounts: `{"A.Select.some-workload": 15}`, - expectedQueryErrorCounts: `{"A.Select.some-workload": 0}`, + name: "select into query with per workload metrics", + plan: fakeSelectPlan, + tableName: "A", + queryCount: 1, + duration: 10, + rowsAffected: 15, + rowsReturned: 0, + errorCount: 0, + errorCode: "OK", + enablePerWorkloadTableMetrics: true, + workload: "some-workload", + expectedQueryCounts: `{"A.Select.some-workload": 1}`, + expectedQueryTimes: `{"A.Select.some-workload": 10}`, + expectedQueryRowsAffected: `{"A.Select.some-workload": 15}`, + expectedQueryRowsReturned: `{"A.Select.some-workload": 0}`, + expectedQueryTextCharsProcessed: `{"A.Select.some-workload": 43}`, + expectedQueryRowCounts: `{"A.Select.some-workload": 15}`, + expectedQueryErrorCounts: `{"A.Select.some-workload": 0}`, }, { - name: "error with per workload metrics", - plan: fakeSelectPlan, - tableName: "A", - queryCount: 1, - duration: 10, - rowsAffected: 0, - rowsReturned: 0, - errorCount: 1, - errorCode: "RESOURCE_EXHAUSTED", - enablePerWorkloadTableMetrics: true, - workload: "some-workload", - expectedQueryCounts: `{"A.Select.some-workload": 1}`, - expectedQueryTimes: `{"A.Select.some-workload": 10}`, - expectedQueryRowsAffected: `{}`, - expectedQueryRowsReturned: `{"A.Select.some-workload": 0}`, - expectedQuerySQLTextCounts: `{"A.Select.some-workload": 43}`, - expectedQueryRowCounts: `{"A.Select.some-workload": 0}`, - expectedQueryErrorCounts: `{"A.Select.some-workload": 1}`, + name: "error with per workload metrics", + plan: fakeSelectPlan, + tableName: "A", + queryCount: 1, + duration: 10, + rowsAffected: 0, + rowsReturned: 0, + errorCount: 1, + errorCode: "RESOURCE_EXHAUSTED", + enablePerWorkloadTableMetrics: true, + workload: "some-workload", + expectedQueryCounts: `{"A.Select.some-workload": 1}`, + expectedQueryTimes: `{"A.Select.some-workload": 10}`, + expectedQueryRowsAffected: `{}`, + expectedQueryRowsReturned: `{"A.Select.some-workload": 0}`, + expectedQueryTextCharsProcessed: `{"A.Select.some-workload": 43}`, + expectedQueryRowCounts: `{"A.Select.some-workload": 0}`, + expectedQueryErrorCounts: `{"A.Select.some-workload": 1}`, }, { - name: "insert query with per workload metrics", - plan: fakeInsertPlan, - tableName: "A", - queryCount: 1, - duration: 10, - rowsAffected: 15, - rowsReturned: 0, - errorCount: 0, - errorCode: "OK", - enablePerWorkloadTableMetrics: true, - workload: "some-workload", - expectedQueryCounts: `{"A.Insert.some-workload": 1}`, - expectedQueryTimes: `{"A.Insert.some-workload": 10}`, - expectedQueryRowsAffected: `{"A.Insert.some-workload": 15}`, - expectedQueryRowsReturned: `{}`, - expectedQuerySQLTextCounts: `{"A.Insert.some-workload": 59}`, - expectedQueryRowCounts: `{"A.Insert.some-workload": 15}`, - expectedQueryErrorCounts: `{"A.Insert.some-workload": 0}`, + name: "insert query with per workload metrics", + plan: fakeInsertPlan, + tableName: "A", + queryCount: 1, + duration: 10, + rowsAffected: 15, + rowsReturned: 0, + errorCount: 0, + errorCode: "OK", + enablePerWorkloadTableMetrics: true, + workload: "some-workload", + expectedQueryCounts: `{"A.Insert.some-workload": 1}`, + expectedQueryTimes: `{"A.Insert.some-workload": 10}`, + expectedQueryRowsAffected: `{"A.Insert.some-workload": 15}`, + expectedQueryRowsReturned: `{}`, + expectedQueryTextCharsProcessed: `{"A.Insert.some-workload": 59}`, + expectedQueryRowCounts: `{"A.Insert.some-workload": 15}`, + expectedQueryErrorCounts: `{"A.Insert.some-workload": 0}`, }, } @@ -776,7 +776,7 @@ func TestAddQueryStats(t *testing.T) { assert.Equal(t, testcase.expectedQueryRowsAffected, qe.queryRowsAffected.String()) assert.Equal(t, testcase.expectedQueryRowsReturned, qe.queryRowsReturned.String()) assert.Equal(t, testcase.expectedQueryRowCounts, qe.queryRowCounts.String()) - assert.Equal(t, testcase.expectedQuerySQLTextCounts, qe.querySQLTextCounts.String()) + assert.Equal(t, testcase.expectedQueryTextCharsProcessed, qe.querySQLTextCounts.String()) assert.Equal(t, testcase.expectedQueryErrorCounts, qe.queryErrorCounts.String()) }) }