Repository: apache/kafka
File: metadata/src/main/java/org/apache/kafka/controller/QuorumController.java (Java)

Code before:
    private void handleEventEnd(String name, long startProcessingTimeNs) {
        long endProcessingTime = time.nanoseconds();
        long deltaNs = endProcessingTime - startProcessingTimeNs;
        log.debug("Processed {} in {} us", name,
            MICROSECONDS.convert(deltaNs, NANOSECONDS));
        performanceMonitor.observeEvent(name, deltaNs);
        controllerMetrics.updateEventQueueProcessingTime(NANOSECONDS.toMillis(deltaNs));
        controllerMetrics.updateIdleStartTime();
    }

    private Throwable handleEventException(
        String name,
        OptionalLong startProcessingTimeNs,
        Throwable exception
    ) {
        OptionalLong deltaUs;
        if (startProcessingTimeNs.isPresent()) {
            long endProcessingTime = time.nanoseconds();
            long deltaNs = endProcessingTime - startProcessingTimeNs.getAsLong();
            performanceMonitor.observeEvent(name, deltaNs);
            controllerMetrics.updateEventQueueProcessingTime(NANOSECONDS.toMillis(deltaNs));
            deltaUs = OptionalLong.of(MICROSECONDS.convert(deltaNs, NANOSECONDS));
        } else {
            deltaUs = OptionalLong.empty();
        }
        controllerMetrics.updateIdleStartTime();
        EventHandlerExceptionInfo info = EventHandlerExceptionInfo.
                fromInternal(exception, this::latestController);
        int epoch = curClaimEpoch;
        if (epoch == -1) {
            epoch = offsetControl.lastCommittedEpoch();
        }
        String failureMessage = info.failureMessage(epoch, deltaUs,
                isActiveController(), offsetControl.lastCommittedOffset());
        if (info.isTimeoutException() && (deltaUs.isEmpty())) {
            controllerMetrics.incrementOperationsTimedOut();
        }
        if (info.isFault()) {
            nonFatalFaultHandler.handleFault(name + ": " + failureMessage, exception);
        } else {
            log.info("{}: {}", name, failureMessage);
        }
        if (info.causesFailover() && isActiveController()) {
            renounce();
        }
        return info.effectiveExternalException();
    }

    private long updateEventStartMetricsAndGetTime(OptionalLong eventCreatedTimeNs) {
        long now = time.nanoseconds();
        controllerMetrics.updateIdleEndTime();

Review comment (suggestion):
feels almost like updateIdleStartTime should be tied to/incorporated into updateEventQueueProcessingTime

Code after:
        }
    }

    private OptionalInt latestController() {
        return raftClient.leaderAndEpoch().leaderId();
    }

    private void handleEventEnd(String name, long startProcessingTimeNs) {
        long endProcessingTime = time.nanoseconds();
        long deltaNs = endProcessingTime - startProcessingTimeNs;
        log.debug("Processed {} in {} us", name,
            MICROSECONDS.convert(deltaNs, NANOSECONDS));
        performanceMonitor.observeEvent(name, deltaNs);
        controllerMetrics.updateEventQueueProcessingTime(NANOSECONDS.toMillis(deltaNs));
    }

    private Throwable handleEventException(
        String name,
        OptionalLong startProcessingTimeNs,
        Throwable exception
    ) {
        OptionalLong deltaUs;
        if (startProcessingTimeNs.isPresent()) {
            long endProcessingTime = time.nanoseconds();
            long deltaNs = endProcessingTime - startProcessingTimeNs.getAsLong();
            performanceMonitor.observeEvent(name, deltaNs);
            controllerMetrics.updateEventQueueProcessingTime(NANOSECONDS.toMillis(deltaNs));
            deltaUs = OptionalLong.of(MICROSECONDS.convert(deltaNs, NANOSECONDS));
        } else {
            deltaUs = OptionalLong.empty();
        }
        EventHandlerExceptionInfo info = EventHandlerExceptionInfo.
                fromInternal(exception, this::latestController);
        int epoch = curClaimEpoch;
        if (epoch == -1) {
            epoch = offsetControl.lastCommittedEpoch();
        }
        String failureMessage = info.failureMessage(epoch, deltaUs,
                isActiveController(), offsetControl.lastCommittedOffset());
        if (info.isTimeoutException() && (deltaUs.isEmpty())) {
            controllerMetrics.incrementOperationsTimedOut();
        }
        if (info.isFault()) {
            nonFatalFaultHandler.handleFault(name + ": " + failureMessage, exception);
        } else {
            log.info("{}: {}", name, failureMessage);
        }
        if (info.causesFailover() && isActiveController()) {
            renounce();
        }
        return info.effectiveExternalException();