Skip to content

Commit

Permalink
Use a throttled logger for exceeded memory warnings (#15424)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
Signed-off-by: Florent Poinsard <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
  • Loading branch information
GuptaManan100 and frouioui authored Mar 26, 2024
1 parent 6976baa commit bec2180
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ import (
"vitess.io/vitess/go/acl"
"vitess.io/vitess/go/cache/theine"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/sqlerror"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/stats"
"vitess.io/vitess/go/streamlog"
"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/callerid"
"vitess.io/vitess/go/vt/key"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
querypb "vitess.io/vitess/go/vt/proto/query"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
Expand Down Expand Up @@ -73,6 +75,8 @@ var (

queriesProcessedByTable = stats.NewCountersWithMultiLabels("QueriesProcessedByTable", "Queries processed at vtgate by plan type, keyspace and table", []string{"Plan", "Keyspace", "Table"})
queriesRoutedByTable = stats.NewCountersWithMultiLabels("QueriesRoutedByTable", "Queries routed from vtgate to vttablet by plan type, keyspace and table", []string{"Plan", "Keyspace", "Table"})

exceedMemoryRowsLogger = logutil.NewThrottledLogger("ExceedMemoryRows", 1*time.Minute)
)

const (
Expand Down Expand Up @@ -231,7 +235,12 @@ func (e *Executor) Execute(ctx context.Context, mysqlCtx vtgateservice.MySQLConn
if err != nil {
piiSafeSQL = logStats.StmtType
}
log.Warningf("%q exceeds warning threshold of max memory rows: %v. Actual memory rows: %v", piiSafeSQL, warnMemoryRows, len(result.Rows))
warningMsg := fmt.Sprintf("%q exceeds warning threshold of max memory rows: %v. Actual memory rows: %v", piiSafeSQL, warnMemoryRows, len(result.Rows))
exceedMemoryRowsLogger.Warningf(warningMsg)
safeSession.RecordWarning(&querypb.QueryWarning{
Code: uint32(sqlerror.EROutOfMemory),
Message: warningMsg,
})
}

logStats.SaveEndTime()
Expand Down Expand Up @@ -365,7 +374,12 @@ func (e *Executor) StreamExecute(
if err != nil {
piiSafeSQL = logStats.StmtType
}
log.Warningf("%q exceeds warning threshold of max memory rows: %v. Actual memory rows: %v", piiSafeSQL, warnMemoryRows, srr.rowsReturned)
warningMsg := fmt.Sprintf("%q exceeds warning threshold of max memory rows: %v. Actual memory rows: %v", piiSafeSQL, warnMemoryRows, srr.rowsReturned)
exceedMemoryRowsLogger.Warningf(warningMsg)
safeSession.RecordWarning(&querypb.QueryWarning{
Code: uint32(sqlerror.EROutOfMemory),
Message: warningMsg,
})
}

logStats.SaveEndTime()
Expand Down

0 comments on commit bec2180

Please sign in to comment.