Skip to content

Metrics #1059

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

Merged
merged 2 commits into from
Mar 22, 2022
Merged

Metrics #1059

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,13 +55,17 @@ public class Controller<P extends HasMetadata> implements Reconciler<P>, Cleaner
private final boolean contextInitializer;
private final boolean hasDeleterDependents;
private final boolean isCleaner;
private final Metrics metrics;


public Controller(Reconciler<P> reconciler,
ControllerConfiguration<P> configuration,
KubernetesClient kubernetesClient) {
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);
Expand Down Expand Up @@ -105,9 +110,8 @@ private void initContextIfNeeded(P resource, Context<P> context) {

@Override
public DeleteControl cleanup(P resource, Context<P> context) {
initContextIfNeeded(resource, context);
try {
return metrics()
return metrics
.timeControllerExecution(
new ControllerExecution<>() {
@Override
Expand All @@ -127,6 +131,7 @@ public String successTypeName(DeleteControl deleteControl) {

@Override
public DeleteControl execute() {
initContextIfNeeded(resource, context);
if (hasDeleterDependents) {
dependents.stream()
.filter(d -> d instanceof Deleter)
Expand All @@ -147,8 +152,7 @@ public DeleteControl execute() {

@Override
public UpdateControl<P> reconcile(P resource, Context<P> context) throws Exception {
initContextIfNeeded(resource, context);
return metrics().timeControllerExecution(
return metrics.timeControllerExecution(
new ControllerExecution<>() {
@Override
public String name() {
Expand All @@ -174,18 +178,13 @@ public String successTypeName(UpdateControl<P> result) {

@Override
public UpdateControl<P> execute() throws Exception {
initContextIfNeeded(resource, context);
dependents.forEach(dependent -> dependent.reconcile(resource, context));
return reconciler.reconcile(resource, context);
}
});
}


private Metrics metrics() {
final var metrics = ConfigurationServiceProvider.instance().getMetrics();
return metrics != null ? metrics : Metrics.NOOP;
}

@Override
public List<EventSource> prepareEventSources(EventSourceContext<P> context) {
List<EventSource> sources = new LinkedList<>();
Expand Down