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

Add exclusion rules to filter unwanted events #259

Merged
merged 5 commits into from
May 15, 2023

Conversation

acbox
Copy link
Contributor

@acbox acbox commented Apr 27, 2023

No description provided.

@salesforce-cla
Copy link

Thanks for the contribution! Before we can merge this, we need @acbox to sign the Salesforce Inc. Contributor License Agreement.

@hoerup
Copy link
Contributor

hoerup commented May 2, 2023

could possibly solve #206 ?

@hoerup
Copy link
Contributor

hoerup commented May 2, 2023

can the filtering also exclude CRD's ?
and thereby solve #210

Copy link
Collaborator

@nurland nurland left a comment

Choose a reason for hiding this comment

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

Thank you @acbox for the contribution, this is great! Added some comments, but otherwise lgtm

Tiltfile Outdated
@@ -0,0 +1,57 @@
#
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please move this file out to a separate PR, we'd like to keep PRs focused on one feature, thanks!
It would also be great if we can update readme with instructions on how to run tile with sloop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, not sure this warrants a separate PR yet as there were some unresolved issues with the workflow incorporating Tilt. The Tiltfile also relied on running a local cluster with Kind, which is perhaps too opinionated.

@@ -37,3 +37,13 @@ func Contains(stringList []string, elem string) bool {
func GetFilePath(filePath string, fileName string) string {
return path.Join(filePath, fileName)
}

func Truncate(text string, width int) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please add unit tests for Truncate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added unit tests, doing this highlighted some bugs in Truncate that I've fixed.


if !strings.Contains(result1.Payload, `"name":"ns"`) { t.Error("Expected event not found") }
if !strings.Contains(result2.Payload, `"name":"s1"`) { t.Error("Expected event not found") }
if !strings.Contains(result3.Payload, `"name":"s3"`) { t.Error("Expected event not found") }
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we check that "name":"s2" is not present?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you give an example? I found this the most straightforward way. I changed the if statements to assert calls, bit cleaner.

@@ -81,21 +82,58 @@ func Test_bigPicture(t *testing.T) {
masterURL := "url"
kubeContext := "" // empty string makes things work
enableGranularMetrics := true
kw, err := NewKubeWatcherSource(kubeClient, outChan, resync, includeCrds, time.Duration(10*time.Second), masterURL, kubeContext, enableGranularMetrics)
exclusionRules := map[string][]any{
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we also add a test where exclusionRules are not provided, i.e. uses the default value of ExclusionRules: map[string][]any{},

Copy link
Contributor Author

@acbox acbox May 4, 2023

Choose a reason for hiding this comment

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

I've added separate tests for default and non-default exclusion rules

return false
}
var result bytes.Buffer
err = jsonlogic.Apply(
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add err check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

nurland
nurland previously approved these changes May 9, 2023
Copy link
Collaborator

@nurland nurland left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! LGTM

@acbox
Copy link
Contributor Author

acbox commented May 11, 2023

Pushed a fix for the failed GitHub Action test.

nurland
nurland previously approved these changes May 11, 2023
Looks like the ordering for events received from the channel is
non-deterministic. I had changed the tests in this PR to expect events
in an exact order, which passed reliably on my local machine but failed
when run by the GitHub Actions workflow. In this commit I've reverted
the existing big picture test (the one with no exclusion rules) to not
check the payload, and modified the new test (including an exclusion
rule) to:

a) wait 1 second for all events to be received on the channel
b) verify that the excluded event is not received regardless of order
c) verify that the expected number of events is received
@acbox
Copy link
Contributor Author

acbox commented May 15, 2023

This PR should pass the CI tests now as per the commit comment here ae0b4d0

@sana-jawad sana-jawad merged commit f0bd290 into salesforce:master May 15, 2023
@sana-jawad
Copy link
Collaborator

@acbox thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants