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

[chore] Build docker image for PHP auto-intrumentation #3409

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

SergeyKleyman
Copy link

Description: Part 1 of #3331 that is adding support for auto-instrumentation of PHP application in the same way as it's already implemented for other runtimes such as Java, .NET, etc.
As requested this PR handles the part which is publishing the image.

password: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare files for docker image
run: ./autoinstrumentation/php/prepare_files_for_docker_image.sh --ext-ver ${{ env.VERSION }} --dest-dir ${PWD}/autoinstrumentation/php/files_for_docker_image
Copy link
Contributor

Choose a reason for hiding this comment

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

How about running this inside the Dockerfile? As part of a multi-stage build

Copy link
Author

Choose a reason for hiding this comment

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

Thank you - good idea. I'll try - I wonder if it will work considering that the script runs other docker containers...

Copy link
Author

Choose a reason for hiding this comment

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

I tried running the script in Dockerfile during build but in order for it to work /var/run/docker.sock has to be mounted from the host (because the script spawns docker containers to build various files). Unfortunately it seems it is not possible to mount /var/run/docker.sock from the host during the build phase of docker image.

Copy link
Member

Choose a reason for hiding this comment

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

if it runs other containers, I think it doesnt make much sense to mount the docker sock. It simply makes it harder to execute it on machines with only e.g. podman available.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to second the request to run all of this as a multi-stage docker build instead. That will make it much easier to maintain. I see that the script requires running docker images - in my view, you should instead rework it so the Dockerfile itself accepts the PHP version and libc flavor as arguments. If you can't fit everything in a single Dockerfile, multiple different ones are also fine.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for clarification. I understand that multiple images built by the workflow using QEMU each image for the corresponding CPU architecture, the part about which I am not clear is how the corresponding image is selected at the runtime? Namely how pkg/instrumentation/python.go knows which image to copy files from? Will the correct image with auto-instrumentation files be selected based on CPU architecture used by docker image with the instrumented application? Do I understand correctly that that determination will occur after pkg/instrumentation/python.go execution?

Copy link
Author

Choose a reason for hiding this comment

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

And on a separate note, could you cleanly rebase your changes on main? Right now it looks like you have a very messy merge in there.

Yes, I did rebase your changes on main - should I have done a merge instead of rebase? Is there a way to fix the current messy state?

Copy link
Author

Choose a reason for hiding this comment

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

That said, looking at your build script more, I can see why it wouldn't be that easy to switch to that method

Won't switching to multi-stage image approach (either by generating Dockerfile or writing it manually) handle CPU architecture automatically?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for clarification. I understand that multiple images built by the workflow using QEMU each image for the corresponding CPU architecture, the part about which I am not clear is how the corresponding image is selected at the runtime? Namely how pkg/instrumentation/python.go knows which image to copy files from? Will the correct image with auto-instrumentation files be selected based on CPU architecture used by docker image with the instrumented application? Do I understand correctly that that determination will occur after pkg/instrumentation/python.go execution?

The operator doesn't know the CPU architecture of the image. It could find out, but it doesn't care what it is. The container runtime on the K8s Node (containerd in most cases) will simply download the right image for the Node's CPU architecture.

Won't switching to multi-stage image approach (either by generating Dockerfile or writing it manually) handle CPU architecture automatically?

It will, but a Dockerfile with 6+ build stages, one for each combination of libc+php, is going to be messy and repetitive. I'm wondering if there's an elegant way of handing this.

Copy link
Author

Choose a reason for hiding this comment

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

I agree that neither of the discussed proposals is perfect but this docker image is just a bag of files and it's not used directly by the end user.
Maybe for now we can implement one of the proposals that is good enough, we will get the feature out, receive feedback and then if/when necessary we can improve upon it?

@SergeyKleyman SergeyKleyman changed the title Build docker image for PHP auto-intrumentation [chore] Build docker image for PHP auto-intrumentation Nov 6, 2024
@SergeyKleyman
Copy link
Author

I marked autoinstrumentation/php/prepare_files_for_docker_image.sh as executable and added "[chore]" to the PR title to skip changelog check. Please take a look.

@SergeyKleyman SergeyKleyman marked this pull request as ready for review November 6, 2024 12:39
@SergeyKleyman SergeyKleyman requested a review from a team as a code owner November 6, 2024 12:39
@swiatekm
Copy link
Contributor

@SergeyKleyman can you clean this branch up so Github doesn't show all the changes from main?

@SergeyKleyman
Copy link
Author

@SergeyKleyman can you clean this branch up so Github doesn't show all the changes from main?

Sure thing - I am not an Git expert though so maybe you can help me out with exact git commands to achieve that? I think I caused the current situation because I rebased my branch on main and then I did pull-then-push while maybe the right way would have been to force-push without pull ? I just thought that force-pushing to published branch is kind of "bad" thing. So maybe you can help me with the following two questions:

  1. Do I understand correctly that the right way to rebase on the current main would have been to rebase local clone and then force-push?
  2. How can I fix the current state so that this PR shows only my changes on top of main?

Thank you in advance.

@SergeyKleyman
Copy link
Author

  1. Do I understand correctly that the right way to rebase on the current main would have been to rebase local clone and then force-push?
  2. How can I fix the current state so that this PR shows only my changes on top of main?

It seems merging main to my branch fixed the issue so I assume I should have just merged main on the first attempt instead of rebasing on main.

@SergeyKleyman
Copy link
Author

@swiatekm Could you please take a look if there is anything else still needs to be done?

Copy link
Contributor

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

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

I'm ok with this. We can experiment with moving the whole build to Docker after merging. The build script is simple enough as is. @open-telemetry/operator-maintainers please have a look as well, I'm not comfortable merging this without your go-ahead.

Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

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

I think this LGTM. the bash code was actually incredibly readable so good on you :D

One minor thing, let's include php in the versions.txt file which rn just won't be read by anything.

@SergeyKleyman
Copy link
Author

I think this LGTM. the bash code was actually incredibly readable so good on you :D

One minor thing, let's include php in the versions.txt file which rn just won't be read by anything.

Done. Please take a look.

@SergeyKleyman
Copy link
Author

Could you please let me know what is the next step to get this PR merged?

@swiatekm swiatekm requested a review from pavolloffay December 10, 2024 11:48
@swiatekm
Copy link
Contributor

@pavolloffay could you also have a look?

@SergeyKleyman no need to do anything else on your end. Supporting autoinstrumentation in a new language is simply a big decision, and we want to have wide consensus before merging it.

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.

5 participants