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

fix(tenant/timeline metrics): race condition during shutdown + recreation #7064

Merged
merged 1 commit into from Mar 11, 2024

Conversation

problame
Copy link
Contributor

@problame problame commented Mar 8, 2024

Tenant::shutdown or Timeline::shutdown completes and becomes externally
observable before the corresponding Tenant/Timeline object is dropped.

For example, after observing a Tenant::shutdown to complete, we could
attach the same tenant_id again. The shut down Tenant object might still
be around at the time of the attach.

The race is then the following:

  • old object's metrics are still around
  • new object uses with_label_values
  • old object calls remove_label_values

The outcome is that the new object will have the metric objects (they're
an Arc internall) but the metrics won't be part of the internal registry
and hence they'll be missing in /metrics.

Later, when the new object gets shut down and tries to
remove_label_value, it will observe an error because
the metric was already removed by the old object.

Changes

This PR moves metric removal to shutdown().

An alternative design would be to multi-version the metrics using a
distinguishing label, or, to use a better metrics crate that allows
removing metrics from the registry through the locally held metric
handle instead of interacting with the (globally shared) registry.

refs #7051

Tenant::shutdown or Timeline::shutdown completes and becomes externally
observable before the corresponding Tenant/Timeline object is dropped.

For example, after observing a Tenant::shutdown to complete, we could
attach the same tenant_id again. The shut down Tenant object might still
be around at the time of the attach.

The race is then the following:
- old object's metrics are still around
- new object uses with_label_values
- old object calls remove_label_values

The outcome is that the new object will have the metric objects (they're
an Arc internall) but the metrics won't be part of the internal registry
and hence they'll be missing in `/metrics`.

Later, when the new object gets shut down and tries to
remove_label_value, it will observe an error because
the metric was already removed by the old object.

Changes
-------

This PR moves metric removal to `shutdown()`.

An alternative design would be to multi-version the metrics using a
distinguishing label, or, to use a better metrics crate that allows
removing metrics from the registry through the locally held metric
handle instead of interacting with the (globally shared) registry.
@problame problame requested a review from a team as a code owner March 8, 2024 11:46
@problame problame requested review from VladLazar and koivunej and removed request for VladLazar March 8, 2024 11:46
Copy link

github-actions bot commented Mar 8, 2024

2490 tests run: 2365 passed, 0 failed, 125 skipped (full report)


Code coverage* (full report)

  • functions: 28.8% (7025 of 24428 functions)
  • lines: 47.6% (43445 of 91322 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
89b177e at 2024-03-08T12:30:32.435Z :recycle:

@koivunej
Copy link
Contributor

koivunej commented Mar 8, 2024

Interesting there was no test failures, but I guess that only means we don't have a test creating two tenants/timelines with the same id.

@koivunej
Copy link
Contributor

koivunej commented Mar 11, 2024

Ok, this is interesting. We have yet to merge this. Still, on staging, there are a few "forever attaching" tenants in metrics. I will have to dig deeper then.

EDIT: I understood what causes this; we never reset the time series on startup: #7084

@problame problame merged commit 8224580 into main Mar 11, 2024
53 checks passed
@problame problame deleted the problame/race-free-metrics-removal branch March 11, 2024 14:41
VladLazar pushed a commit that referenced this pull request Mar 12, 2024
…tion (#7064)

Tenant::shutdown or Timeline::shutdown completes and becomes externally
observable before the corresponding Tenant/Timeline object is dropped.

For example, after observing a Tenant::shutdown to complete, we could
attach the same tenant_id again. The shut down Tenant object might still
be around at the time of the attach.

The race is then the following:
- old object's metrics are still around
- new object uses with_label_values
- old object calls remove_label_values

The outcome is that the new object will have the metric objects (they're
an Arc internall) but the metrics won't be part of the internal registry
and hence they'll be missing in `/metrics`.

Later, when the new object gets shut down and tries to
remove_label_value, it will observe an error because
the metric was already removed by the old object.

Changes
-------

This PR moves metric removal to `shutdown()`.

An alternative design would be to multi-version the metrics using a
distinguishing label, or, to use a better metrics crate that allows
removing metrics from the registry through the locally held metric
handle instead of interacting with the (globally shared) registry.

refs #7051
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.

None yet

2 participants