Skip to content

Commit

Permalink
fix(otelbench): properly handle lack of reports
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Dec 8, 2024
1 parent 8f5dbb3 commit f93e8f8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
9 changes: 2 additions & 7 deletions cmd/otelbench/chtracker/chtracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chtracker

import (
"context"
"fmt"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -93,7 +92,7 @@ func (t *Tracker[Q]) Track(ctx context.Context, meta Q, cb func(context.Context,
}

// Report iterates over tracked queries.
func (t *Tracker[Q]) Report(ctx context.Context, cb func(context.Context, TrackedQuery[Q], []QueryReport) error) error {
func (t *Tracker[Q]) Report(ctx context.Context, cb func(context.Context, TrackedQuery[Q], []QueryReport, error) error) error {
if err := t.Flush(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -125,11 +124,7 @@ func (t *Tracker[Q]) Report(ctx context.Context, cb func(context.Context, Tracke
for i, result := range queries {
tq := t.queries[i]

if result.Err != nil {
fmt.Printf("Failed to retrieve reports for %q: %s\n", tq.TraceID, result.Err)
}

if err := cb(ctx, tq, result.Reports); err != nil {
if err := cb(ctx, tq, result.Reports, result.Err); err != nil {
return errors.Wrap(err, "report callback")
}
}
Expand Down
12 changes: 11 additions & 1 deletion cmd/otelbench/logqlbench/logqlbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ func (p *LogQLBenchmark) Run(ctx context.Context) error {

var reports []LogQLReportQuery
if err := p.tracker.Report(ctx,
func(ctx context.Context, tq chtracker.TrackedQuery[Query], queries []chtracker.QueryReport) error {
func(ctx context.Context, tq chtracker.TrackedQuery[Query], queries []chtracker.QueryReport, retriveErr error) error {
var errMsg string
if retriveErr != nil {
if errors.Is(retriveErr, context.DeadlineExceeded) {
errMsg = "no queries"
} else {
errMsg = retriveErr.Error()
}
}

header := tq.Meta.Header()
reports = append(reports, LogQLReportQuery{
ID: header.ID,
Expand All @@ -144,6 +153,7 @@ func (p *LogQLBenchmark) Run(ctx context.Context) error {
DurationNanos: tq.Duration.Nanoseconds(),
Queries: queries,
Timeout: tq.Timeout,
ReportError: errMsg,
})
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 @@ -16,4 +16,5 @@ type LogQLReportQuery struct {
Matchers []string `yaml:"matchers,omitempty"`
Queries []chtracker.QueryReport `yaml:"queries,omitempty"`
Timeout bool `yaml:"timeout,omitempty"`
ReportError string `yaml:"report_error,omitempty"`
}
6 changes: 5 additions & 1 deletion cmd/otelbench/promql_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ func (p *PromQL) Run(ctx context.Context) error {

var reports []PromQLReportQuery
if err := p.tracker.Report(ctx,
func(ctx context.Context, tq chtracker.TrackedQuery[promQLQuery], queries []chtracker.QueryReport) error {
func(ctx context.Context, tq chtracker.TrackedQuery[promQLQuery], queries []chtracker.QueryReport, retriveErr error) error {
if retriveErr != nil {
return retriveErr
}

entry := PromQLReportQuery{
ID: tq.Meta.ID,
DurationNanos: tq.Duration.Nanoseconds(),
Expand Down

0 comments on commit f93e8f8

Please sign in to comment.