Skip to content

Commit 1596ade

Browse files
authored
feat: export index usage statistics (#9)
1 parent 3dcec01 commit 1596ade

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

pkg/export/exporter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ var exportTables = []Table{
158158
` ROUND((metrics->>'sys.totalmem')::FLOAT / 1073741824, 1) AS total_mem_gib` +
159159
` FROM crdb_internal.kv_node_status`,
160160
},
161-
{Database: "", Name: "crdb_internal.table_indexes", TimeColumn: "", Scope: TenantScopeMain}, // Use "" to query across all databases
161+
{Database: "", Name: "crdb_internal.table_indexes", TimeColumn: "", Scope: TenantScopeMain}, // Use "" to query across all databases
162+
{Database: "", Name: "crdb_internal.index_usage_statistics", TimeColumn: "", Scope: TenantScopeMain}, // Use "" to query across all databases
162163
{Database: "system", Name: "table_statistics", TimeColumn: "", Scope: TenantScopeMain},
163164
{
164165
Database: "crdb_internal",

pkg/export/exporter_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,24 @@ func TestExportTables(t *testing.T) {
195195
}
196196
}
197197

198+
func TestExportTablesIncludesIndexUsageStatistics(t *testing.T) {
199+
found := false
200+
for _, table := range exportTables {
201+
if table.Database == "" && table.Name == "crdb_internal.index_usage_statistics" {
202+
found = true
203+
if table.Scope != TenantScopeMain {
204+
t.Errorf("crdb_internal.index_usage_statistics should have Scope TenantScopeMain, got %q", table.Scope)
205+
}
206+
if table.TimeColumn != "" {
207+
t.Errorf("crdb_internal.index_usage_statistics should have no TimeColumn, got %q", table.TimeColumn)
208+
}
209+
}
210+
}
211+
if !found {
212+
t.Error("exportTables should contain crdb_internal.index_usage_statistics")
213+
}
214+
}
215+
198216
func TestExportTablesIncludesNodeCPUMem(t *testing.T) {
199217
found := false
200218
for _, table := range exportTables {

0 commit comments

Comments
 (0)