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
Move StartedAt time to before starting the container #47003
base: master
Are you sure you want to change the base?
Conversation
/cc @cpuguy83 PTAL if this is what you had in mind; #45445 (comment)
I must admit though that I'm not "stoked" about having to pass the extra arguments; do we know exactly what code-path triggers this? Is this tapering over a bug? (curious if this is because we're setting this state in 2 separate ways; once in |
I don't think we're tapering over a bug. If the monitor was setting the state and overriding the containerStart, then moving the containerStart time earlier wouldn't have fixed the bug, as the monitor would have still overridden it and we would have gotten the exact same results as before. From what I can see it's simply just the issue of there being a lot of code between the actual container start command, and the moment we generate the time prior to this MR. This code takes about 0.2 seconds to execute on my PC, which puts the starting time of the container about 0.2 seconds after the time the container is actually started. My team is trying to time the execution time of arbitrary untrusted code for our product, so we would really like to use docker's internal timing as it's more accurate than the external measuring we're currently doing, but that's not possible when the results are inconsistent and return negative time differences. |
Right, but it looks like this PR changes the semantics of the "StartedAt" field; before this PR, the Both can make sense on their own, but they do carry a different meaning. Unfortunately these are areas that originated from early in the project, where intended behavior was not always documented (if at all), but other code in the same area seems to confirm that the intent was "started" (and running), as Prometheus counters, and container events are also updated there; Lines 214 to 227 in 1f6c42c
However, and it looks like this is where there's a discrepancy; if the process exits before it's considered started, then
|
Is there anything I can do to help out with this? |
Looking at the code (but not being an expert), it now seems like the |
What's the status on this? What are the next steps to take here? |
I would also be curious to the status of this PR |
Personally it's LGTM after addressing #47003 (review) But @thaJeztah @cpuguy83 might have other thoughts here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not pretty but I'm not sure we can make it so in the current design.
LGTM
6aeb775
to
6962bd5
Compare
@vvoland would you be able to review this PR again? I implemented your feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Sorry I forgot that one can't take an address without assigning the expression to a variable.
@vvoland I implemented your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM; there are just some small typos I didn't notice in my suggestion 🙈
4eb341d
to
689ee15
Compare
Thanks ❤️ |
Signed-off-by: Lars Andringa <l.s.andringa@rug.nl> Signed-off-by: LarsSven <l.s.andringa@rug.nl> Replaced boolean parameter by IsZero check Signed-off-by: LarsSven <l.s.andringa@rug.nl> Separated SetRunning into two functions Signed-off-by: LarsSven <l.s.andringa@rug.nl> Apply suggestions from code review Documentation fixes Co-authored-by: Paweł Gronowski <me@woland.xyz> Signed-off-by: LarsSven <l.s.andringa@rug.nl>
689ee15
to
d4f61f9
Compare
Done :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #45445
- What I did
Moby reports the StartedAt and FinishedAt times of containers. The StartedAt time is inaccurate as it is set too late in the container startup process, being set way past the moment the container is started. This not only makes the StartedAt be reported as relatively late, and the difference between StartedAt and FinishedAt be too optimistic, but with very short-lived containers the StartedAt is reported later than the FinishedAt, meaning the container took a negative amount of time to complete.
This MR moves the StartedAt time recording to right before the container is told to start. This makes the code slightly more complex, as the StartedAt time now has to be passed to the moment it can be recorded, but improves the accuracy of the StartedAt time.
Hello-world prior to the change:
"StartedAt": "2023-12-28T22:15:43.373989192Z",
"FinishedAt": "2023-12-28T22:15:43.373677346Z"
Hello-world after the change:
"StartedAt": "2023-12-30T14:19:39.241397794Z",
"FinishedAt": "2023-12-30T14:19:39.423867882Z"
- How I did it
I record the start time using time.Now() right before
ctr.Start
. I then pass this variable to theSetRunning
function, which is called later and actually records the StartedAt time. Previously, this time was generated within the SetRunning function. For all unit tests and the health monitor, I simply generate the time right on the function call (So I pass time.Now() as a parameter). For unit tests, the StartedAt time doesn't matter, and for the monitor, I could not find a better place to record the time prior to SetRunning.- How to verify it
docker inspect
.- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)