Skip to content

Commit

Permalink
feat: add limit to SelectSeries API (#3602)
Browse files Browse the repository at this point in the history
* add limit to SelectSeries API

* Update pkg/model/time_series_merger.go

Co-authored-by: Bryan Huhta <[email protected]>

---------

Co-authored-by: Bryan Huhta <[email protected]>
  • Loading branch information
kolesnikovae and bryanhuhta authored Oct 3, 2024
1 parent 3cc5bd8 commit a3b9a83
Show file tree
Hide file tree
Showing 13 changed files with 529 additions and 203 deletions.
273 changes: 142 additions & 131 deletions api/gen/proto/go/querier/v1/querier.pb.go

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions api/gen/proto/go/querier/v1/querier_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

141 changes: 75 additions & 66 deletions api/gen/proto/go/query/v1/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions api/gen/proto/go/query/v1/query_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/openapiv2/gen/phlare.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,10 @@
"items": {
"type": "string"
}
},
"limit": {
"type": "string",
"format": "int64"
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions api/querier/v1/querier.proto
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ message SelectSeriesRequest {
optional types.v1.TimeSeriesAggregationType aggregation = 7;
// Select stack traces that match the provided selector.
optional types.v1.StackTraceSelector stack_trace_selector = 8;
// Select the top N series by total value.
optional int64 limit = 9;
}

message SelectSeriesResponse {
Expand Down
1 change: 1 addition & 0 deletions api/query/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ message SeriesLabelsReport {
message TimeSeriesQuery {
double step = 1;
repeated string group_by = 2;
int64 limit = 3;
}

message TimeSeriesReport {
Expand Down
3 changes: 2 additions & 1 deletion pkg/frontend/frontend_select_time_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ func (f *Frontend) SelectSeries(
return nil, err
}

return connect.NewResponse(&querierv1.SelectSeriesResponse{Series: m.TimeSeries()}), nil
series := m.Top(int(c.Msg.GetLimit()))
return connect.NewResponse(&querierv1.SelectSeriesResponse{Series: series}), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

querierv1 "github.com/grafana/pyroscope/api/gen/proto/go/querier/v1"
queryv1 "github.com/grafana/pyroscope/api/gen/proto/go/query/v1"
phlaremodel "github.com/grafana/pyroscope/pkg/model"
"github.com/grafana/pyroscope/pkg/validation"
)

Expand Down Expand Up @@ -50,6 +51,7 @@ func (q *QueryFrontend) SelectSeries(
TimeSeries: &queryv1.TimeSeriesQuery{
Step: c.Msg.GetStep(),
GroupBy: c.Msg.GetGroupBy(),
Limit: c.Msg.GetLimit(),
},
}},
})
Expand All @@ -59,5 +61,6 @@ func (q *QueryFrontend) SelectSeries(
if report == nil {
return connect.NewResponse(&querierv1.SelectSeriesResponse{}), nil
}
return connect.NewResponse(&querierv1.SelectSeriesResponse{Series: report.TimeSeries.TimeSeries}), nil
series := phlaremodel.TopSeries(report.TimeSeries.TimeSeries, int(c.Msg.GetLimit()))
return connect.NewResponse(&querierv1.SelectSeriesResponse{Series: series}), nil
}
Loading

0 comments on commit a3b9a83

Please sign in to comment.