Skip to content

Commit 4c6243b

Browse files
committed
update field names to also list vl_*_id
1 parent c65e577 commit 4c6243b

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

lib/logstorage/pipe_field_names.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ func (pfp *pipeFieldNamesProcessor) writeBlock(workerID uint, br *blockResult) {
136136
shard.updateColumnHits("_time", filter, hits)
137137
shard.updateColumnHits("_stream", filter, hits)
138138
shard.updateColumnHits("_stream_id", filter, hits)
139+
if br.bs.bsw.pso.isMultiTenant {
140+
for _, columnName := range tenantColumns {
141+
if !br.bs.isHiddenField(columnName) {
142+
shard.updateColumnHits(columnName, filter, hits)
143+
}
144+
}
145+
}
139146
}
140147
}
141148

@@ -145,6 +152,10 @@ func (shard *pipeFieldNamesProcessorShard) updateHits(refs []columnHeaderRef, br
145152
if br.bs.isHiddenField(columnName) {
146153
continue
147154
}
155+
if br.bs.bsw.pso.isMultiTenant && isTenantColumn(columnName) {
156+
// The stored column is shadowed by the automatically generated tenant column.
157+
continue
158+
}
148159
shard.updateColumnHits(columnName, filter, hits)
149160
}
150161
}

lib/logstorage/storage_search_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,54 @@ func newTestQueryContext(tenantIDs []TenantID, q *Query) *QueryContext {
17491749
return NewQueryContext(context.Background(), qs, tenantIDs, false, q, false, nil)
17501750
}
17511751

1752+
func TestStorageGetFieldNamesMultitenant(t *testing.T) {
1753+
t.Parallel()
1754+
1755+
path := t.TempDir()
1756+
s := MustOpenStorage(path, &StorageConfig{
1757+
Retention: 24 * time.Hour,
1758+
})
1759+
defer s.MustClose()
1760+
1761+
now := time.Now().UnixNano()
1762+
lr := GetLogRows(nil, nil, nil, nil, "")
1763+
for i := range 3 {
1764+
tenantID := TenantID{
1765+
AccountID: uint32(i + 1),
1766+
ProjectID: uint32(i + 11),
1767+
}
1768+
fields := []Field{
1769+
{Name: "_msg", Value: fmt.Sprintf("message-%d", i)},
1770+
}
1771+
if i < 2 {
1772+
fields = append(fields,
1773+
Field{Name: "vl_account_id", Value: "stored-account-id"},
1774+
Field{Name: "vl_project_id", Value: "stored-project-id"},
1775+
)
1776+
}
1777+
lr.mustAdd(tenantID, now+int64(i), fields)
1778+
}
1779+
s.MustAddRows(lr)
1780+
PutLogRows(lr)
1781+
s.DebugFlush()
1782+
1783+
q := mustParseQuery("*")
1784+
qs := &QueryStats{}
1785+
qctx := NewQueryContext(context.Background(), qs, nil, true, q, false, nil)
1786+
results, err := s.GetFieldNames(qctx, "vl_")
1787+
if err != nil {
1788+
t.Fatalf("unexpected error: %s", err)
1789+
}
1790+
1791+
resultsExpected := []ValueWithHits{
1792+
{"vl_account_id", 3},
1793+
{"vl_project_id", 3},
1794+
}
1795+
if !reflect.DeepEqual(results, resultsExpected) {
1796+
t.Fatalf("unexpected result; got\n%v\nwant\n%v", results, resultsExpected)
1797+
}
1798+
}
1799+
17521800
func TestGetTenantFilter(t *testing.T) {
17531801
t.Parallel()
17541802

0 commit comments

Comments
 (0)