Skip to content

Commit

Permalink
sql: more specific naming for telemetry statement sampling vars
Browse files Browse the repository at this point in the history
We are introducing the logging of transaction events in a following
commit. This patch renames a couple of items used for telemetry
logging that will be used exclusively for statement logging. They
are given more specific names to indicate they are used to log
statement events in order to differentiate them from incoming txn
level logging utils.

Renames:
- func `shouldEmitLog` -> `shouldEmitStatementLog`
- cluster setting `TelemetryMaxEventFrequency` ->
  `TelemetryMaxStatementEventFrequency`
  (note that the sql name for this cluster setting remains unchanged)

Release note: None

Epic: none
  • Loading branch information
xinhaoz committed Jan 29, 2024
1 parent 06a1cab commit 8c098e1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/telemetryccl/telemetry_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func TestBulkJobTelemetryLogging(t *testing.T) {
},
}

sql.TelemetryMaxEventFrequency.Override(context.Background(), &testCluster.Server(0).ApplicationLayer().ClusterSettings().SV, 10)
sql.TelemetryMaxStatementEventFrequency.Override(context.Background(), &testCluster.Server(0).ApplicationLayer().ClusterSettings().SV, 10)

// Run all the queries, one after the previous one is finished.
var jobID int
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func NewServer(cfg *ExecutorConfig, pool *mon.BytesMonitor) *Server {
idxRecommendationsCache: idxrecommendations.NewIndexRecommendationsCache(cfg.Settings),
}

telemetryLoggingMetrics := newTelemetryLoggingmetrics(cfg.TelemetryLoggingTestingKnobs, cfg.Settings)
telemetryLoggingMetrics := newTelemetryLoggingMetrics(cfg.TelemetryLoggingTestingKnobs, cfg.Settings)
telemetryLoggingMetrics.registerOnTelemetrySamplingModeChange(cfg.Settings)
s.TelemetryLoggingMetrics = telemetryLoggingMetrics

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/exec_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (p *planner) maybeLogStatementInternal(
txnID = p.txn.ID().String()
}

if telemetryMetrics.shouldEmitLog(telemetryMetrics.timeNow(), txnID, forceLog, stmtCount) {
if telemetryMetrics.shouldEmitStatementLog(telemetryMetrics.timeNow(), txnID, forceLog, stmtCount) {
var queryLevelStats execstats.QueryLevelStats
if stats, ok := p.instrumentation.GetQueryLevelStats(); ok {
queryLevelStats = *stats
Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/telemetry_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// are logged to the telemetry channel.
const defaultMaxEventFrequency = 8

var TelemetryMaxEventFrequency = settings.RegisterIntSetting(
var TelemetryMaxStatementEventFrequency = settings.RegisterIntSetting(
settings.ApplicationLevel,
"sql.telemetry.query_sampling.max_event_frequency",
"the max event frequency at which we sample executions for telemetry, "+
Expand Down Expand Up @@ -108,7 +108,7 @@ type TelemetryLoggingMetrics struct {
skippedQueryCount atomic.Uint64
}

func newTelemetryLoggingmetrics(
func newTelemetryLoggingMetrics(
knobs *TelemetryLoggingTestingKnobs, st *cluster.Settings,
) *TelemetryLoggingMetrics {
t := TelemetryLoggingMetrics{Knobs: knobs, st: st}
Expand Down Expand Up @@ -195,18 +195,18 @@ func (t *TelemetryLoggingMetrics) timeNow() time.Time {
return timeutil.Now()
}

// shouldEmitLog returns true if the stmt should be logged to telemetry. The last emitted time
// shouldEmitStatementLog returns true if the stmt should be logged to telemetry. The last emitted time
// tracked by telemetry logging metrics will be updated to the given time if any of the following
// are met:
// - The telemetry mode is set to "transaction" AND the stmt is the first in
// the txn AND the txn is not already being tracked AND the required amount
// of time has elapsed.
// - The telemetry mode is set to "statement" AND the required amount of time has elapsed
// - The txn is not being tracked and the stmt is being forced to log.
func (t *TelemetryLoggingMetrics) shouldEmitLog(
func (t *TelemetryLoggingMetrics) shouldEmitStatementLog(
newTime time.Time, txnExecutionID string, force bool, stmtPosInTxn int,
) (shouldEmit bool) {
maxEventFrequency := TelemetryMaxEventFrequency.Get(&t.st.SV)
maxEventFrequency := TelemetryMaxStatementEventFrequency.Get(&t.st.SV)
requiredTimeElapsed := time.Second / time.Duration(maxEventFrequency)
isTxnMode := telemetrySamplingMode.Get(&t.st.SV) == telemetryModeTransaction
txnsLimit := int(telemetryTrackedTxnsLimit.Get(&t.st.SV))
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/telemetry_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func TestTelemetryLogging(t *testing.T) {
}

for _, tc := range testData {
TelemetryMaxEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, tc.stubMaxEventFrequency)
TelemetryMaxStatementEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, tc.stubMaxEventFrequency)
if tc.enableInjectTxErrors {
_, err := db.DB.ExecContext(context.Background(), "SET inject_retry_errors_enabled = 'true'")
require.NoError(t, err)
Expand Down Expand Up @@ -919,7 +919,7 @@ func TestNoTelemetryLogOnTroubleshootMode(t *testing.T) {
db.Exec(t, "CREATE TABLE t();")

stubMaxEventFrequency := int64(1)
TelemetryMaxEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, stubMaxEventFrequency)
TelemetryMaxStatementEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, stubMaxEventFrequency)

/*
Testing Cases:
Expand Down Expand Up @@ -1035,7 +1035,7 @@ func TestTelemetryLogJoinTypesAndAlgorithms(t *testing.T) {
");")

stubMaxEventFrequency := int64(1000000)
TelemetryMaxEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, stubMaxEventFrequency)
TelemetryMaxStatementEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, stubMaxEventFrequency)

testData := []struct {
name string
Expand Down Expand Up @@ -1528,7 +1528,7 @@ func TestFunctionBodyRedacted(t *testing.T) {
db.Exec(t, `SET CLUSTER SETTING sql.telemetry.query_sampling.enabled = true;`)
db.Exec(t, `CREATE TABLE kv (k STRING, v INT)`)
stubMaxEventFrequency := int64(1000000)
TelemetryMaxEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, stubMaxEventFrequency)
TelemetryMaxStatementEventFrequency.Override(context.Background(), &s.ClusterSettings().SV, stubMaxEventFrequency)

stmt := `CREATE FUNCTION f() RETURNS INT
LANGUAGE SQL
Expand Down

0 comments on commit 8c098e1

Please sign in to comment.