-
Notifications
You must be signed in to change notification settings - Fork 218
feat: remove CR meters when they are deleted (after a delay) #1805
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
Conversation
I guess the target should be the |
Yes |
15cd69c
to
46a674a
Compare
this.registry = registry; | ||
this.cleanUpDelayInSeconds = cleanUpDelayInSeconds; |
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.
Why is there a delay, why cannot be deleted instantly?
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.
Because you still might want to get the metrics on the deleted resources for a while before the metrics are removed.
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.
true, would worth to write it as a javadoc so it is obvious from code.
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.
Yes, the feature needs to be documented.
@@ -31,9 +31,17 @@ public class MicrometerMetrics implements Metrics { | |||
private static final String RECONCILIATIONS_QUEUE_SIZE = PREFIX + RECONCILIATIONS + "queue.size."; | |||
private final MeterRegistry registry; | |||
private final Map<String, AtomicInteger> gauges = new ConcurrentHashMap<>(); | |||
private final Map<ResourceID, Set<Meter.Id>> metersPerResource = new ConcurrentHashMap<>(); | |||
private final ScheduledExecutorService metersCleaner = Executors.newScheduledThreadPool(10); |
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.
Since the clean is a short running task (I assume), wouldn't' be better to use a Timer?
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.
Because it's usually better to use ScheduledExecutorService
than Timer
. See https://stackoverflow.com/a/409993.
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.
Ok, then the number of Threads should be configurable, and we should use 1 as default.
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.
Actually the whole ScheduledExecutorService should be configurable.
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.
Both delay and thread numbers are configurable. What other aspects would need configuration?
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.
For example bursting the threads (like the cached executor), but I think it fine for now now
@@ -116,6 +124,14 @@ public void receivedEvent(Event event, Map<String, Object> metadata) { | |||
@Override | |||
public void cleanupDoneFor(ResourceID resourceID, Map<String, Object> metadata) { | |||
incrementCounter(resourceID, "events.delete", metadata); | |||
|
|||
// schedule deletion of meters associated with ResourceID | |||
metersCleaner.schedule(() -> { |
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.
Since this is a non trivial logic, we should add unit test.
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.
I'm not sure a unit test makes sense here, though I certainly could add one. What would make more sense would be an integration test to check that the metrics are actually not there anymore, will see how complex that could be to set up.
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.
IMO we should tests every non trivial logic with unit tests, and see at least that the API there is called for every ID eventually.
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.
The logic is trivial: on delete, call remove on all the meters associated with the resource id. I've added an integration test, anyway.
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
238df1e
to
f2c7d9c
Compare
f2c7d9c
to
d9c27e2
Compare
Kudos, SonarCloud Quality Gate passed! |
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.
Made one comment on default otherwise looks good to me
...pport/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetrics.java
Outdated
Show resolved
Hide resolved
* feat: remove CR meters when they are deleted (after a delay) Fixes #1803. Also added documentation for the Metrics feature.
* feat: remove CR meters when they are deleted (after a delay) Fixes #1803. Also added documentation for the Metrics feature.
* feat: remove CR meters when they are deleted (after a delay) Fixes #1803. Also added documentation for the Metrics feature.
Fixes #1803.