From 1405062fc0dec4b44f1bd4f078da40344c649e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20CROCQUESEL?= <88554524+scrocquesel@users.noreply.github.com> Date: Mon, 21 Mar 2022 22:25:15 +0100 Subject: [PATCH 1/2] fix: measure total time execution (reconcile/cleanup) --- .../io/javaoperatorsdk/operator/processing/Controller.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 7ee63d760f..41adc2bfea 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -105,7 +105,6 @@ private void initContextIfNeeded(P resource, Context
context) { @Override public DeleteControl cleanup(P resource, Context
context) { - initContextIfNeeded(resource, context); try { return metrics() .timeControllerExecution( @@ -127,6 +126,7 @@ public String successTypeName(DeleteControl deleteControl) { @Override public DeleteControl execute() { + initContextIfNeeded(resource, context); if (hasDeleterDependents) { dependents.stream() .filter(d -> d instanceof Deleter) @@ -147,7 +147,6 @@ public DeleteControl execute() { @Override public UpdateControl
reconcile(P resource, Context
context) throws Exception { - initContextIfNeeded(resource, context); return metrics().timeControllerExecution( new ControllerExecution<>() { @Override @@ -174,6 +173,7 @@ public String successTypeName(UpdateControl
result) { @Override public UpdateControl
execute() throws Exception { + initContextIfNeeded(resource, context); dependents.forEach(dependent -> dependent.reconcile(resource, context)); return reconciler.reconcile(resource, context); } From a1a7eab39a5e77ddd249b4c1ff05c750bc11c17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20CROCQUESEL?= <88554524+scrocquesel@users.noreply.github.com> Date: Mon, 21 Mar 2022 22:25:15 +0100 Subject: [PATCH 2/2] refactor: optimize controller metrics call --- .../operator/processing/Controller.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 41adc2bfea..f0aea0e1e2 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -2,6 +2,7 @@ import java.util.LinkedList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -54,6 +55,8 @@ public class Controller
implements Reconciler
, Cleaner private final boolean contextInitializer; private final boolean hasDeleterDependents; private final boolean isCleaner; + private final Metrics metrics; + public Controller(Reconciler
reconciler, ControllerConfiguration
configuration, @@ -61,6 +64,8 @@ public Controller(Reconciler
reconciler, this.reconciler = reconciler; this.configuration = configuration; this.kubernetesClient = kubernetesClient; + this.metrics = Optional.ofNullable(ConfigurationServiceProvider.instance().getMetrics()) + .orElse(Metrics.NOOP); contextInitializer = reconciler instanceof ContextInitializer; eventSourceManager = new EventSourceManager<>(this); @@ -106,7 +111,7 @@ private void initContextIfNeeded(P resource, Context
context) { @Override public DeleteControl cleanup(P resource, Context
context) { try { - return metrics() + return metrics .timeControllerExecution( new ControllerExecution<>() { @Override @@ -147,7 +152,7 @@ public DeleteControl execute() { @Override public UpdateControl
reconcile(P resource, Context
context) throws Exception { - return metrics().timeControllerExecution( + return metrics.timeControllerExecution( new ControllerExecution<>() { @Override public String name() { @@ -180,12 +185,6 @@ public UpdateControl
execute() throws Exception {
});
}
-
- private Metrics metrics() {
- final var metrics = ConfigurationServiceProvider.instance().getMetrics();
- return metrics != null ? metrics : Metrics.NOOP;
- }
-
@Override
public List context) {
List