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

Proposal: Use depends_on for container startup order #568

Closed

Conversation

davidkopp
Copy link
Contributor

@davidkopp davidkopp commented Nov 30, 2023

This PR tries to resolve #567.

It uses depends_on to determine a better startup order, and it checks if the dependent containers are running before starting the respective container.

There are some open questions that have to be discussed. Therefore, this PR is currently more like a proposal.

  • Would this PR be problematic for the current measurement model of the boot phase?
  • What is the best way to check if the dependent containers are ready? The check if their state is "running" is actually not sufficient. A health check as proposed in Way to check if containers have booted #423 would be better
  • What should be configurable regarding the waiting time for dependent containers?
  • The Compose Specification of depends_on states, that it also removes the services in dependency order. I think this is not relevant for GMT. Or is it relevant to have a proper measurement of the removal phase?

@davidkopp davidkopp marked this pull request as ready for review November 30, 2023 12:34
@ArneTR
Copy link
Member

ArneTR commented Dec 1, 2023

That PR looks excellent!

The logic looks sound and from just looking at it should do exactly what depends_on advertises.

Having the healthcheck logic also integrated would be a dream, but I would argue it is more reasonable to merge this first and then we keep the other issue open for people interesting to open a PR on this.

I will give it a more detailed look tomorrow and make a proper review.

Copy link
Member

@ArneTR ArneTR left a comment

Choose a reason for hiding this comment

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

I gave the PR a closer look. The approach is great!

I put some comments and remarks. Please give it a look and share your thoughts.

@davidkopp
Copy link
Contributor Author

@ArneTR Thanks for the review and your helpful comments! I'm a quite inexperienced (Python) programmer, so it is also good for me for learning 😊

I think I have now made all the requested changes.
In addition, I have added one configuration for the waiting loop:

boot:
  wait_time_dependencies: 20

Does this make sense for you?
To be able to execute the tests, this config has to be added to test-config.yml.

@ArneTR
Copy link
Member

ArneTR commented Dec 5, 2023

The key in the config is aptly named. Can you put it under "measurement" though. I think this makes more sense, as we already have config vars there that influence measurements.

So hierarchy would be measurement -> boot -> wait_time_dependencies

  1. Check for long syntax looks good.

  2. I believe the cycle check is not doing what it should. It will find if a resource is lisitng itself, but it does not find a real cycle.
    Imagine a setup of 6 containers that always list the next one, and the last then listing the first again. This will lead to a cycle also and is currently not checked.

Let me know if you need a sample yml.

@davidkopp
Copy link
Contributor Author

The config looks now as follows:

measurement:
   idle-time-start: 10
   idle-time-end: 5
   flow-process-runtime: 3800
   phase-transition-time: 1
   boot:
     wait_time_dependencies: 20
   metric-providers:

Is it the way you had in mind?

The faulty implementation of the cycle detection is a little embarrassing. Should be fixed now.

@ArneTR
Copy link
Member

ArneTR commented Dec 6, 2023

The position of the config option is exactly how I had it in mind, thanks for moving that!

@ribalba can you have a look at the cycle protection implementation and how David implemented it. Am a bit short in time today and tomorrow.
@ribalba Please also create a more complex test case with a bigger hierarchy of the containers with more than one link between containers just be on the safe side.

# Check if there are dependencies defined with 'depends_on'.
# If so, change the order of the services accordingly.
for service_name in services.keys():
order_of_service_names = self.order_service_names(order_of_service_names, service_name)
Copy link
Member

Choose a reason for hiding this comment

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

Hey, thank you for this great PR again. Arne and me just talked about the code and while this code is fully functional we see that it might be hard to maintain in the future as you carry the whole list order_of_service_names or order_array into every sub iteration. While this is fine for now we see that this might be the source of errors in a few years time as it is harder to comprehend. Also this pattern can be the source of errors when doing more complex things. When calling recursive functions it might be better to only pass in the context of the recursion and then handle the building of the list in the parent. Not something we need to fix right now but just as a remark.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on this feedback I created an alternative PR with some refactorings:
#593

@ribalba
Copy link
Member

ribalba commented Dec 12, 2023

As soon as this is merged I will add a more complex test. As I can't write to @davidkopp repo.

@davidkopp
Copy link
Contributor Author

As soon as this is merged I will add a more complex test. As I can't write to @davidkopp repo.

Is it really the case that you don't have the permissions?

The option "Allowing edits by maintainers" is enabled.

If checked, users with write access to green-coding-berlin/green-metrics-tool can add new commits to your 567-depends-on-order branch.

@ribalba
Copy link
Member

ribalba commented Dec 20, 2023

This was merged here #593 (comment)

@ribalba ribalba closed this Dec 20, 2023
@davidkopp davidkopp deleted the 567-depends-on-order branch December 20, 2023 11:13
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.

Compose flag depends_on gets ignored
3 participants