Skip to content

Commit

Permalink
fix(otelbench): use query title to output, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jun 17, 2024
1 parent fe25f38 commit 3adaf57
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cmd/otelbench/promql_analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (
"io"
"os"
"slices"
"strconv"
"time"
"unicode"
"unicode/utf8"

"github.com/dustin/go-humanize"
"github.com/go-faster/errors"
Expand Down Expand Up @@ -82,12 +85,32 @@ func (a PromQLAnalyze) renderPretty(report PromQLReport, w io.Writer) error {

func (a PromQLAnalyze) renderBenchstat(report PromQLReport, w io.Writer) error {
var recs []benchfmt.Result

for _, q := range report.Queries {
var name []byte
if q.Title != "" {
// Normalize title as benchmark name.
for _, r := range q.Title {
switch {
case unicode.IsSpace(r):
name = append(name, '_')
case !strconv.IsPrint(r):
s := strconv.QuoteRune(r)
name = append(name, s[1:len(s)-1]...)
default:
name = utf8.AppendRune(name, r)
}
}
}
if len(name) == 0 {
name = fmt.Appendf(name, "Query%d", q.ID)
}

rec := benchfmt.Result{
Name: bytes.Join(
[][]byte{
[]byte(`PromQL`),
fmt.Appendf(nil, "Query%d", q.ID),
name,
},
[]byte{'/'},
),
Expand Down

0 comments on commit 3adaf57

Please sign in to comment.