Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Dec 14, 2023
1 parent aa1b379 commit ebe7390
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
4 changes: 2 additions & 2 deletions runtime/queries/filterutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func FilterNotInClause(col *runtimev1.Expression, values []*runtimev1.Expression
}
}

func FilterLikeClause(col *runtimev1.Expression, val *runtimev1.Expression) *runtimev1.Expression {
func FilterLikeClause(col, val *runtimev1.Expression) *runtimev1.Expression {
return &runtimev1.Expression{
Expression: &runtimev1.Expression_Cond{
Cond: &runtimev1.Condition{
Expand All @@ -54,7 +54,7 @@ func FilterLikeClause(col *runtimev1.Expression, val *runtimev1.Expression) *run
}
}

func FilterNotLikeClause(col *runtimev1.Expression, val *runtimev1.Expression) *runtimev1.Expression {
func FilterNotLikeClause(col, val *runtimev1.Expression) *runtimev1.Expression {
return &runtimev1.Expression{
Expression: &runtimev1.Expression_Cond{
Cond: &runtimev1.Condition{
Expand Down
2 changes: 1 addition & 1 deletion runtime/queries/metricsview_toplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (q *MetricsViewToplist) buildMetricsTopListSQL(mv *runtimev1.MetricsViewSpe
havingClause := ""
if q.Having != nil {
var havingClauseArgs []any
havingClause, havingClauseArgs, err = buildFromExpression(q.Having, nil, dialect)
havingClause, havingClauseArgs, err = buildFromExpression(q.Having, measureAliases, dialect)
if err != nil {
return "", nil, err
}
Expand Down
20 changes: 20 additions & 0 deletions runtime/queries/metricsview_toplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/rilldata/rill/runtime/queries"
"github.com/rilldata/rill/runtime/testruntime"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down Expand Up @@ -38,6 +39,25 @@ func TestMetricsViewsToplist_measure_filters(t *testing.T) {
MetricsView: mv.Spec,
TimeStart: ctr.Result.Min,
TimeEnd: timestamppb.New(maxTime),
Having: &runtimev1.Expression{
Expression: &runtimev1.Expression_Cond{
Cond: &runtimev1.Condition{
Op: runtimev1.Operation_OPERATION_GT,
Exprs: []*runtimev1.Expression{
{
Expression: &runtimev1.Expression_Ident{
Ident: "measure_1",
},
},
{
Expression: &runtimev1.Expression_Val{
Val: structpb.NewNumberValue(3.25),
},
},
},
},
},
},
Sort: []*runtimev1.MetricsViewSort{
{
Name: "domain",
Expand Down
13 changes: 11 additions & 2 deletions runtime/server/observability_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ func safeTimeStr(t *timestamppb.Timestamp) string {
return t.AsTime().String()
}

func filterCount(m *runtimev1.MetricsViewFilter) int {
func filterCount(m *runtimev1.Expression) int {
if m == nil {
return 0
}
return len(m.Include) + len(m.Exclude)
c := 0
switch e := m.Expression.(type) {
case *runtimev1.Expression_Ident:
c++
case *runtimev1.Expression_Cond:
for _, expr := range e.Cond.Exprs {
c += filterCount(expr)
}
}
return c
}

func marshalInlineMeasure(ms []*runtimev1.InlineMeasure) []string {
Expand Down
18 changes: 6 additions & 12 deletions runtime/server/queries_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func (s *Server) MetricsViewAggregation(ctx context.Context, req *runtimev1.Metr
attribute.StringSlice("args.sort.names", marshalMetricsViewAggregationSort(req.Sort)),
attribute.String("args.time_start", safeTimeStr(req.TimeStart)),
attribute.String("args.time_end", safeTimeStr(req.TimeEnd)),
// TODO filter and having
//attribute.Int("args.filter_count", filterCount(req.Filter)),
attribute.Int("args.filter_count", filterCount(req.Where)),
attribute.Int64("args.limit", req.Limit),
attribute.Int64("args.offset", req.Offset),
attribute.Int("args.priority", int(req.Priority)),
Expand Down Expand Up @@ -104,10 +103,9 @@ func (s *Server) MetricsViewToplist(ctx context.Context, req *runtimev1.MetricsV
attribute.Int("args.priority", int(req.Priority)),
attribute.String("args.time_start", safeTimeStr(req.TimeStart)),
attribute.String("args.time_end", safeTimeStr(req.TimeEnd)),
attribute.Int("args.filter_count", filterCount(req.Where)),
attribute.StringSlice("args.sort.names", marshalMetricsViewSort(req.Sort)),
attribute.StringSlice("args.inline_measures", marshalInlineMeasure(req.InlineMeasures)),
// TODO filter and having
//attribute.Int("args.filter_count", filterCount(req.Filter)),
)

s.addInstanceRequestAttributes(ctx, req.InstanceId)
Expand Down Expand Up @@ -177,8 +175,7 @@ func (s *Server) MetricsViewComparison(ctx context.Context, req *runtimev1.Metri
attribute.String("args.dimension", req.Dimension.Name),
attribute.StringSlice("args.measures", measureNames),
attribute.StringSlice("args.sort.names", marshalMetricsViewComparisonSort(req.Sort)),
// TODO filter and having
//attribute.Int("args.filter_count", filterCount(req.Filter)),
attribute.Int("args.filter_count", filterCount(req.Where)),
attribute.Int64("args.limit", req.Limit),
attribute.Int64("args.offset", req.Offset),
attribute.Int("args.priority", int(req.Priority)),
Expand Down Expand Up @@ -253,8 +250,7 @@ func (s *Server) MetricsViewTimeSeries(ctx context.Context, req *runtimev1.Metri
attribute.String("args.time_start", safeTimeStr(req.TimeStart)),
attribute.String("args.time_end", safeTimeStr(req.TimeEnd)),
attribute.String("args.time_granularity", req.TimeGranularity.String()),
// TODO filter and having
//attribute.Int("args.filter_count", filterCount(req.Filter)),
attribute.Int("args.filter_count", filterCount(req.Where)),
attribute.Int("args.priority", int(req.Priority)),
)

Expand Down Expand Up @@ -311,8 +307,7 @@ func (s *Server) MetricsViewTotals(ctx context.Context, req *runtimev1.MetricsVi
attribute.StringSlice("args.inline_measures.names", marshalInlineMeasure(req.InlineMeasures)),
attribute.String("args.time_start", safeTimeStr(req.TimeStart)),
attribute.String("args.time_end", safeTimeStr(req.TimeEnd)),
// TODO filter and having
//attribute.Int("args.filter_count", filterCount(req.Filter)),
attribute.Int("args.filter_count", filterCount(req.Where)),
attribute.Int("args.priority", int(req.Priority)),
)

Expand Down Expand Up @@ -365,8 +360,7 @@ func (s *Server) MetricsViewRows(ctx context.Context, req *runtimev1.MetricsView
attribute.String("args.time_start", safeTimeStr(req.TimeStart)),
attribute.String("args.time_end", safeTimeStr(req.TimeEnd)),
attribute.String("args.time_granularity", req.TimeGranularity.String()),
// TODO filter and having
//attribute.Int("args.filter_count", filterCount(req.Filter)),
attribute.Int("args.filter_count", filterCount(req.Where)),
attribute.StringSlice("args.sort.names", marshalMetricsViewSort(req.Sort)),
attribute.Int("args.limit", int(req.Limit)),
attribute.Int64("args.offset", req.Offset),
Expand Down

0 comments on commit ebe7390

Please sign in to comment.