@@ -39,7 +39,8 @@ type bufferedStmtStats []sqlstats.RecordedStmtStats
3939//
4040// 2. The insights subsystem (insightsWriter) which is used to
4141// persist statement and transaction insights to an in-memory cache.
42- // Events are sent to the insights subsystem for async processing.
42+ // Events are sent to the insights subsystem for async processing in
43+ // observeStatement() and observeTransaction() respectively.
4344type StatsCollector struct {
4445
4546 // stmtBuf contains the current transaction's statement
@@ -227,11 +228,9 @@ func (s *StatsCollector) shouldObserveInsights() bool {
227228 return sqlstats .StmtStatsEnable .Get (& s .st .SV ) && sqlstats .TxnStatsEnable .Get (& s .st .SV )
228229}
229230
230- // ObserveStatement sends the recorded statement stats to the insights system
231+ // observeStatement sends the recorded statement stats to the insights system
231232// for further processing.
232- func (s * StatsCollector ) ObserveStatement (
233- stmtFingerprintID appstatspb.StmtFingerprintID , value sqlstats.RecordedStmtStats ,
234- ) {
233+ func (s * StatsCollector ) observeStatement (value sqlstats.RecordedStmtStats ) {
235234 if ! s .sendInsights {
236235 return
237236 }
@@ -257,7 +256,7 @@ func (s *StatsCollector) ObserveStatement(
257256
258257 insight := insights.Statement {
259258 ID : value .StatementID ,
260- FingerprintID : stmtFingerprintID ,
259+ FingerprintID : value . FingerprintID ,
261260 LatencyInSeconds : value .ServiceLatencySec ,
262261 Query : value .Query ,
263262 Status : getInsightStatus (value .StatementError ),
@@ -283,12 +282,10 @@ func (s *StatsCollector) ObserveStatement(
283282 }
284283}
285284
286- // ObserveTransaction sends the recorded transaction stats to the insights system
285+ // observeTransaction sends the recorded transaction stats to the insights system
287286// for further processing.
288- func (s * StatsCollector ) ObserveTransaction (
289- _ctx context.Context ,
290- txnFingerprintID appstatspb.TransactionFingerprintID ,
291- value sqlstats.RecordedTxnStats ,
287+ func (s * StatsCollector ) observeTransaction (
288+ txnFingerprintID appstatspb.TransactionFingerprintID , value sqlstats.RecordedTxnStats ,
292289) {
293290 if ! s .sendInsights {
294291 return
@@ -344,6 +341,8 @@ func (s *StatsCollector) ObserveTransaction(
344341func (s * StatsCollector ) RecordStatement (
345342 ctx context.Context , value sqlstats.RecordedStmtStats ,
346343) error {
344+ s .observeStatement (value )
345+
347346 // TODO(xinhaoz): This isn't the best place to set this, but we'll clean this up
348347 // when we refactor the stats collection code to send the stats to an ingester.
349348 s .stmtFingerprintID = value .FingerprintID
@@ -362,6 +361,8 @@ func (s *StatsCollector) RecordStatement(
362361func (s * StatsCollector ) RecordTransaction (
363362 ctx context.Context , key appstatspb.TransactionFingerprintID , value sqlstats.RecordedTxnStats ,
364363) error {
364+ s .observeTransaction (key , value )
365+
365366 // TODO(117690): Unify StmtStatsEnable and TxnStatsEnable into a single cluster setting.
366367 if ! sqlstats .TxnStatsEnable .Get (& s .st .SV ) {
367368 return nil
0 commit comments