gnodet-bot commented on code in PR #29504: URL: https://github.com/apache/camel/pull/29504#discussion_r4518215395
########## dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthHistory.java: ########## @@ -0,0 +1,91 @@ +/* + * 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.dsl.jbang.core.commands.tui; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Whether each integration was ready and live, second by second over the last minutes, as the TUI read its health: a + * check that went DOWN and came back between two looks at the Health tab is seen on its strip. + */ +final class HealthHistory { + + static final int SECONDS = 300; + /** Not known for that second: before the TUI read the integration, or the integration did not say. */ + static final byte UNKNOWN = -1; + static final byte READY = 1; + static final byte LIVE = 2; + + // per pid: a ring of the last SECONDS seconds, and the second its last value is of + private final Map<String, Ring> rings = new ConcurrentHashMap<>(); + + private static final class Ring { + final byte[] values = new byte[SECONDS]; + long last = -1; + + Ring() { + Arrays.fill(values, UNKNOWN); + } + } + + /** Records the state of the integration at the second (epoch seconds) it was read. */ + void record(IntegrationInfo info, long second) { + if (info.pid == null || info.healthReady == null && info.healthLive == null) { Review Comment: đĄ **Nit:** Parentheses would clarify the operator precedence here â `&&` does bind tighter than `||`, so the guard is correct, but the intent (skip when pid is unknown, **or** when both health states are unknown) is not immediately obvious at a glance: ```suggestion if (info.pid == null || (info.healthReady == null && info.healthLive == null)) { ``` ########## dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/HealthHistory.java: ########## @@ -0,0 +1,91 @@ +/* + * 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.dsl.jbang.core.commands.tui; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Whether each integration was ready and live, second by second over the last minutes, as the TUI read its health: a + * check that went DOWN and came back between two looks at the Health tab is seen on its strip. + */ +final class HealthHistory { + + static final int SECONDS = 300; + /** Not known for that second: before the TUI read the integration, or the integration did not say. */ + static final byte UNKNOWN = -1; + static final byte READY = 1; + static final byte LIVE = 2; + + // per pid: a ring of the last SECONDS seconds, and the second its last value is of + private final Map<String, Ring> rings = new ConcurrentHashMap<>(); + + private static final class Ring { + final byte[] values = new byte[SECONDS]; + long last = -1; + + Ring() { + Arrays.fill(values, UNKNOWN); + } + } + + /** Records the state of the integration at the second (epoch seconds) it was read. */ + void record(IntegrationInfo info, long second) { + if (info.pid == null || info.healthReady == null && info.healthLive == null) { + return; + } + byte value = (byte) ((Boolean.TRUE.equals(info.healthReady) ? READY : 0) + | (Boolean.TRUE.equals(info.healthLive) ? LIVE : 0)); Review Comment: âšī¸ **Heads up (not a bug):** The guard above skips the record only when *both* `healthReady` and `healthLive` are null. When one of them is `null` and the other is known, `Boolean.TRUE.equals(null)` returns `false`, so the null side is recorded as bit-off (not ready / not live). In practice Camel reports both together so this shouldn't matter, but it is worth a comment if someone ever adds an integration that only reports readiness â their liveness would silently show as DOWN instead of UNKNOWN. -- 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]
