Skip to content

Replace platforms.Format with platforms.FormatAll in user-visible messages and logs.#49973

Merged
vvoland merged 2 commits intomoby:masterfrom
ctalledo:fix-for-48659
May 21, 2025
Merged

Replace platforms.Format with platforms.FormatAll in user-visible messages and logs.#49973
vvoland merged 2 commits intomoby:masterfrom
ctalledo:fix-for-48659

Conversation

@ctalledo
Copy link
Copy Markdown
Collaborator

@ctalledo ctalledo commented May 14, 2025

- What I did

Use platforms.FormatAll (instead of platforms.Format) in user-visible messages and logs, since it includes the image's platform OS version (when set).

@thaJeztah
Copy link
Copy Markdown
Member

We should probably not mark the ticket as fixed until we reviewed the remaining uses (I changed the "fixes" to "addresses"); we can do those separately (changes in this PR look good AFAICS), but make sure that we're not accidentally dropping os.version in places where it shouldn't be dropped.

I had a quick peek (if my IDE is not lying to me), and outside of vendor code, and the good news is that the list is not too long, so probably doable in a follow-up. I found the remaining uses here;

// key is used to synchronize resolutions that can happen in parallel when doing multi-stage.
key := "getconfig::" + ref + "::" + platforms.Format(p)

pm[platforms.Format(p)] = struct{}{}
}
for _, p := range archutil.SupportedPlatforms(noCache) {
if _, ok := pm[platforms.Format(p)]; !ok {

func (i *ImageService) pullTag(ctx context.Context, ref reference.Named, platform *ocispec.Platform, metaHeaders map[string][]string, authConfig *registrytypes.AuthConfig, out progress.Output) error {
var opts []containerd.RemoteOpt
if platform != nil {
opts = append(opts, containerd.WithPlatform(platforms.Format(*platform)))

for _, platform := range imagePlatforms {
ps := platforms.Format(platform)
manifestDesc, _, err := oneLayerPlatformManifest(dir, platform, FileInLayer{Path: "bash", Content: []byte("layer-" + ps)})

for _, platform := range opts.Stored {
ps := platforms.Format(platform)
manifestDesc, _, err := oneLayerPlatformManifest(dir, platform, FileInLayer{Path: "bash", Content: []byte("layer-" + ps)})

@thaJeztah thaJeztah added this to the 28.2.0 milestone May 14, 2025
Comment thread distribution/pull_v2.go
platform = *pp
}
log.G(ctx).Debugf("%s resolved to a manifestList object with %d entries; looking for a %s match", ref, len(mfstList.Manifests), platforms.Format(platform))
log.G(ctx).Debugf("%s resolved to a manifestList object with %d entries; looking for a %s match", ref, len(mfstList.Manifests), platforms.FormatAll(platform))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not for this PR, but we should use structured logs more for entries like these; ideally we would review the names we used for fields in those logs (as I think we're not always consistent); having more structured logs allows easier filtering / querying of logs (more so if they carry consistent fields, which allows correlating logs).

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@ctalledo
Copy link
Copy Markdown
Collaborator Author

ctalledo commented May 14, 2025

I had a quick peek (if my IDE is not lying to me), and outside of vendor code, and the good news is that the list is not too long, so probably doable in a follow-up. I found the remaining uses here;

Thanks @thaJeztah; yes I saw those remaining instances too, but wasn't sure if the change should apply to them because they are functional changes (as opposed to logging / messaging changes).

I'll take a closer look and do another commit on this PR.

@ctalledo ctalledo requested a review from tonistiigi as a code owner May 14, 2025 17:24
@ctalledo
Copy link
Copy Markdown
Collaborator Author

I'll take a closer look and do another commit on this PR.

Done with this, I've added a second commit to this PR; see 7a57e73.

Comment on lines 184 to +185
// key is used to synchronize resolutions that can happen in parallel when doing multi-stage.
key := "getconfig::" + ref + "::" + platforms.Format(p)
key := "getconfig::" + ref + "::" + platforms.FormatAll(p)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could use some extra eyes on this one if changing this one is OK to do

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@tonistiigi: does this PR look OK (in particular the use of FormatAll() above).

Copy link
Copy Markdown
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

This is ok in user messages but may not be fine in places where platform string is passed as input.

Comment thread builder/builder-next/worker/worker.go Outdated
pm := make(map[string]struct{}, len(w.Opt.Platforms))
for _, p := range w.Opt.Platforms {
pm[platforms.Format(p)] = struct{}{}
pm[platforms.FormatAll(p)] = struct{}{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks; I get what you are recommending, but that seems outside the scope of this PR (i.e., you are suggesting a refactoring of the entire function, where as this PR is simply about replacing Format() with FormatAll()).

Can we do what you are suggesting in a follow-up PR?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then don't make changes to this part of the code.

Copy link
Copy Markdown
Collaborator Author

@ctalledo ctalledo May 19, 2025

Choose a reason for hiding this comment

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

Just so I understand: is that because the change I am proposing incorrect? If so where, I don't see the error (and CI is green).

Copy link
Copy Markdown
Member

@tonistiigi tonistiigi May 19, 2025

Choose a reason for hiding this comment

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

The old code is incorrect and the new code is incorrect as well. OSVersion would be incorrect in here in any case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Got it, thanks, I've reverted that part of the change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I assume the change in builder/builder-next/adapters/containerimage/pull.go looks good to you?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like that code was originally added in dbffbe8 (#41601); was this incorrect all this time? 😓

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, never mind; I looked at the wrong part of the diff 🙈 ignore me.

Copy link
Copy Markdown
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

CI is red

@thaJeztah
Copy link
Copy Markdown
Member

We could probably move the second commit to a separate PR if that one still needs looking at (assuming the first one was green)

…sages and logs.

Use FormatAll in user-visible messages and logs, since it includes the image's
platform OS version (when set).

Fixes moby#48659.

Signed-off-by: Cesar Talledo <[email protected]>
@ctalledo
Copy link
Copy Markdown
Collaborator Author

We could probably move the second commit to a separate PR if that one still needs looking at (assuming the first one was green)

No need, CI is green now (I rebased from master).

@ctalledo ctalledo requested a review from vvoland May 19, 2025 17:25
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@ctalledo could you open a tracking ticket to outline the work that's needed as commented by Tonis? Trying to make sure we don't lose track of that.

@thaJeztah
Copy link
Copy Markdown
Member

Also @vvoland PTAL (you have a "request changes" pending)

@ctalledo
Copy link
Copy Markdown
Collaborator Author

@ctalledo could you open a tracking ticket to outline the work that's needed as commented by Tonis? Trying to make sure we don't lose track of that.

Sure: #50037

@vvoland vvoland merged commit a3bee41 into moby:master May 21, 2025
144 checks passed
@ctalledo ctalledo deleted the fix-for-48659 branch May 21, 2025 18:18
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.

c8d: review uses of platforms.Format vs platforms.FormatAll

4 participants