joeyutong commented on code in PR #955: URL: https://github.com/apache/flink-agents/pull/955#discussion_r3891956627
########## runtime/src/main/java/org/apache/flink/agents/runtime/metrics/BuiltInExecutionMetrics.java: ########## @@ -0,0 +1,100 @@ +/* + * 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.flink.agents.runtime.metrics; + +import org.apache.flink.agents.api.Event; +import org.apache.flink.agents.api.trace.ExecutionLifecycleEvents; +import org.apache.flink.agents.api.trace.ExecutionTraceContext; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.function.LongSupplier; +import java.util.function.Predicate; + +/** Derives built-in LLM and Tool metrics from execution lifecycle events. */ +final class BuiltInExecutionMetrics { + + private final FlinkAgentsMetricGroupImpl agentMetricGroup; + private final LongSupplier nanoTime; + private final Map<String, ExecutionMetricRecorder> metricRecordersByEntityType; + private final Map<String, Long> activeExecutionStartNanos = new HashMap<>(); Review Comment: Good catch. Child execution start timestamps are now grouped by their parent Action execution and the group is removed when that Action reaches finished, failed, or reused. The new test verifies that cleanup is scoped to the terminated Action and preserves latency state for another active Action. ########## runtime/src/main/java/org/apache/flink/agents/runtime/metrics/BuiltInActionMetrics.java: ########## @@ -19,26 +19,124 @@ package org.apache.flink.agents.runtime.metrics; +import org.apache.flink.agents.api.Event; +import org.apache.flink.agents.api.trace.ExecutionLifecycleEvents; +import org.apache.flink.agents.api.trace.ExecutionTraceContext; import org.apache.flink.metrics.Counter; +import org.apache.flink.metrics.Histogram; import org.apache.flink.metrics.Meter; -/** - * ActionMetricGroup class extends FlinkAgentsMetricGroupImpl and is used to monitor and measure the - * performance metrics of executing actions. It provides metrics for the total number of actions - * executed and the number of actions executed per second. - */ +import java.util.HashMap; +import java.util.Map; +import java.util.OptionalLong; +import java.util.concurrent.TimeUnit; +import java.util.function.LongSupplier; + +/** Tracks execution rate, scheduling latency, and current task/execution counts for one Action. */ public class BuiltInActionMetrics { + static final String ACTION_SCHEDULING_LATENCY_MS = "actionSchedulingLatencyMs"; Review Comment: Agreed. I documented built-in metric names as reserved in their corresponding scopes, both in the RunnerContext Javadocs and the monitoring guide. I kept runtime rejection out of this PR because framework and user metrics currently share the same get-or-create API; enforcing ownership needs a separate registration boundary. ########## runtime/src/main/java/org/apache/flink/agents/runtime/metrics/BuiltInMetrics.java: ########## @@ -41,9 +48,27 @@ public class BuiltInMetrics { private final Counter eventLogWriteFailures; - private final HashMap<String, BuiltInActionMetrics> actionMetricGroups; + private final BuiltInInputRunMetrics inputRunMetrics; + + private final BuiltInExecutionMetrics executionMetrics; + + private final Map<String, BuiltInActionMetrics> actionMetricGroups; public BuiltInMetrics(FlinkAgentsMetricGroupImpl parentMetricGroup, AgentPlan agentPlan) { + this( + parentMetricGroup, + agentPlan, + toolName -> { + Map<String, ?> tools = agentPlan.getResourceProviders().get(ResourceType.TOOL); Review Comment: Agreed. I removed the two-argument constructor and updated both tests to pass an explicit predicate. Production now remains the only source of Tool registration semantics through ResourceCache.hasResource. -- 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]
