Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: return sorted results in certain list endpoints #12054

Merged
merged 1 commit into from
Feb 15, 2022
Merged

Conversation

shoenig
Copy link
Member

@shoenig shoenig commented Feb 11, 2022

These API endpoints now return results in chronological order. They
can return results in reverse chronological order by setting the
query parameter ascending=true.

  • Eval.List
  • Deployment.List

We can add more endpoints following the same pattern. But lets get these out of the way first and see if what we're doing here actually makes sense / is necessary in light of go-bexpr.

Parts of #11742

@vercel vercel bot temporarily deployed to Preview – nomad February 14, 2022 15:29 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad February 14, 2022 16:04 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad February 14, 2022 16:04 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad February 14, 2022 16:50 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad February 14, 2022 17:29 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad February 14, 2022 20:02 Inactive
return args.ShouldBeFiltered(deployment)
}
return false
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we now rely on a _prefix iterator over namespaces, we need to filter out any deployments that erroneously match the prefix. (e.g. want foo, but also matches fooo).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be worth having a test for this? Just to make sure the behaviour or ShouldBeFiltered changes unexpectedly.

@shoenig shoenig marked this pull request as ready for review February 14, 2022 23:37
@shoenig shoenig requested a review from tgross February 14, 2022 23:38
Copy link
Contributor

@lgfa29 lgfa29 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments. I think it would be nice to have a CLI flag as well, but that can come in a follow-up PR.

The api package update question I don't really know the answer, but I think that, without changes, it wouldn't be possible to use the new parameter?

@@ -859,6 +859,8 @@ type EvalDequeueRequest struct {
type EvalListRequest struct {
FilterJobID string
FilterEvalStatus string
FilterNamespace string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a new namespace filter? What's the difference from QueryOptions.Namespace?

nomad/structs/structs.go Show resolved Hide resolved
return args.ShouldBeFiltered(deployment)
}
return false
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be worth having a test for this? Just to make sure the behaviour or ShouldBeFiltered changes unexpectedly.

These API endpoints now return results in chronological order. They
can return results in reverse chronological order by setting the
query parameter ascending=true.

- Eval.List
- Deployment.List
@shoenig shoenig merged commit 07f4227 into main Feb 15, 2022
@shoenig shoenig deleted the b-creation-indexes branch February 15, 2022 21:08
lgfa29 added a commit that referenced this pull request Feb 24, 2022
The paginator logic was built when go-memdb iterators would return items
ordered lexicographically by their prefixes, but #12054 added the option
for some tables to return results ordered by their `CreateIndex`
instead, which invalidated the previous paginator assumption.

This fix changes the paginator so that it skips values that are
different from the token bein searched instead of just smaller ones.
lgfa29 added a commit that referenced this pull request Feb 28, 2022
The paginator logic was built when go-memdb iterators would return items
ordered lexicographically by their ID prefixes, but #12054 added the
option for some tables to return results ordered by their `CreateIndex`
instead, which invalidated the previous paginator assumption.

The iterator used for pagination must still return results in some order
so that the paginator can properly handle requests where the next_token
value is not present in the results anymore (e.g., the eval was GC'ed).

In these situations, the paginator will start the returned page in the
first element right after where the requested token should've been.

This commit moves the logic to generate pagination tokens from the
elements being paginated to the iterator itself so that callers can have
more control over the token format to make sure they are properly
ordered and stable.

It also allows configuring the paginator as being ordered in ascending
or descending order, which is relevant when looking for a token that may
not be present anymore.
lgfa29 added a commit that referenced this pull request Mar 1, 2022
The paginator logic was built when go-memdb iterators would return items
ordered lexicographically by their ID prefixes, but #12054 added the
option for some tables to return results ordered by their `CreateIndex`
instead, which invalidated the previous paginator assumption.

The iterator used for pagination must still return results in some order
so that the paginator can properly handle requests where the next_token
value is not present in the results anymore (e.g., the eval was GC'ed).

In these situations, the paginator will start the returned page in the
first element right after where the requested token should've been.

This commit moves the logic to generate pagination tokens from the
elements being paginated to the iterator itself so that callers can have
more control over the token format to make sure they are properly
ordered and stable.

It also allows configuring the paginator as being ordered in ascending
or descending order, which is relevant when looking for a token that may
not be present anymore.
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants