Skip to content

Commit

Permalink
fix(otelbench): add query type to report
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Dec 6, 2024
1 parent 1acf68d commit 365247d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/otelbench/logql_analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (a LogQLAnalyze) renderBenchstat(report logqlbench.LogQLReport, w io.Writer
Name: bytes.Join(
[][]byte{
[]byte(`LogQL`),
[]byte(q.Type),
name,
},
[]byte{'/'},
Expand Down
1 change: 1 addition & 0 deletions cmd/otelbench/logqlbench/logqlbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func (p *LogQLBenchmark) Run(ctx context.Context) error {
header := tq.Meta.Header()
reports = append(reports, LogQLReportQuery{
ID: header.ID,
Type: string(tq.Meta.Type()),
Title: header.Title,
Description: header.Description,
Query: tq.Meta.Query(),
Expand Down
37 changes: 37 additions & 0 deletions cmd/otelbench/logqlbench/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ import (

// Query is a benchmarked query.
type Query interface {
Type() QueryType
Header() QueryHeader
Query() string
Matchers() []string
Execute(ctx context.Context, client *lokiapi.Client, p *LogQLBenchmark) error
}

// QueryType is a type of query.
type QueryType string

const (
InstantQueryType QueryType = "instant"
RangeQueryType QueryType = "range"
SeriesQueryType QueryType = "series"
LabelsQueryType QueryType = "labels"
LabelValuesQueryType QueryType = "label_values"
)

var _ = []Query{
&InstantQuery{},
&RangeQuery{},
Expand All @@ -44,6 +56,11 @@ type InstantQuery struct {
LogQL string `yaml:"query,omitempty"`
}

// Type returns the query type.
func (q *InstantQuery) Type() QueryType {
return InstantQueryType
}

// Header returns the query header.
func (q *InstantQuery) Header() QueryHeader {
return q.QueryHeader
Expand Down Expand Up @@ -91,6 +108,11 @@ type RangeQuery struct {
LogQL string `yaml:"query,omitempty"`
}

// Type returns the query type.
func (q *RangeQuery) Type() QueryType {
return RangeQueryType
}

// Header returns the query header.
func (q *RangeQuery) Header() QueryHeader {
return q.QueryHeader
Expand Down Expand Up @@ -161,6 +183,11 @@ type SeriesQuery struct {
Match []string `yaml:"match,omitempty"`
}

// Type returns the query type.
func (q *SeriesQuery) Type() QueryType {
return SeriesQueryType
}

// Header returns the query header.
func (q *SeriesQuery) Header() QueryHeader {
return q.QueryHeader
Expand Down Expand Up @@ -210,6 +237,11 @@ type LabelsQuery struct {
End string `yaml:"end,omitempty"`
}

// Type returns the query type.
func (q *LabelsQuery) Type() QueryType {
return LabelsQueryType
}

// Header returns the query header.
func (q *LabelsQuery) Header() QueryHeader {
return q.QueryHeader
Expand Down Expand Up @@ -260,6 +292,11 @@ type LabelValuesQuery struct {
Match string `yaml:"match,omitempty"`
}

// Type returns the query type.
func (q *LabelValuesQuery) Type() QueryType {
return LabelValuesQueryType
}

// Header returns the query header.
func (q *LabelValuesQuery) Header() QueryHeader {
return q.QueryHeader
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 @@ -8,6 +8,7 @@ type LogQLReport struct {

type LogQLReportQuery struct {
ID int `yaml:"id,omitempty"`
Type string `yaml:"type,omitempty"`
Query string `yaml:"query,omitempty"`
Title string `yaml:"title,omitempty"`
Description string `yaml:"description,omitempty"`
Expand Down

0 comments on commit 365247d

Please sign in to comment.