-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
fix: Avoid duplicated warnings #36579
Conversation
2667f5f
to
75c94f6
Compare
bf7e698
to
a6e058b
Compare
7cb2bd2
to
4ec8538
Compare
4ec8538
to
ebbe1e9
Compare
2417ac4
to
4a65a5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I think this will be a good fix for some of the annoying repeated diagnostics we already have and had no way to effectively filter. I would just add some unit tests for equality/inequality.
d9bfe72
to
c22c9fb
Compare
@@ -92,7 +92,10 @@ func testModuleWithSnapshot(t *testing.T, name string) (*configs.Config, *config | |||
func testModuleInline(t testing.TB, sources map[string]string) *configs.Config { | |||
t.Helper() | |||
|
|||
cfgPath := t.TempDir() | |||
cfgPath, err := filepath.EvalSymlinks(t.TempDir()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off-topic -- wondering what necessitated this? Asking bc of the EvalSymlinks
on Windows problems, so trying to figure out where the legitimate uses are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's somewhat annoying but the easiest way of making tests pass for me.
Specifically, some logic inside of Plan()
and Validate()
evaluates symlinks and so if there are symlinks in the way, we end up with different paths than those that come from t.TempDir()
.
In my case t.TempDir()
points somewhere to /var/tmp/...
whereas /var
is a symlink to /private/var
. I believe this is default on macOS.
internal/tfdiags/diagnostic_base.go
Outdated
@@ -38,3 +38,25 @@ func (d diagnosticBase) FromExpr() *FromExpr { | |||
func (d diagnosticBase) ExtraInfo() interface{} { | |||
return nil | |||
} | |||
|
|||
func (d diagnosticBase) Equals(otherDiag ComparableDiagnostic) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since diagnosticBase
can't implement reliable equality because it doesn't contain the location data, we should probably remove this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would mean sourceless diagnostics become incomparable - what do you suggest we do in tests that need to test for equality then?
terraform/internal/tfdiags/sourceless.go
Lines 10 to 16 in 43ee22f
func Sourceless(severity Severity, summary, detail string) Diagnostic { | |
return diagnosticBase{ | |
severity: severity, | |
summary: summary, | |
detail: detail, | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second look I don't see any test failures anymore - not sure where I saw them before. Either way, I removed the comparison method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why I cannot reproduce those failures locally but the CI does still show 4 failing tests.
We can implement a separate comparison with cmp.Diff
for those tests I suppose - does that sound like a sensible way forward?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TestBackendConfig_Proxy currently uses cmp.Diff
directly, does anything change if tfdiags.AssertDiagnosticsMatch
is used instead?
Edit: It looks like the test passes if the test helper is used instead, which is due to the helper converting diags to RPC-friendly diags before comparison.
5d6ed2c
to
895a5ab
Compare
Currently, some warning diagnostics, such as the following are being duplicated during
terraform plan
Human Interface
Machine Interface
This PR aims to address duplicates such as the one shown above.
As mentioned elsewhere I am not particularly excited about the nature of the solution, where we filter out duplicates. I think ideally we just shouldn't be producing the duplicates but considering the complexity we are dealing with - where the many diagnostics can be produced in many different places and in different goroutines - I find it relatively difficult to implement such a solution in any reasonable time.
On a more positive note, we already have business of comparing diagnostics for equality in tests and so we can now make use of this new logic I'm adding in the PR.
Target Release
1.12.x
CHANGELOG entry