luigidemasi commented on code in PR #27791: URL: https://github.com/apache/camel/pull/27791#discussion_r4270311317
########## components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/internal/SemanticMonitoringService.java: ########## @@ -0,0 +1,430 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.semantic.internal; + +import java.time.Instant; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +import javax.management.ObjectName; +import javax.management.StandardMBean; + +import org.apache.camel.CamelContext; +import org.apache.camel.CamelContextAware; +import org.apache.camel.builder.ThreadPoolBuilder; +import org.apache.camel.semantic.SemanticMetricSource; +import org.apache.camel.semantic.SemanticMonitoringConfiguration; +import org.apache.camel.semantic.SemanticMonitoringEvent; +import org.apache.camel.semantic.SemanticMonitoringSnapshot; +import org.apache.camel.semantic.SemanticMonitoringStore; +import org.apache.camel.spi.CamelEvent; +import org.apache.camel.spi.EventNotifier; +import org.apache.camel.support.EventNotifierSupport; +import org.apache.camel.support.service.ServiceHelper; +import org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy; +import org.apache.camel.util.json.JsonObject; + +/** Bounded read-only projection of supplied measurements, shared by all surfaces. */ +public final class SemanticMonitoringService extends EventNotifierSupport { + private static final Object CREATION_LOCK = new Object(); + private static final int CAPACITY = 100; + private static final int MAX_SOURCES = 32; + private final Map<String, SemanticMetricSource> sources = new LinkedHashMap<>(); + private final Map<String, SemanticMonitoringStore> stores = new LinkedHashMap<>(); + private final Map<String, Cached> latest = new LinkedHashMap<>(); + private SemanticMonitoringConfiguration configuration = new SemanticMonitoringConfiguration(); + private final Map<String, RetainedSample> retainedSamples = new LinkedHashMap<>(); + private final Deque<Cached> history = new ArrayDeque<>(); + private final List<EventNotifier> ownedNotifiers = new ArrayList<>(); + private final List<ObjectName> mbeans = new ArrayList<>(); + private final AtomicLong sourceErrors = new AtomicLong(); + private final AtomicLong storeErrors = new AtomicLong(); + private final AtomicLong dropped = new AtomicLong(); + private final AtomicLong evicted = new AtomicLong(); + private final AtomicLong managementErrors = new AtomicLong(); + private volatile ExecutorService writer; + private ScheduledExecutorService sampler; + private volatile String lastSample; + private final Map<String, Map<String, Object>> sourceHealth = new ConcurrentHashMap<>(); + private final Map<String, Map<String, Object>> storeHealth = new ConcurrentHashMap<>(); + private int omittedSources; + private int omittedStores; Review Comment: Fixed in 673b410779fd: `omittedSources` is now `volatile`. `omittedStores` was removed together with the monitoring-store SPI, so there is no remaining store counter with this visibility issue. _Codex (AI-generated) on behalf of @luigidemasi._ ########## components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/internal/SemanticAuditService.java: ########## @@ -371,27 +395,61 @@ public Invocation begin( observerErrors.incrementAndGet(); } } + EventHelper.notifyAiEvent(context, () -> event); return invocation; } + private Set<String> supportedExtensions(Supplier<Set<String>> capabilities) { + try { + return Set.copyOf(capabilities.get()); + } catch (Exception | AssertionError | LinkageError failure) { + capabilityErrors.incrementAndGet(); + return Set.of(); + } + } + + private boolean hasEventConsumers() { + var management = context.getManagementStrategy(); + if (management != null && management.getStartedEventNotifiers() != null) { + for (var notifier : management.getStartedEventNotifiers()) { + try { + if (!(notifier instanceof SemanticMonitoringService) + && !notifier.isDisabled() && !notifier.isIgnoreAiEvents()) { + return true; + } + } catch (Throwable failure) { + // Match AI event dispatch: a broken listener must not change evaluation or block other listeners. + LOG.warn("Cannot check semantic event listener eligibility", failure); + } + } + } + return false; + } Review Comment: Addressed in 6b0fd299a2fd and 673b410779fd. `MainDurationEventNotifier` and `PlaceholderSummaryEventNotifier` now call `setIgnoreAiEvents(true)`. `MainDurationAliasTest.testDurationDoesNotRequestAiEventCreation` starts Main with its duration notifier and verifies that the lazy AI-event supplier is never invoked. The existing semantic tests also cover absent, disabled, AI-ignoring and broken listeners. `EventConsole.ConsoleEventNotifier` already opts out of AI events. For custom notifiers, the [language guide](https://github.com/apache/camel/blob/e2406d2ff70967d7d0e8f77eb9978b895f370e80/components/camel-ai/camel-semantic/src/main/docs/semantic-language.adoc#L1231) now explicitly documents `setIgnoreAiEvents(true)` / `isIgnoreAiEvents()`, and explains that filtering in `isEnabled(event)` can avoid delivery but cannot avoid constructing the real event. I kept eligibility aligned with `EventHelper` instead of probing with a sentinel: a listener can accept a concrete semantic subtype or an exchange-backed event while rejecting a generic sentinel, which would incorrectly suppress a valid notification. Management being enabled alone does not require semantic event construction. _Codex (AI-generated) on behalf of @luigidemasi._ ########## components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/internal/SemanticMonitoringService.java: ########## @@ -0,0 +1,430 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.semantic.internal; + +import java.time.Instant; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +import javax.management.ObjectName; +import javax.management.StandardMBean; + +import org.apache.camel.CamelContext; +import org.apache.camel.CamelContextAware; +import org.apache.camel.builder.ThreadPoolBuilder; +import org.apache.camel.semantic.SemanticMetricSource; +import org.apache.camel.semantic.SemanticMonitoringConfiguration; +import org.apache.camel.semantic.SemanticMonitoringEvent; +import org.apache.camel.semantic.SemanticMonitoringSnapshot; +import org.apache.camel.semantic.SemanticMonitoringStore; +import org.apache.camel.spi.CamelEvent; +import org.apache.camel.spi.EventNotifier; +import org.apache.camel.support.EventNotifierSupport; +import org.apache.camel.support.service.ServiceHelper; +import org.apache.camel.util.concurrent.ThreadPoolRejectedPolicy; +import org.apache.camel.util.json.JsonObject; + +/** Bounded read-only projection of supplied measurements, shared by all surfaces. */ +public final class SemanticMonitoringService extends EventNotifierSupport { + private static final Object CREATION_LOCK = new Object(); + private static final int CAPACITY = 100; + private static final int MAX_SOURCES = 32; + private final Map<String, SemanticMetricSource> sources = new LinkedHashMap<>(); + private final Map<String, SemanticMonitoringStore> stores = new LinkedHashMap<>(); + private final Map<String, Cached> latest = new LinkedHashMap<>(); + private SemanticMonitoringConfiguration configuration = new SemanticMonitoringConfiguration(); Review Comment: Removed in 673b410779fd: both the `configuration` field and `SemanticMonitoringConfiguration` are gone. The viewer now keeps only current values, refreshed once per second; it has no sampled history or runtime history-interval setting. That removes the stale configuration read entirely. History and retention belong to the external monitoring backend; optional Micrometer/Prometheus export is tracked in [CAMEL-25648](https://issues.apache.org/jira/browse/CAMEL-25648). _Codex (AI-generated) on behalf of @luigidemasi._ ########## docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc: ########## @@ -13,6 +13,42 @@ See the xref:camel-upgrade-recipes-tool.adoc[documentation] page for details. == Upgrading Camel 4.23 to 4.24 +=== camel-semantic - explicit experts + +Every evaluation in the preview semantic API now requires an explicit `expert` registry bean name. +Move block-level `expert` values onto each evaluation in YAML and XML; in Java, move `.expert(...)` +from `SemanticEvaluationsBuilder` to each `SemanticEvaluationBuilder`. + +The `camel.language.semantic.default-expert` and `camel.language.semantic.adapter` options, +`SemanticLanguage.setDefaultExpert` / `setAdapter`, automatic selection of a sole expert, and +`META-INF/services/org/apache/camel/semantic-adapter` discovery are removed. Register an expert +bean explicitly, including its initialization and destruction methods where needed, and reference +it from each evaluation. Expert references accept property placeholders, but do not fall back to +class loading. The default state selector is unchanged. + +The semantic metadata response no longer includes `defaultExpert`, `defaultError` or +`defaultErrorCode`. Operation inspection and completion require an explicit expert reference. + +=== camel-semantic - evaluation-only auditing + +The preview semantic audit API no longer records route actions. `SemanticAuditDecision`, +`SemanticAudit.get(context).decision(...)` and `SemanticObserver.decision(...)` have been removed. +Remove the corresponding decision beans and processor calls from routes. Evaluation auditing is +automatic under the existing audit configuration; normal application routing remains unchanged. +Previously persisted version-1 decision records remain readable and exportable as legacy data. +Semantic audit browsing no longer accepts route-action, namespace or application-correlation filters. +The console's `target` filter is also removed. Event-ID detail responses no longer expand a decision's Review Comment: Added in 6b0fd299a2fd. The [4.24 upgrade guide](https://github.com/apache/camel/blob/e2406d2ff70967d7d0e8f77eb9978b895f370e80/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc#L32) now says that newly captured evaluations use `definition` instead of `target`, instructs consumers and queries to migrate, and notes removal of the console's `target` filter. Previously persisted records retain their original fields. _Codex (AI-generated) on behalf of @luigidemasi._ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
