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

Raise if oscilating mutation is found #1030

Merged

Conversation

mmirecki
Copy link
Contributor

No description provided.

return false, nil
}
if cmp.Equal(original, obj) {
return false, fmt.Errorf("ocilating mutation for %s %s", obj.GroupVersionKind().Group, obj.GroupVersionKind().Kind)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: oscillating

if i == 0 {
return false, nil
}
if cmp.Equal(original, obj) {
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 want to do deep comparisons to find oscillating mutations? This could ~double the cost of mutation as I imagine for large objects the deep comparison is likely the most expensive part. If we get an oscillating mutation, we could just wait for a non-convergence error.

I think the tradeoff here is: if we have a system of 20 mutations and we detect oscillation after the 2nd application, we catch it early, but successful mutations now have ~40 comparisons.

Without this check: if we have the same oscillating system, we detect it after ~20 mutations, but successful mutations now have ~20 comparisons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that if line 92 is true, we will always return, either with an error or without.
The number of mutations will stay the same as before the change, and the number of comparison will be increased by 1 only (always).
If we have 20 mutations, and end after the second iteration, both before the change we have 40 mutation, and 3 comparisons (2 with old, 1 with original).

		if cmp.Equal(old, obj) { // If this is true, we always leave the if with a return
			if i == 0 {
				return false, nil
			}
			if cmp.Equal(original, obj) { // If not true, we return anyway
				return false, fmt.Errorf("ocilating mutation for %s %s", obj.GroupVersionKind().Group, obj.GroupVersionKind().Kind)
			}
			return true, nil // We always return here anyway
		} 

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right, sorry for the invalid feedback!

@mmirecki mmirecki force-pushed the raiseIfOscilatingMutationsWasFound branch 2 times, most recently from afd2f88 to 56fb5bf Compare December 16, 2020 20:16
@codecov-io
Copy link

codecov-io commented Dec 16, 2020

Codecov Report

Merging #1030 (e179a9e) into master (13edcf9) will decrease coverage by 0.15%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1030      +/-   ##
==========================================
- Coverage   46.40%   46.24%   -0.16%     
==========================================
  Files          62       62              
  Lines        4060     4063       +3     
==========================================
- Hits         1884     1879       -5     
- Misses       1932     1936       +4     
- Partials      244      248       +4     
Flag Coverage Δ
unittests 46.24% <33.33%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/mutation/system.go 79.31% <33.33%> (-1.65%) ⬇️
...onstrainttemplate/constrainttemplate_controller.go 53.57% <0.00%> (-1.95%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13edcf9...e179a9e. Read the comment docs.

Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

LGTM, pending dependent reviews

@ritazh @sozercan @shomron thoughts?

@mmirecki mmirecki changed the title WIP: Raise if oscilating mutation is found Raise if oscilating mutation is found Dec 17, 2020
@@ -73,10 +73,10 @@ func (s *System) Upsert(m Mutator) error {
}

// Mutate applies the mutation in place to the given object
Copy link
Member

Choose a reason for hiding this comment

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

Can you pls add a comment about the return values?

Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

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

Just one nit, need to rebase and resolve conflicts

Signed-off-by: mmirecki <mmirecki@redhat.com>
@mmirecki mmirecki force-pushed the raiseIfOscilatingMutationsWasFound branch from 56fb5bf to e179a9e Compare December 22, 2020 10:08
@maxsmythe maxsmythe merged commit 1eed2a3 into open-policy-agent:master Dec 23, 2020
@maxsmythe
Copy link
Contributor

@ritazh Sorry, I merged this without noticing your code comment comment. I added a PR to address it:

#1040

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