Skip to content

Commit b2d98d6

Browse files
authored
fix(thor): Return empty log lines properly for the new engine (#20971)
1 parent 42ab348 commit b2d98d6

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

pkg/engine/compat.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,8 @@ func (b *streamsResultBuilder) CollectRecord(rec arrow.RecordBatch) {
134134
shortName == types.ColumnNameError || shortName == types.ColumnNameErrorDetails):
135135
parsedCol := col.(*array.String)
136136

137-
// TODO: keep errors if --strict is set
138-
// These are reserved column names used to track parsing errors. We are dropping them until
139-
// we add support for --strict parsing.
140-
if shortName == types.ColumnNameError || shortName == types.ColumnNameErrorDetails {
141-
continue
142-
}
137+
isErrorColumn := ident.ColumnType() == types.ColumnTypeGenerated &&
138+
shortName == types.ColumnNameError || shortName == types.ColumnNameErrorDetails
143139

144140
forEachNotNullRowColValue(numRows, parsedCol, func(rowIdx int) {
145141
parsedVal := parsedCol.Value(rowIdx)
@@ -155,7 +151,7 @@ func (b *streamsResultBuilder) CollectRecord(rec arrow.RecordBatch) {
155151
b.rowBuilders[rowIdx].metadataBuilder.Del(shortName)
156152
}
157153
// If the parsed value is empty, the builder won't accept it as it's not a valid Prometheus-style label. We must add it later for LogQL compatibility.
158-
if parsedVal == "" {
154+
if parsedVal == "" && !isErrorColumn {
159155
b.rowBuilders[rowIdx].parsedEmptyKeys = append(b.rowBuilders[rowIdx].parsedEmptyKeys, shortName)
160156
}
161157
})
@@ -167,8 +163,8 @@ func (b *streamsResultBuilder) CollectRecord(rec arrow.RecordBatch) {
167163
lbs := b.rowBuilders[rowIdx].lbsBuilder.Labels()
168164
ts := b.rowBuilders[rowIdx].timestamp
169165
line := b.rowBuilders[rowIdx].line
170-
// Ignore rows that don't have stream labels, log line, or timestamp
171-
if line == "" || ts.IsZero() || lbs.IsEmpty() {
166+
// Ignore rows that don't have stream labels, or timestamp
167+
if ts.IsZero() || lbs.IsEmpty() {
172168
b.resetRowBuilder(rowIdx)
173169
continue
174170
}

pkg/engine/compat_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestStreamsResultBuilder(t *testing.T) {
3030
require.NotNil(t, builder.Build(stats.Result{}, md).Data)
3131
})
3232

33-
t.Run("rows without log line, timestamp, or labels are ignored", func(t *testing.T) {
33+
t.Run("rows without timestamp, or labels are ignored", func(t *testing.T) {
3434
colTs := semconv.ColumnIdentTimestamp
3535
colMsg := semconv.ColumnIdentMessage
3636
colEnv := semconv.NewIdentifier("env", types.ColumnTypeMetadata, types.Loki.String)
@@ -70,7 +70,7 @@ func TestStreamsResultBuilder(t *testing.T) {
7070
err := collectResult(context.Background(), pipeline, builder)
7171

7272
require.NoError(t, err)
73-
require.Equal(t, 0, builder.Len(), "expected no entries to be collected")
73+
require.Equal(t, 1, builder.Len(), "expected 1 entry to be collected")
7474
})
7575

7676
t.Run("successful conversion of labels, log line, timestamp, and structured metadata ", func(t *testing.T) {

pkg/logql/bench/generator.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,12 @@ func (g *Generator) generateEntriesForStream(meta StreamMetadata) []logproto.Ent
381381
}
382382
}
383383

384-
// Generate log line using the application's generators for the selected format
385-
line := app.LogGenerator(level, entryTs, faker)
384+
line := ""
385+
// Leave 3% of logs lines empty
386+
if g.rnd.Float32() > 0.03 {
387+
// Generate log line using the application's generators for the selected format
388+
line = app.LogGenerator(level, entryTs, faker)
389+
}
386390

387391
// Create metadata in a deterministic order
388392
var metadata []logproto.LabelAdapter

pkg/logql/bench/queries/regression/metric-queries.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ queries:
208208
unwrappable_fields:
209209
- ttl
210210
- description: HTTP status code distribution
211-
query: sum by (level) (count_over_time(${SELECTOR} | json [${RANGE}]))
211+
query: sum by (level) (count_over_time(${SELECTOR} | json | __error__="" [${RANGE}]))
212212
kind: metric
213213
time_range:
214214
length: 24h

0 commit comments

Comments
 (0)