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

FIXME: pass the logger and print the warning inside #1038

Merged

Conversation

anushkamittal20
Copy link
Contributor

References: issue
slack thread

I have made changes to remove the message returned from DecodeLayerMetadataFile and the consequent changes that were required.

@anushkamittal20
Copy link
Contributor Author

@natalieparellano I started working on this issue, and I was hoping to get suggestions on how to tackle this.
Thank you very much!

Copy link
Member

@natalieparellano natalieparellano left a comment

Choose a reason for hiding this comment

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

@anushkamittal20 this looks great! Apologies for the slow reply (I've been out). You are definitely on the right track! It would be good to add a couple tests in layermetadata_test.go. You can construct a "spy" logger for this, if you search for assertLogEntry you'll find where we do something similar elsewhere.

buildpack/layermetadata.go Outdated Show resolved Hide resolved
@anushkamittal20
Copy link
Contributor Author

Thank you very much for the review @natalieparellano.
I will try to implement the same and push the changes!

@anushkamittal20
Copy link
Contributor Author

@natalieparellano , sorry it took a bit, I have tried to implement the change, and the current implementation works as well. Please let me know if you need any corrections. Thank you for taking the time to help!
I also wanted to confirm how we can tackle this . Since we will no longer return the message string, there is a part of the code I have commented.

if msg != "" {
 	if api.MustParse(l.api).LessThan("0.6") {
 		l.logger.Warn(msg)
 	} else {
 		return LayerMetadata{}, errors.New(msg)
 	}
 } 

Thank you!

@jjbustamante
Copy link
Member

@anushkamittal20 I think you forgot to run make format before pushing your code and the CI failed, just do that, run make format in your local environment and then push the changes.

@natalieparellano
Copy link
Member

@anushkamittal20 I think (though I'm not sure) that the logic you quoted should move inside DecodeLayerMetadataFile around where we call decoder.Decode in that function. We have the buildpack API at that point, so we can log or return an error depending on the version.

@anushkamittal20
Copy link
Contributor Author

@jjbustamante, I will run make format and push it. Thank you for letting me know!
@natalieparellano, I will try to move the logic in DecodeLayerMetadataFile and see if that works all right, thank you for your feedback. That was helpful!
P.S. Sorry for the delay, I will implement these changes and push them to the branch.

@natalieparellano
Copy link
Member

Looks like it needs another make format

@natalieparellano
Copy link
Member

@anushkamittal20 any update on this one?

@anushkamittal20
Copy link
Contributor Author

anushkamittal20 commented Apr 14, 2023

@natalieparellano wanted to update you on this.
The required changes are done.
I was facing dependency issues on my OS and wasn't able to run make format I am currently trying to resolve the issues or work around them. Will push the new changes ASAP.

Signed-off-by: anushkamittal20 <[email protected]>
buildpack/build.go Outdated Show resolved Hide resolved
buildpack/build.go Outdated Show resolved Hide resolved
Signed-off-by: anushkamittal20 <[email protected]>
Signed-off-by: anushkamittal20 <[email protected]>
@anushkamittal20 anushkamittal20 marked this pull request as ready for review April 18, 2023 05:25
@anushkamittal20 anushkamittal20 requested a review from a team as a code owner April 18, 2023 05:25
Comment on lines 54 to 57
logger.Warn(str)
if !api.MustParse(buildpackAPI).LessThan("0.6") {
return LayerMetadataFile{}, errors.New(str)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
logger.Warn(str)
if !api.MustParse(buildpackAPI).LessThan("0.6") {
return LayerMetadataFile{}, errors.New(str)
}
if api.MustParse(buildpackAPI).LessThan("0.6") {
logger.Warn(str)
} else {
return LayerMetadataFile{}, errors.New(str)
}

I think this is what we want... the test failures may be due to a test needing to be updated

h.AssertEq(t, lmf.Cache, true)
h.AssertEq(t, lmf.Build, false)
h.AssertEq(t, lmf.Launch, false)
})
it("metadata file in wrong format", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it("metadata file in wrong format", func() {
it("logs a warning when the metadata file has wrong format (on older apis)", func() {

Copy link
Member

Choose a reason for hiding this comment

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

We can make another it block for returns an error when the metadata file has wrong format that provides a newer buildpack API on the equivalent of line 59

h.AssertNil(t, err)

var lmf buildpack.LayerMetadataFile
lmf, _ = buildpack.DecodeLayerMetadataFile(metadataFile.Name(), "0.9", logger)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
lmf, _ = buildpack.DecodeLayerMetadataFile(metadataFile.Name(), "0.9", logger)
lmf, err := buildpack.DecodeLayerMetadataFile(metadataFile.Name(), "0.5", logger)
h.AssertNil(t, err)

@natalieparellano
Copy link
Member

@anushkamittal20 thanks for taking another look at this. I think it's on the right track, we just need two different test cases for old and new buildpack API.

@anushkamittal20
Copy link
Contributor Author

Hey @natalieparellano, thank you very much for your review.
I will work on the suggested changes and get back to you!

Signed-off-by: anushkamittal20 <[email protected]>
Signed-off-by: anushkamittal20 <[email protected]>
Signed-off-by: anushkamittal20 <[email protected]>
Copy link
Member

@natalieparellano natalieparellano left a comment

Choose a reason for hiding this comment

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

Looks great! Awesome work @anushkamittal20 - thanks so much for the PR ❤️

@natalieparellano natalieparellano merged commit 5dbedd3 into buildpacks:main May 30, 2023
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.

3 participants