Skip to content

Commit

Permalink
sql: add created_at to index usage stat telemetry
Browse files Browse the repository at this point in the history
This commit adds a creation timestamp to the index usage
statistics telemetry.

Fixes cockroachdb#84458.

Release justification: low-risk updates to new functionality
Release note(sql change): Added a creation timestamp to index usage statistics
telemetry.
  • Loading branch information
ericharmeling committed Sep 7, 2022
1 parent c29bfab commit 6078958
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/generated/eventlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,7 @@ An event of type `captured_index_usage_stats`
| `IndexType` | | no |
| `IsUnique` | | no |
| `IsInverted` | | no |
| `CreatedAt` | | no |


#### Common fields
Expand Down
10 changes: 8 additions & 2 deletions pkg/sql/scheduledlogging/captured_index_usage_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func captureIndexUsageStats(

// Capture index usage statistics for each database.
var ok bool
expectedNumDatums := 9
expectedNumDatums := 10
var allCapturedIndexUsageStats []logpb.EventPayload
for _, databaseName := range allDatabaseNames {
// Omit index usage statistics on the default databases 'system',
Expand All @@ -189,7 +189,8 @@ func captureIndexUsageStats(
ti.is_unique,
ti.is_inverted,
total_reads,
last_read
last_read,
ti.created_at
FROM %s.crdb_internal.index_usage_statistics AS us
JOIN %s.crdb_internal.table_indexes ti
ON us.index_id = ti.index_id
Expand Down Expand Up @@ -233,6 +234,10 @@ func captureIndexUsageStats(
if row[8] != tree.DNull {
lastRead = tree.MustBeDTimestampTZ(row[8]).Time
}
createdAt := time.Time{}
if row[9] != tree.DNull {
createdAt = tree.MustBeDTimestamp(row[9]).Time
}

capturedIndexStats := &eventpb.CapturedIndexUsageStats{
TableID: uint32(roachpb.TableID(tableID)),
Expand All @@ -245,6 +250,7 @@ func captureIndexUsageStats(
IndexType: string(indexType),
IsUnique: bool(isUnique),
IsInverted: bool(isInverted),
CreatedAt: createdAt.String(),
}

allCapturedIndexUsageStats = append(allCapturedIndexUsageStats, capturedIndexStats)
Expand Down
10 changes: 10 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.

1 change: 1 addition & 0 deletions pkg/util/log/eventpb/telemetry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ message CapturedIndexUsageStats {
string index_type = 9 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""];
bool is_unique = 10 [(gogoproto.jsontag) = ",omitempty"];
bool is_inverted = 11 [(gogoproto.jsontag) = ",omitempty"];
string created_at = 12 [(gogoproto.jsontag) = ",omitempty", (gogoproto.moretags) = "redact:\"nonsensitive\""];
}

// CreateChangefeed is an event for any CREATE CHANGEFEED query that
Expand Down

0 comments on commit 6078958

Please sign in to comment.