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

Let metrics libs handle the atomicity #5738

Merged
merged 6 commits into from Feb 11, 2020
Merged

Conversation

sylr
Copy link
Contributor

@sylr sylr commented Oct 28, 2019

What does this PR do?

Let metrics libs handle the atomicity.

Motivation

Removes an atomic lock that the libs already implement.

Removes a defer call, the less the better until go 1.14.

More

  • Added/updated tests
  • Added/updated documentation

Additional Notes

m.openConnsGauge.With(labelValues...).Set(float64(openConns))
}(labels)
m.openConnsGauge.With(labels...).Add(1)
defer m.openConnsGauge.With(labels...).Add(-1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I restored the defer call instead of moving m.openConnsGauge.With(labels...).Add(-1) after m.next.ServeHTTP(recorder, req) because I've a scenario where, when doing a load testing of an SSE endpoint with rate limiting activated, we never go past m.next.ServeHTTP(recorder, req) and the Gauge is never decremented.

@mpl if you have an idea why I would be really interested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

well, that suggests m.next.ServeHTTP never returns, either because of a deadlock or a blocked channel, does it not?

@ldez ldez added this to To review in v2 via automation Jan 7, 2020
@ldez ldez assigned mpl Feb 4, 2020
@mpl mpl self-requested a review February 4, 2020 10:25
Copy link
Collaborator

@mpl mpl left a comment

Choose a reason for hiding this comment

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

minor fix needed, LGTM otherwise.

pkg/middlewares/metrics/metrics.go Outdated Show resolved Hide resolved
m.openConnsGauge.With(labelValues...).Set(float64(openConns))
}(labels)
m.openConnsGauge.With(labels...).Add(1)
defer m.openConnsGauge.With(labels...).Add(-1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

well, that suggests m.next.ServeHTTP never returns, either because of a deadlock or a blocked channel, does it not?

- Let metrics libs handle the atomicity.
- Pre-allocate labels slice so that append() calls do not need to extend it.

Signed-off-by: Sylvain Rabot <s.rabot@lectra.com>
@sylr sylr changed the base branch from v2.0 to master February 4, 2020 15:33
pkg/middlewares/metrics/metrics.go Outdated Show resolved Hide resolved
ratelimit.toml Outdated Show resolved Hide resolved
@ldez ldez removed the bot/no-merge label Feb 5, 2020
Sylvain Rabot and others added 3 commits February 5, 2020 11:04
Signed-off-by: Sylvain Rabot <s.rabot@lectra.com>
Co-Authored-By: mpl <mathieu.lonjaret@gmail.com>
Signed-off-by: Sylvain Rabot <s.rabot@lectra.com>
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

@ldez ldez added this to the next milestone Feb 11, 2020
Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

LGTM

@sylr
Copy link
Contributor Author

sylr commented Feb 11, 2020

@ldez why did you remove the attempt to create the label slice with the correct size ?

@traefiker traefiker merged commit 8762e51 into traefik:master Feb 11, 2020
v2 automation moved this from To review to Done Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
v2
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants