Copilot commented on code in PR #7390: URL: https://github.com/apache/hbase/pull/7390#discussion_r2483752217
########## hbase-server/src/main/resources/hbase-webapps/canary/canary.jsp: ########## @@ -17,4 +17,135 @@ * limitations under the License. */ --%> -<meta HTTP-EQUIV="REFRESH" content="0;url=/canary-status"/> +<%@ page contentType="text/html;charset=UTF-8" + import="java.util.*" + import="org.apache.hadoop.hbase.ServerName" + import="org.apache.hadoop.hbase.tool.CanaryTool" + import="java.util.concurrent.atomic.LongAdder" + import="org.apache.hadoop.hbase.ServerName" Review Comment: The import `org.apache.hadoop.hbase.ServerName` is duplicated on lines 22 and 25. Remove one of the duplicate imports. ```suggestion ``` ########## hbase-server/src/main/java/org/apache/hadoop/hbase/util/CanaryStatusUtil.java: ########## @@ -0,0 +1,42 @@ +/* + * 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.hadoop.hbase.util; + +import org.apache.hadoop.hbase.ServerName; +import org.apache.yetus.audience.InterfaceAudience; + +/** + * Utility used by the web UI JSP pages. + */ [email protected] +public class CanaryStatusUtil { + + private CanaryStatusUtil() { + // Do not instantiate. + } + + public static String serverNameLink(ServerName serverName) { + int infoPort = serverName.getPort() + 1; + String url = "//" + serverName.getHostname() + ":" + infoPort + "/"; + if (infoPort > 0) { + return "<a href=\"" + url + "\">" + serverName.getServerName() + "</a>"; + } else { + return serverName.getServerName(); + } Review Comment: The logic is incorrect: when `serverName.getPort()` returns -1, `infoPort` becomes 0, but the condition checks `if (infoPort > 0)`. This means when the port is -1, `infoPort` is 0, which fails the `> 0` check correctly. However, when the port is valid (e.g., 12345), `infoPort` is 12346 (always > 0), so the link is always returned. The condition should check if the original port is valid (>= 0) before creating the link, not if `infoPort > 0`. The correct check should be `if (serverName.getPort() >= 0)` or `if (infoPort > 0)` should be `if (serverName.getPort() >= 0)`. ########## hbase-server/src/test/java/org/apache/hadoop/hbase/tool/TestCanaryTool.java: ########## @@ -437,4 +449,137 @@ private void testZookeeperCanaryWithArgs(String[] args) throws Exception { HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT); verify(sink, atLeastOnce()).publishReadTiming(eq(baseZnode), eq(hostPort), anyLong()); } + + @Test + public void testWebUI() throws Exception { + CanaryTool.RegionStdOutSink sink = mock(CanaryTool.RegionStdOutSink.class); + + Configuration configuration = HBaseConfiguration.create(testingUtility.getConfiguration()); + int infoPort = 16666; + configuration.setInt(HBASE_CANARY_INFO_PORT, infoPort); + + ExecutorService executorService = startCanaryToolInBackground(sink, configuration); + + // Test that old canary status page URl redirects to JSP Review Comment: Corrected spelling of 'URl' to 'URL'. ```suggestion // Test that old canary status page URL redirects to JSP ``` -- 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]
