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

Expose deprecation data in Bundle #59

Merged
merged 8 commits into from
Jun 10, 2024

Conversation

Maed223
Copy link
Contributor

@Maed223 Maed223 commented May 14, 2024

Updates sourceBundle’s ModulePackageVersionsResponse type to include registry module deprecation data in the response. This deprecation data is then propagated to the Bundle, where it will be then used within a related tfc-agent PR to add diagnostic warnings about deprecated module versions for stacks .

Related Items

@Maed223 Maed223 force-pushed the TF-12458/expose-deprecation-attributes branch from b8e6fc8 to ef8c8ac Compare June 4, 2024 23:29
@Maed223 Maed223 marked this pull request as ready for review June 5, 2024 00:09
@Maed223 Maed223 changed the title Expose deprecation data in ModulePackageVersionsResponse Expose deprecation data in Bundle Jun 5, 2024
Copy link
Contributor

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Got a couple concerns with this, but they are minor. We should find a way to create a meaningful test

sourcebundle/builder.go Outdated Show resolved Hide resolved
sourceaddrs/source_remote.go Outdated Show resolved Hide resolved
…le, use index to append elements to slice with known length and capacity
@@ -29,6 +29,12 @@ type RegistrySource struct {
subPath string
}

type RegistryVersionDeprecation struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

This type may be in the wrong package, too.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the way you un-nested the thing previously called "RemoteSourceInfo"!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah gotcha. Just to clarify your thinking, would you consider it out of place since it's only used in sourcebundle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And in any case any suggestions where it might be a better fit? No file in particular pops out at me in the package.

Copy link
Contributor Author

@Maed223 Maed223 Jun 6, 2024

Choose a reason for hiding this comment

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

Ended up moving it to package_meta.go in the sourcebundle package, seems to be the best fit.

Included here: 3914531

Copy link

@uturunku1 uturunku1 left a comment

Choose a reason for hiding this comment

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

Thanks for walking me through a demo of the changes. To recap, you'll adjust the "more information" section to include a url that can actually be clicked.
The changes we smoked tested today were through the agent, which is good. But I'd also recommend that you smoke test by building the binary for stacks, running some of their commands in the CLI, and just confirming that nothing is broken over there.
I took a look at your code changes yesterday, and again today. I really like that after you addressed Brandon's comment, the scope of your changes has reduced and simplified, in a good way!
While I am absent, please, continue with Brandon, and if possible with someone from the Stacks project to get their blessing on these changes 🙏

Copy link
Contributor

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Really basic feedback. I didn't smoke test but looks safe

@@ -73,12 +73,14 @@ type Builder struct {
// selected version of each module registry package.
resolvedRegistry map[registryPackageVersion]sourceaddrs.RemoteSource

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a code comment

Suggested change
// resolvedRegistryVersionDeprecations tracks potential deprecations for
// each package version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included 👍 ea8f696

remotePackageDirs: make(map[sourceaddrs.RemotePackage]string),
remotePackageMeta: make(map[sourceaddrs.RemotePackage]*PackageMeta),
resolvedRegistry: make(map[registryPackageVersion]sourceaddrs.RemoteSource),
resolvedRegistryVersionDeprecations: make(map[registryPackageVersion]*RegistryVersionDeprecation),
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly verbose-- plus 'resolved' may refer to the RemoteSource values...

Suggested change
resolvedRegistryVersionDeprecations: make(map[registryPackageVersion]*RegistryVersionDeprecation),
versionDeprecations: make(map[registryPackageVersion]*RegistryVersionDeprecation),

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 we meet in the middle with packageVersionDeprecations?

Included here: ea8f696

Comment on lines 366 to 367
deprecation := b.registryPackageVersionDeprecations[pkgAddr][version]
return deprecation
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought this could panic, but it wont! Neat. No need for a local, though

Suggested change
deprecation := b.registryPackageVersionDeprecations[pkgAddr][version]
return deprecation
return b.registryPackageVersionDeprecations[pkgAddr][version]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included 👍 ea8f696

Comment on lines 694 to 696
if registryDeprecations[pkgAddr.Namespace] == nil {
registryDeprecations[pkgAddr.Namespace] = make(map[versions.Version]*ModulePackageVersionDeprecation)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to reallocate this nested map: https://go.dev/play/p/dmUQYnvF7y_H

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I thought initially as well, but I'm otherwise getting nil pointer exceptions. Any idea why that could be the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually nevermind that 😅, didn't initially catch that you were assigning a map at the index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included 👍 ea8f696

@@ -108,11 +110,17 @@ func OpenDir(baseDir string) (*Bundle, error) {
vs = make(map[versions.Version]sourceaddrs.RemoteSource)
ret.registryPackageSources[pkgAddr] = vs
}
deprecations := ret.registryPackageVersionDeprecations[pkgAddr]
if deprecations == nil {
deprecations = make(map[versions.Version]*RegistryVersionDeprecation)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary reallocation I think (see previous comment)

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 suppose that similar to the above we could just assign the nested map at the index of pkgAddr but I figured to was best to stick with the style of how registryPackageSources is handled above for consistencies sake.

vs := ret.registryPackageSources[pkgAddr]
if vs == nil {
    vs = make(map[versions.Version]sourceaddrs.RemoteSource)
    ret.registryPackageSources[pkgAddr] = vs
}

Copy link
Contributor

@alisdair alisdair left a comment

Choose a reason for hiding this comment

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

Just some minor go-specific thoughts. From a stacks technical point of view, this looks fine to me!

@@ -73,12 +73,16 @@ type Builder struct {
// selected version of each module registry package.
resolvedRegistry map[registryPackageVersion]sourceaddrs.RemoteSource

// resolvedRegistryVersionDeprecations tracks potential deprecations for
// each package version
packageVersionDeprecations map[registryPackageVersion]*RegistryVersionDeprecation
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why this is a map of pointer-to-RegistryVersionDeprecation. Later on we store nil in this map if a registry package version has no deprecation information, rather than having no entry in the map at all. Is that important?

Having a pointer here means we need to be diligent about nil checks, or we'll panic. Would there be a disadvantage to this being map[registryPackageVersion]RegistryVersionDeprecation instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comes from the approach we've taken with how we denote deprecated versions. In essence, when there are no deprecations, the registry api doesn't include it in the Module Version response. So in this waynil denotes an un-deprecated module.

@@ -73,12 +73,16 @@ type Builder struct {
// selected version of each module registry package.
resolvedRegistry map[registryPackageVersion]sourceaddrs.RemoteSource

// resolvedRegistryVersionDeprecations tracks potential deprecations for
// each package version
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is currently just restating the variable name, and some more detail would be helpful. Example future readers' questions you may want to proactively answer (or not! whatever you think is pertinent):

  • Where is the data gathered from?
  • What consumes this data?
  • What's a "potential" deprecation?

While we're here, the field in the comment doesn't match the field name in the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included 👍 be5d907

// resolvedRegistryVersionDeprecations tracks potential deprecations for
// each package version
packageVersionDeprecations map[registryPackageVersion]*RegistryVersionDeprecation

// registryPackageVersions caches responses from module registry calls to
// look up the available versions for a particular module package. Although
// these could potentially change while we're running, we assume that the
// lifetime of a particular Builder is short enough for that not to
// matter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth noting here that this cache includes the deprecation data, as well as the package versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included 👍 be5d907

return vs
}

func extractVersionDeprecationsFromResponse(modPackageInfos []ModulePackageInfo) map[versions.Version]*ModulePackageVersionDeprecation {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is very simple and only called from one site. I think it's more typical go style to inline this instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Included 👍 be5d907

@Maed223 Maed223 merged commit d050c34 into main Jun 10, 2024
9 checks passed
@Maed223 Maed223 deleted the TF-12458/expose-deprecation-attributes branch June 10, 2024 19:15
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