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

[processor/k8sattributes] Support name:tag@digest image name format #36145

Merged
merged 3 commits into from
Nov 25, 2024

Conversation

spiffyy99
Copy link
Contributor

@spiffyy99 spiffyy99 commented Nov 2, 2024

Description

Fixed issue with k8sattributesprocessor where digest is not properly separated from tag if both are present. used official docker library to perform parsing.

Link to tracking issue

Fixes #36131

Testing

unit tests
integration/e2e tests

Documentation

N/A. Fields are already described correctly, this is simply fixing parsing logic

Copy link

linux-foundation-easycla bot commented Nov 2, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added the processor/k8sattributes k8s Attributes processor label Nov 2, 2024
@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch 2 times, most recently from 8a9c1bd to 90d3a08 Compare November 2, 2024 03:33
@spiffyy99 spiffyy99 marked this pull request as ready for review November 2, 2024 03:33
@spiffyy99 spiffyy99 requested a review from a team as a code owner November 2, 2024 03:33
@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch 4 times, most recently from 09323ed to 828a728 Compare November 2, 2024 17:10
@TylerHelmuth TylerHelmuth requested a review from ChrsMark November 4, 2024 20:17
Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

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

Thank's for working on this @spiffyy99!

I think the fix is in the right direction but I left some concerns.

@spiffyy99
Copy link
Contributor Author

thanks for the review christos.

Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

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

Overall looks good. Could we add a section in the docs describing the logic from https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/36145/files#r1832085419?

processor/k8sattributesprocessor/e2e_test.go Show resolved Hide resolved
processor/k8sattributesprocessor/e2e_test.go Outdated Show resolved Hide resolved
@spiffyy99
Copy link
Contributor Author

Overall looks good. Could we add a section in the docs describing the logic from https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/36145/files#r1832085419?

Already referenced it here: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/36145/files#diff-f9652f665e3a05f0768f863df6d7543c56b7cf671e4d2be1d7086c5d73e7cc3dR12

any other section you think it would be good to mention this?

@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch from a51981f to 6b95457 Compare November 7, 2024 14:35
@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch from 6b95457 to 3859c70 Compare November 7, 2024 15:50
@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch from e09c207 to 25d7678 Compare November 7, 2024 18:54
Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

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

LGTM. Thank's @spiffyy99!

@TylerHelmuth please take a look

processor/k8sattributesprocessor/e2e_test.go Outdated Show resolved Hide resolved
@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch from d9ee59f to 35b2a0b Compare November 8, 2024 16:24
@spiffyy99
Copy link
Contributor Author

@dmitryax @fatsheep9146 @TylerHelmuth could one of you take a look at this? thanks!

// parseAttributesFromImage parses the image name and tag for differently-formatted image names.
// returns "latest" as the default if tag not present. also checks if the image contains a digest.
// if it does, no latest tag is assumed.
func parseNameAndTagFromImage(image string) (name, tag string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use the already available internal docker.ParseImageName function instead?

I would prefer to all components use the same strategy for common functionalities. Note that the shared function cannot parse images with digest at the moment and should be fixed beforehand: #36279

Copy link
Member

Choose a reason for hiding this comment

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

Having a single implementation makes sense.
Also I think the package should be renamed to container and not docker since it doesn't only cover docker.

Copy link
Member

Choose a reason for hiding this comment

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

Since this is a private implementation I am ok moving forward with this approach for now, but I agree it should used the shared function. Created #36418

Copy link
Member

Choose a reason for hiding this comment

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

@spiffyy99 I was gonna merge this before the release but now I want to make our test coverage is still handling when no digest is set. If you get to using docker.ParseImageName before this is merged I'll close the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I can update.

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, looking at this further, wouldn't it be better to use the official docker api code for things like this? i'm sure this regex is correct as well but I'd think that the official one is a better practice (reference.Parse).

another option is we can update docker.ParseImageName to use reference.Parse, but it seems like that function is used in a bunch

i'm not the one maintaining this though, so I don't feel strongly. just pointing it out

Copy link
Member

@TylerHelmuth TylerHelmuth left a comment

Choose a reason for hiding this comment

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

@spiffyy99 your updates to the test give me confidence that we set the new attribute correctly, but are there still tests for latest or v0.112.0 (tests for when no digest is used)?

@spiffyy99
Copy link
Contributor Author

@spiffyy99 your updates to the test give me confidence that we set the new attribute correctly, but are there still tests for latest or v0.112.0 (tests for when no digest is used)?

@TylerHelmuth yes, there are tests with only the version, and no version.

https://github.com/spiffyy99/opentelemetry-collector-contrib/blob/fix-k8s-image-parsing/processor/k8sattributesprocessor/internal/kube/client_test.go#L1496-L1513

this is also in the e2e tests. we have cases with no tag or digest, tag only, digest only, and both.

@spiffyy99 spiffyy99 force-pushed the fix-k8s-image-parsing branch from f9ecf48 to 115ec54 Compare November 25, 2024 01:21
@TylerHelmuth TylerHelmuth merged commit a8a8b6d into open-telemetry:main Nov 25, 2024
158 checks passed
@github-actions github-actions bot added this to the next release milestone Nov 25, 2024
@zarbis
Copy link

zarbis commented Nov 26, 2024

@spiffyy99 thanks for the fix!

shivanthzen pushed a commit to shivanthzen/opentelemetry-collector-contrib that referenced this pull request Dec 5, 2024
…pen-telemetry#36145)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Fixed issue with `k8sattributesprocessor` where digest is not properly
separated from tag if both are present. used official docker library to
perform parsing.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
open-telemetry#36131

<!--Describe what testing was performed and which tests were added.-->
#### Testing
unit tests
integration/e2e tests

<!--Describe the documentation added.-->
#### Documentation
N/A. Fields are already described correctly, this is simply fixing
parsing logic

<!--Please delete paragraphs that you did not use before submitting.-->
ZenoCC-Peng pushed a commit to ZenoCC-Peng/opentelemetry-collector-contrib that referenced this pull request Dec 6, 2024
…pen-telemetry#36145)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Fixed issue with `k8sattributesprocessor` where digest is not properly
separated from tag if both are present. used official docker library to
perform parsing.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
open-telemetry#36131

<!--Describe what testing was performed and which tests were added.-->
#### Testing
unit tests
integration/e2e tests

<!--Describe the documentation added.-->
#### Documentation
N/A. Fields are already described correctly, this is simply fixing
parsing logic

<!--Please delete paragraphs that you did not use before submitting.-->
sbylica-splunk pushed a commit to sbylica-splunk/opentelemetry-collector-contrib that referenced this pull request Dec 17, 2024
…pen-telemetry#36145)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Fixed issue with `k8sattributesprocessor` where digest is not properly
separated from tag if both are present. used official docker library to
perform parsing.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
open-telemetry#36131

<!--Describe what testing was performed and which tests were added.-->
#### Testing
unit tests
integration/e2e tests

<!--Describe the documentation added.-->
#### Documentation
N/A. Fields are already described correctly, this is simply fixing
parsing logic

<!--Please delete paragraphs that you did not use before submitting.-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
processor/k8sattributes k8s Attributes processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[processor/k8sattributes] Support name:tag@digest image name format
7 participants