Skip to content

Commit

Permalink
Merge pull request #554 from go-faster/perf/improve-label-lookup
Browse files Browse the repository at this point in the history
perf(chstorage): only query resource attributes for labels
  • Loading branch information
ernado authored Dec 4, 2024
2 parents a588eef + bc62e70 commit 43edb59
Show file tree
Hide file tree
Showing 46 changed files with 1,421 additions and 554 deletions.
14 changes: 12 additions & 2 deletions cmd/otelbench/chtracker/chtracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Tracker[Q any] struct {
type TrackedQuery[Q any] struct {
TraceID string
Duration time.Duration
Timeout bool
Meta Q
}

Expand All @@ -65,15 +66,24 @@ func (t *Tracker[Q]) Track(ctx context.Context, meta Q, cb func(context.Context,
}()
}

if err := cb(ctx, meta); err != nil {
return errors.Wrap(err, "send tracked")
var (
timeout bool
sendErr = cb(ctx, meta)
)
switch {
case sendErr == nil:
case errors.Is(sendErr, context.DeadlineExceeded):
timeout = true
default:
return errors.Wrap(sendErr, "send tracked")
}
duration := time.Since(start)

t.queriesMux.Lock()
t.queries = append(t.queries, TrackedQuery[Q]{
TraceID: traceID,
Duration: duration,
Timeout: timeout,
Meta: meta,
})
t.queriesMux.Unlock()
Expand Down
3 changes: 2 additions & 1 deletion cmd/otelbench/logqlbench/logqlbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (p *LogQLBenchmark) Run(ctx context.Context) error {
// Warmup.
for i := 0; i < p.Warmup; i++ {
if err := p.send(ctx, q); err != nil {
return errors.Wrap(err, "send")
return errors.Wrap(err, "send (warmup)")
}
if err := pb.Add(1); err != nil {
return errors.Wrap(err, "update progress bar")
Expand Down Expand Up @@ -139,6 +139,7 @@ func (p *LogQLBenchmark) Run(ctx context.Context) error {
Matchers: tq.Meta.Match,
DurationNanos: tq.Duration.Nanoseconds(),
Queries: queries,
Timeout: tq.Timeout,
})
return nil
},
Expand Down
1 change: 1 addition & 0 deletions cmd/otelbench/logqlbench/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ type LogQLReportQuery struct {
DurationNanos int64 `yaml:"duration_nanos,omitempty"`
Matchers []string `yaml:"matchers,omitempty"`
Queries []chtracker.QueryReport `yaml:"queries,omitempty"`
Timeout bool `yaml:"timeout,omitempty"`
}
25 changes: 25 additions & 0 deletions dev/local/ch-log-bench-read/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

echo ">> Benchmark"
start_time="2024-11-20T00:00:00Z"
end_time="2024-12-01T00:00:00Z"

queries_file="${BENCH_QUERIES:-testdata/logql.yml}"
benchmark_runs="${BENCH_RUNS:-15}"

OTEL_EXPORTER_OTLP_INSECURE="true" go run github.com/go-faster/oteldb/cmd/otelbench logql bench \
--start "$start_time" \
--end "$end_time" \
-i "$queries_file" \
-o report.yml \
--trace \
--allow-empty=false \
--count "$benchmark_runs"

echo ">> Analyze"
go run github.com/go-faster/oteldb/cmd/otelbench logql analyze \
--input report.yml \
--format benchstat >benchstat.report.txt

echo ">> Benchstat"
benchstat benchstat.report.txt
43 changes: 0 additions & 43 deletions dev/local/ch-log-bench-read/run.sh

This file was deleted.

14 changes: 14 additions & 0 deletions dev/local/ch-log-bench-read/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

echo ">> Setup oteldb locally"
docker compose up -d --remove-orphans --build

DUMP_DIR="${DUMP_DIR:-/tmp/slowdump}"

echo ">> Upload benchmark data"
go run github.com/go-faster/oteldb/cmd/otelbench dump restore \
--truncate \
--database default \
--input "${DUMP_DIR}"
10 changes: 5 additions & 5 deletions dev/local/ch-log-bench-read/testdata/logql.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
range:
- title: Failed POST requests
- title: Lookup by materialzied attribute
query: |-
{http_method="POST"} |= "Error"
series:
- title: All POST series
match: ['{http_method="POST"}']
{level!="DEBUG", service_name="go-faster.oteldb"}
- title: Lookup by regular attribute
query: |-
{operationName="SearchTagValuesV2"}
Loading

0 comments on commit 43edb59

Please sign in to comment.