Use counter for tracking container states#29554
Conversation
395cc44 to
17d9b1a
Compare
dnephin
left a comment
There was a problem hiding this comment.
Generally design SGTM, but I do have a question about it
There was a problem hiding this comment.
I think you could do something like:
defer s.UpdateCounter()()func (s *State) UpdateCounter() func() {
oldState := s.StateString()
return func() {
s.counter.SetCount(oldState, s.StateString())
}
}There was a problem hiding this comment.
Isn't this still racy if the container changes state between oldState := s.StateString() and the defer running?
It would reduce the count of the old state twice?
There was a problem hiding this comment.
Ah, you're right the SetCount needs to be done while the lock is held.
aff5310 to
31c805d
Compare
6ed6402 to
4678a2d
Compare
|
@cpuguy83 Is there any way we could leverage the prometheus metrics registry to aggregate this data? |
|
The lock-free proposal (#30225) can close this PR? |
|
@AkihiroSuda I don't think so. Even with a lock-free container, it's still horrible to iterate every single container for |
|
@AkihiroSuda I agree with @cpuguy83 here. Aggregating the entire dataset will be much less reliable than pre-aggregating with counters. @cpuguy83 Any luck getting |
|
@cpuguy83 CI fails :/ |
3877dee to
e25bc83
Compare
|
@stevvooe I have wired in go-metrics here, although I did have to keep a separate counter for reporting to This still has some issue somewhere that so far I've only seen pop in tests where the counts get way off that I need to figure out. |
@cpuguy83 That is a wise decision! @crosbymichael @juliusv Any ideas here? |
There's indeed no way to get the value of a single metric with Prometheus's Go client library, except for calling If you're going to maintain the count yourself anyways, you may want to think about not tracking the state twice, but using throw-away |
|
ping @cpuguy83, what is the status here ? 👼 |
e25bc83 to
9b1a79e
Compare
|
Working on it. |
60b6e01 to
fd78c07
Compare
|
This is all green folks. |
|
Something to consider b/c once metrics are out of experimental we probably ought not change this...
|
dnephin
left a comment
There was a problem hiding this comment.
LGTM
What fixed the counter problems? Was it changing the counters to be per-container containers?
Just started stashing the actual container state when it gets updated rather than calling inc+dec on split states. |
|
LGTM after providing example @crosbymichael PTAL |
|
@cpuguy83 Wondering if we should make an effort to drop the |
|
LGTM Its the best we can do without the ability to query prom metrics in process. , @cpuguy83 not saying your implementation is bad, just working with what we have :) It would be a lot less code if we could query the metric in process and get the values. |
Can you explain what you mean by this? |
|
If we didn't have to query for the info endpoint, you just have a single metric with labels, and you inc/dec the id+state for each of the states, its like 10 lines of code. |
|
@stevvooe Yeah, we could probably simplify the metrics namespace. |
|
@cpuguy83 Right now, it is |
|
@stevvooe Do you have a suggestion? Just remove all-together? |
I think we can remove the prefix, but I'd like to hear @crosbymichael's opinion. We put work into "namespacing" metrics but prometheus already has a lot of context, like "job", "target" and info structs that can be used to create that context. |
|
LGTM |
|
@stevvooe Are you ok if we merge this and talk about namespace separately? |
|
LGTM Let's open a bug to review the namespacing for metrics. |
|
Opened #33056 to discuss. Merging this one since it has all the required LGTM's and is all green. |
Container state counts are used for reporting in the
/infoendpoint.Currently when
/infois called, each container is iterated over andthe containers 'StateString()' is called. This is not very efficient
with lots of containers, and is also racey since
StateString()is notusing a mutex and the mutex is not otherwise locked.
We could just lock the container mutex, but this is proven to be
problematic since there are frequent deadlock scenarios and we should
always have the
/infoendpoint available since this endpoint is usedto get general information about the docker host.
Closes #28912