-
Notifications
You must be signed in to change notification settings - Fork 86
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
runtime/metrics: Delete metrics on object delete #612
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
darkowlzz
added
the
area/runtime
Controller runtime related issues and pull requests
label
Jul 31, 2023
darkowlzz
force-pushed
the
stale-metrics
branch
2 times, most recently
from
July 31, 2023 21:17
b8e2ccb
to
061ec43
Compare
This was referenced Jul 31, 2023
darkowlzz
force-pushed
the
stale-metrics
branch
5 times, most recently
from
August 9, 2023 16:24
9d45642
to
f130fd7
Compare
darkowlzz
force-pushed
the
stale-metrics
branch
2 times, most recently
from
August 10, 2023 13:56
e5ac39e
to
f3f524b
Compare
hiddeco
reviewed
Aug 10, 2023
darkowlzz
force-pushed
the
stale-metrics
branch
2 times, most recently
from
August 10, 2023 19:40
6e1d685
to
a176926
Compare
This was referenced Aug 10, 2023
stefanprodan
approved these changes
Aug 11, 2023
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 @darkowlzz
hiddeco
approved these changes
Aug 11, 2023
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.
Much tidier on the other side of the implementation 🥇
Delete the object metrics when the object is deleted. This ensures that stale metrics about a deleted object is no longer exported. As a result, the `ConditionDelete` is no longer needed. Another reason to not have `ConditionDelete` is that a condition can only be one of True, False or Unknown. This introduces new delete methods in the low level metrics Recorder. In the high level controller metrics, a list of owned finalizers is introduced which is used to determine if an object is being deleted. The existing Record*() methods are updated to check if the given object is deleted, and call record or delete based on that. The user of this API has to pass in the finalizer they write on object they maintain to the metrics helper and record the metrics at the very end of the reconciliation so that the final object state can be used to determine if the metrics can be deleted safely. To allow creating multiple instances of metrics helper, the metrics collector registration is now done using a new function in metrics package called MustMakeRecorder() which returns a metrics.Recorder. metrics.Recorder can be used to create multiple metrics helpers with different attributes if required, sharing the same underlying metrics recorder. Signed-off-by: Sunny <darkowlzz@protonmail.com>
darkowlzz
force-pushed
the
stale-metrics
branch
from
August 11, 2023 13:05
a176926
to
60a95d8
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current metrics
Record*()
methods continues to export the metricsof deleted objects unless the program restarts.
This change deletes the object metrics when the object is deleted. This ensures
that stale metrics about a deleted object is no longer exported.
As a result, the
ConditionDelete
is no longer needed. Another reasonto not have
ConditionDelete
is that a condition can only be one ofTrue, False or Unknown.
This introduces new delete methods in the low level metrics
Recorder
. Inthe high level controller metrics, a list of owned finalizers is
introduced which is used to determine if an object is being deleted.
The existing Record*() methods are updated to check if the given object
is deleted, and call record or delete based on that. The user of this
API has to pass in the finalizer they write on object they maintain to
the metrics helper and record the metrics at the very end of the
reconciliation so that the final object state can be used to determine
if the metrics can be deleted safely.
To allow creating multiple instances of metrics helper, the metrics
collector registration is now done using a new function
MustMakeRecorder()
which returns ametrics.Recorder
.metrics.Recorder
can be used to create multiple metrics helpers with different attributes
if required, sharing the same underlying metrics recorder.
Before this, for a helmrepo and helmchart, the following metrics will continue to be exported even after deleting the helmrepo and helmchart:
This persists for every object in the lifetime of the program.
With this change, all these metrics are deleted once the associated objects are deleted.