-
Notifications
You must be signed in to change notification settings - Fork 219
feat: feat controller queue size, execution thread count #1649
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,28 +5,55 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.javaoperatorsdk.operator.OperatorException; | ||
import io.javaoperatorsdk.operator.api.monitoring.Metrics; | ||
import io.javaoperatorsdk.operator.api.reconciler.Constants; | ||
import io.javaoperatorsdk.operator.api.reconciler.RetryInfo; | ||
import io.javaoperatorsdk.operator.processing.Controller; | ||
import io.javaoperatorsdk.operator.processing.GroupVersionKind; | ||
import io.javaoperatorsdk.operator.processing.event.Event; | ||
import io.javaoperatorsdk.operator.processing.event.ResourceID; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tag; | ||
import io.micrometer.core.instrument.Timer; | ||
|
||
import static io.javaoperatorsdk.operator.api.reconciler.Constants.CONTROLLER_NAME; | ||
|
||
public class MicrometerMetrics implements Metrics { | ||
|
||
private static final String PREFIX = "operator.sdk."; | ||
private static final String RECONCILIATIONS = "reconciliations."; | ||
private static final String RECONCILER_EXECUTING_THREADS = "reconciler.executions."; | ||
private static final String CONTROLLER_QUEUE_SIZE = "reconciler.queue."; | ||
private final MeterRegistry registry; | ||
private final Map<String, AtomicInteger> gauges = new ConcurrentHashMap<>(); | ||
|
||
public MicrometerMetrics(MeterRegistry registry) { | ||
this.registry = registry; | ||
} | ||
|
||
@Override | ||
public void controllerRegistered(Controller<?> controller) { | ||
String executingThreadsName = | ||
RECONCILER_EXECUTING_THREADS + controller.getConfiguration().getName(); | ||
AtomicInteger executingThreads = | ||
registry.gauge(executingThreadsName, | ||
gvkTags(controller.getConfiguration().getResourceClass()), | ||
new AtomicInteger(0)); | ||
gauges.put(executingThreadsName, executingThreads); | ||
|
||
String controllerQueueName = CONTROLLER_QUEUE_SIZE + controller.getConfiguration().getName(); | ||
AtomicInteger controllerQueueSize = | ||
registry.gauge(controllerQueueName, | ||
gvkTags(controller.getConfiguration().getResourceClass()), | ||
new AtomicInteger(0)); | ||
gauges.put(controllerQueueName, controllerQueueSize); | ||
} | ||
|
||
public <T> T timeControllerExecution(ControllerExecution<T> execution) { | ||
final var name = execution.controllerName(); | ||
final var execName = PREFIX + "controllers.execution." + execution.name(); | ||
|
@@ -94,13 +121,35 @@ public void reconcileCustomResource(HasMetadata resource, RetryInfo retryInfoNul | |
"" + retryInfo.map(RetryInfo::getAttemptCount).orElse(0), | ||
RECONCILIATIONS + "retries.last", | ||
"" + retryInfo.map(RetryInfo::isLastAttempt).orElse(true)); | ||
|
||
AtomicInteger controllerQueueSize = | ||
gauges.get(CONTROLLER_QUEUE_SIZE + metadata.get(CONTROLLER_NAME)); | ||
controllerQueueSize.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void finishedReconciliation(HasMetadata resource, Map<String, Object> metadata) { | ||
incrementCounter(ResourceID.fromResource(resource), RECONCILIATIONS + "success", metadata); | ||
} | ||
|
||
@Override | ||
public void reconciliationExecutionStarted(HasMetadata resource, Map<String, Object> metadata) { | ||
AtomicInteger reconcilerExecutions = | ||
gauges.get(RECONCILER_EXECUTING_THREADS + metadata.get(CONTROLLER_NAME)); | ||
reconcilerExecutions.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void reconciliationExecutionFinished(HasMetadata resource, Map<String, Object> metadata) { | ||
AtomicInteger reconcilerExecutions = | ||
gauges.get(RECONCILER_EXECUTING_THREADS + metadata.get(CONTROLLER_NAME)); | ||
reconcilerExecutions.decrementAndGet(); | ||
|
||
AtomicInteger controllerQueueSize = | ||
gauges.get(CONTROLLER_QUEUE_SIZE + metadata.get(CONTROLLER_NAME)); | ||
controllerQueueSize.decrementAndGet(); | ||
} | ||
|
||
public void failedReconciliation(HasMetadata resource, Exception exception, | ||
Map<String, Object> metadata) { | ||
var cause = exception.getCause(); | ||
|
@@ -118,6 +167,12 @@ public void failedReconciliation(HasMetadata resource, Exception exception, | |
return registry.gaugeMapSize(PREFIX + name + ".size", Collections.emptyList(), map); | ||
} | ||
|
||
private List<Tag> gvkTags(Class<? extends HasMetadata> resourceClass) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are several spots where GVK information is added to tags. Could this method be reused elsewhere? Also, it looks like sometimes it's prefixed with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
what do you mean exactly? |
||
final var gvk = GroupVersionKind.gvkFor(resourceClass); | ||
return List.of(Tag.of("group", gvk.group), Tag.of("version", gvk.version), | ||
Tag.of("kind", gvk.kind)); | ||
} | ||
|
||
private void incrementCounter(ResourceID id, String counterName, Map<String, Object> metadata, | ||
String... additionalTags) { | ||
final var additionalTagsNb = | ||
|
Uh oh!
There was an error while loading. Please reload this page.