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

Exclude profiles with labels from history. #4910

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

blkt
Copy link
Contributor

@blkt blkt commented Nov 7, 2024

Summary

Filter by labels when listing history.

History list showed evaluation results even for profiles having labels. This is different from the behaviour of Profile list and status, which by default only showed results for profiles without labels.

This change makes the behaviour of History list closer to the one Profile list and status by adding a new filter to the ListEvaluationHistory endpoint. Both inclusion and exclusion are supported, and the additional * flag is allowed specifically for inclusion.

Fixes stacklok/minder-stories#102

Change Type

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Unit tested.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@blkt blkt self-assigned this Nov 7, 2024
@blkt blkt requested a review from a team as a code owner November 7, 2024 17:27
@coveralls
Copy link

coveralls commented Nov 7, 2024

Coverage Status

coverage: 54.763% (-0.007%) from 54.77%
when pulling 8edd02a on feat/history-list-exclude-profiles-with-labels
into 67bd38d on main.

@blkt blkt force-pushed the feat/history-list-exclude-profiles-with-labels branch from 8adedfc to 8edd02a Compare November 7, 2024 17:41
Comment on lines 161 to 162
-- implicit filter, exclude all labelled profiles
AND p.labels = ARRAY[]::TEXT[]
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to request the history of a particular labelled profile, or is that currently verboten?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a matter of choice, let me bring this up internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the possibility to filter by labels.

@blkt blkt force-pushed the feat/history-list-exclude-profiles-with-labels branch 6 times, most recently from de835ad to 2cbfaa3 Compare November 13, 2024 11:53
// The default is to return all user-created profiles; the string "*" can
// be used to select all profiles, including system profiles. This syntax
// may be expanded in the future.
repeated string label_filter = 11 [
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a single string, similar to what the evaluation history and list profiles requests have?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filters usable in the history-list endpoint are all repeated string so that they can be sent (e.g. via a REST GET) as separate entries (e.g. ?label_filter=foo&label_filter=bar), as comma separated strings (e.g. ?label_filter=foo,bar), or as a combination of the two.
The handler is responsible for splitting the string and populating the struct input to the service/db layer as an array of strings. Layers outside of the control plane only reason in terms of array of strings.

My understanding of label_filter in Profiles is that it can be only passed as comma separated string, which is supported in this case as well. Additionally, the database layer is responsible for splitting the string, while here the responsibility is separate, which hopefully makes lower interfaces clearer.

TL;DR: it already support comma separated strings of labels, I would keep it this way.

@@ -357,6 +374,29 @@ func (filter *listEvaluationFilter) ExcludedProfileNames() []string {
return filter.excludedProfileNames
}

func (filter *listEvaluationFilter) AddLabel(label string) error {
if label == "!*" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like the same logic that exists in LabelsFromFilter, should it be centralized somewhere so it's not duplicated? https://github.com/mindersec/minder/blob/main/internal/db/domain.go#L49

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that this logic should be shared, but history list RPC splits the responsibility between the controlplane and the service layer, while LabelsFromFilter wraps it in the database layer.

I would update how the LabelsFromFilter works by doing the same as done here, but in a separate PR. I can open a task for proper prioritization.

eleftherias
eleftherias previously approved these changes Nov 14, 2024
History list showed evaluation results even for profiles having
labels. This is different from the behaviour of Profile list and
status, which by default only showed results for profiles without
labels.

This change makes the behaviour of History list closer to the one
Profile list and status by adding a new filter to the
`ListEvaluationHistory` endpoint. Both inclusion and exclusion are
supported, and the additional `*` flag is allowed specifically for
inclusion.

Fixes stacklok/minder-stories#102
@blkt blkt merged commit 290dc7d into main Nov 15, 2024
26 checks passed
@blkt blkt deleted the feat/history-list-exclude-profiles-with-labels branch November 15, 2024 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants