Skip to content

Commit

Permalink
sql/telemetry: add SkippedTransactions to SampledTransaction proto
Browse files Browse the repository at this point in the history
This commit adds the field SkippedTransactions to the
SampledTransaction protobuf to count the number of transactions
that were not sampled while telemetry transaction logging
is enabled. The corresponding field is added to the
telemetryLogging struct and will be used in the following
commit to track skipped transactions. Some whitespace in the
SampledTransaction proto definition is adjusted.

Epic: none

Release note (sql change): New field `SkippedTransactions` in
the SampledTransaction event, which is emitted to the TELEMETRY
logging channel when telemetry logging is enabled and set to
"transaction" mode.
  • Loading branch information
xinhaoz committed Jan 18, 2024
1 parent 8484d4b commit a356e63
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/generated/eventlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3081,6 +3081,7 @@ An event of type `sampled_transaction` is the event logged to telemetry at the e
| `RowsRead` | RowsRead is the number of rows read from disk. | no |
| `RowsWritten` | RowsWritten is the number of rows written to disk. | no |
| `SampledExecStats` | SampledExecStats is a nested field containing execution statistics. This field will be omitted if the stats were not sampled. | yes |
| `SkippedTransactions` | SkippedTransactions is the number of transactions that were skipped as part of sampling prior to this one. We only count skipped transactions when telemetry logging is enabled and the sampling mode is set to "transaction". | no |


#### Common fields
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/telemetry_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ type telemetryLoggingMetrics struct {

// skippedQueryCount is used to produce the count of non-sampled queries.
skippedQueryCount atomic.Uint64

// skippedTransactionCount is used to produce the count of non-sampled transactions.
skippedTransactionCount atomic.Uint64
}

func newTelemetryLoggingMetrics(
Expand Down Expand Up @@ -333,3 +336,11 @@ func (t *telemetryLoggingMetrics) resetLastSampledTime() {
defer t.mu.Unlock()
t.mu.lastSampledTime = time.Time{}
}

func (t *TelemetryLoggingMetrics) resetSkippedTransactionCount() (res uint64) {
return t.skippedTransactionCount.Swap(0)
}

func (t *TelemetryLoggingMetrics) incSkippedTransactionCount() {
t.skippedTransactionCount.Add(1)
}
9 changes: 9 additions & 0 deletions pkg/util/log/eventpb/json_encode_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions pkg/util/log/eventpb/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -457,27 +457,32 @@ message SampledTransaction {
int64 num_rows = 18 [(gogoproto.jsontag) = ",includeempty"];

// RetryLatNanos is the amount of time spent retrying the transaction.
int64 retry_lat_nanos = 19 [(gogoproto.jsontag) = ",omitempty"];
int64 retry_lat_nanos = 19 [(gogoproto.jsontag) = ",omitempty"];

// CommitLatNanos is the amount of time spent committing the transaction after all statement operations.
int64 commit_lat_nanos = 20 [(gogoproto.jsontag) = ",includeempty"];
// CommitLatNanos is the amount of time spent committing the transaction after all statement operations.
int64 commit_lat_nanos = 20 [(gogoproto.jsontag) = ",includeempty"];

// IdleLatNanos is the amount of time spent waiting for the client to send statements
// IdleLatNanos is the amount of time spent waiting for the client to send statements
// while the transaction is open.
int64 idle_lat_nanos = 21 [(gogoproto.jsontag) = ",includeempty"];
int64 idle_lat_nanos = 21 [(gogoproto.jsontag) = ",includeempty"];

// BytesRead is the number of bytes read from disk.
int64 bytes_read = 22 [(gogoproto.jsontag) = ",includeempty"];
// BytesRead is the number of bytes read from disk.
int64 bytes_read = 22 [(gogoproto.jsontag) = ",includeempty"];

// RowsRead is the number of rows read from disk.
int64 rows_read = 23 [(gogoproto.jsontag) = ",includeempty"];
// RowsRead is the number of rows read from disk.
int64 rows_read = 23 [(gogoproto.jsontag) = ",includeempty"];

// RowsWritten is the number of rows written to disk.
int64 rows_written = 24 [(gogoproto.jsontag) = ",includeempty"];
// RowsWritten is the number of rows written to disk.
int64 rows_written = 24 [(gogoproto.jsontag) = ",includeempty"];

// SampledExecStats is a nested field containing execution statistics.
// This field will be omitted if the stats were not sampled.
SampledExecStats sampled_exec_stats = 25 [(gogoproto.jsontag) = ",omitempty"];
// SampledExecStats is a nested field containing execution statistics.
// This field will be omitted if the stats were not sampled.
SampledExecStats sampled_exec_stats = 25 [(gogoproto.jsontag) = ",omitempty"];

// SkippedTransactions is the number of transactions that were skipped as part of sampling prior to
// this one. We only count skipped transactions when telemetry logging is enabled and the sampling
// mode is set to "transaction".
int64 skipped_transactions = 26 [(gogoproto.jsontag) = ",omitempty"];
}

// CapturedIndexUsageStats
Expand Down

0 comments on commit a356e63

Please sign in to comment.