Skip to content

daemon/logger/loggerutils: ParseLogTag: fix panic and image ID format, improve test-coverage#52343

Merged
thaJeztah merged 4 commits intomoby:masterfrom
thaJeztah:fix_log_tag
Apr 13, 2026
Merged

daemon/logger/loggerutils: ParseLogTag: fix panic and image ID format, improve test-coverage#52343
thaJeztah merged 4 commits intomoby:masterfrom
thaJeztah:fix_log_tag

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah commented Apr 11, 2026

daemon/logger: Info: touch-up godoc

Update the GoDoc for various methods to be less specific about the underlying
implementation. This struct is currently passed as-is to loggers to allow
setting a templated "tag", but holds various fields that are not documented
for this purpose, and which do not have an explicit method or template-function.

We may want to reimplement that code to be more deliberate on fields and/or
methods intended for templating, but let's start with updating the docs.

daemon/logger/loggerutils: ParseLogTag: improve test-coverage

  • add consts for well-known templating options
  • improve test coverage, and use more realistic values in tests

daemon/logger/loggerutils: ParseLogTag: fix panic and image ID

  • fix a potential panic when using ID() / {{.ID}} or ImageID() / {{.ImagID}}
    if the Info was empty. In practice, this shouldn't happen because it's always
    initialized.
  • fix ImageID() / {{.ImageID}} ("short ID") not trimming the algorithm.

daemon/logger/loggerutils: ParseLogTag: add fast path

Add fast-path for well-known options and skip templating.

- Human readable description for the release notes

Fix `--log-opt "tag={{.ImageID}}"` not stripping the digest's algorithm.

- A picture of a cute animal (not mandatory but encouraged)

Update the GoDoc for various methods to be less specific about the underlying
implementation. This struct is currently passed as-is to loggers to allow
setting a templated "tag", but holds various fields that are not documented
for this purpose, and which do not have an explicit method or template-function.

We may want to reimplement that code to be more deliberate on fields and/or
methods intended for templating, but let's start with updating the docs.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah added this to the 29.4.1 milestone Apr 11, 2026
@github-actions github-actions Bot added the area/daemon Core Engine label Apr 11, 2026
- add consts for well-known templating options
- improve test coverage, and use more realistic values in tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- fix a potential panic when using `ID()` / `{{.ID}}` or `ImageID()` / `{{.ImagID}}`
  if the Info was empty. In practice, this shouldn't happen because it's always
  initialized.
- fix `ImageID()` / `{{.ImageID}}` ("short ID") not trimming the algorithm.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Add fast-path for well-known options and skip templating.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Comment on lines +13 to +22
const (
ctrShortID = "{{.ID}}"
ctrFullID = "{{.FullID}}"
ctrName = "{{.Name}}"
ctrCommand = "{{.Command}}"
imgShortID = "{{.ImageID}}"
imgFullID = "{{.ImageFullID}}"
imgName = "{{.ImageName}}"
hostName = "{{.Hostname}}"
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could consider having consts defined in the client to help creating a template (haven't thought yet what the right shape would be for that).

@@ -10,6 +10,17 @@ import (
// DefaultTemplate defines the defaults template logger should use.
const DefaultTemplate = "{{.ID}}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const DefaultTemplate = "{{.ID}}"
const DefaultTemplate = ctrShortID

should we reuse the const instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I kept it like this, so that it shows up in docs (pkg.go.dev), otherwise it shows as some un-exported var, and I thought it'd be more useful to know "what's this thing" 😂

@thaJeztah thaJeztah merged commit dc75450 into moby:master Apr 13, 2026
212 of 213 checks passed
@thaJeztah thaJeztah deleted the fix_log_tag branch April 13, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants