Skip to content

Commit

Permalink
Decouple from/to filtering in history log RPC. (#3929)
Browse files Browse the repository at this point in the history
Currently, ListEvaluationHistory RPC forces the client to either
specify both from and to or none of them, but the logic behind the
extracted data would allow them to be specified independently.

This change decouples from and to, making the underlying statement a
tiny bit more uniform.
  • Loading branch information
blkt authored Jul 24, 2024
1 parent ab39885 commit ac3241f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
5 changes: 2 additions & 3 deletions database/query/eval_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ SELECT s.id::uuid AS evaluation_id,
AND (sqlc.slice(notAlerts)::alert_status_types[] IS NULL OR ae.status != ANY(sqlc.slice(notAlerts)::alert_status_types[]))
AND (sqlc.slice(notStatuses)::eval_status_types[] IS NULL OR s.status != ANY(sqlc.slice(notStatuses)::eval_status_types[]))
-- time range filter
AND (sqlc.narg(fromts)::timestamp without time zone IS NULL
OR sqlc.narg(tots)::timestamp without time zone IS NULL
OR s.evaluation_time BETWEEN sqlc.narg(fromts) AND sqlc.narg(tots))
AND (sqlc.narg(fromts)::timestamp without time zone IS NULL OR s.evaluation_time >= sqlc.narg(fromts))
AND (sqlc.narg(tots)::timestamp without time zone IS NULL OR s.evaluation_time < sqlc.narg(tots))
-- implicit filter by project id
AND j.id = sqlc.arg(projectId)
ORDER BY
Expand Down
5 changes: 2 additions & 3 deletions internal/db/eval_history.sql.go

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

6 changes: 0 additions & 6 deletions internal/history/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,6 @@ func NewListEvaluationFilter(opts ...FilterOpt) (ListEvaluationFilter, error) {
if filter.projectID == uuid.Nil {
return nil, fmt.Errorf("%w: missing", ErrInvalidProjectID)
}
if filter.to != nil && filter.from == nil {
return nil, fmt.Errorf("%w: from is missing", ErrInvalidTimeRange)
}
if filter.from != nil && filter.to == nil {
return nil, fmt.Errorf("%w: to is missing", ErrInvalidTimeRange)
}
if filter.from != nil && filter.to != nil && filter.from.After(*filter.to) {
return nil, fmt.Errorf("%w: from is greated than to", ErrInvalidTimeRange)
}
Expand Down
12 changes: 10 additions & 2 deletions internal/history/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ func TestListEvaluationFilter(t *testing.T) {
WithTo(now),
)
},
err: true,
check: func(t *testing.T, filter ListEvaluationFilter) {
t.Helper()
require.Nil(t, filter.GetFrom())
require.Equal(t, now, *filter.GetTo())
},
},
{
name: "no to",
Expand All @@ -237,7 +241,11 @@ func TestListEvaluationFilter(t *testing.T) {
WithFrom(now),
)
},
err: true,
check: func(t *testing.T, filter ListEvaluationFilter) {
t.Helper()
require.Equal(t, now, *filter.GetFrom())
require.Nil(t, filter.GetTo())
},
},
{
name: "from after to",
Expand Down

0 comments on commit ac3241f

Please sign in to comment.