javeme commented on code in PR #2278: URL: https://github.com/apache/incubator-hugegraph/pull/2278#discussion_r1320104413
########## hugegraph-test/src/main/java/org/apache/hugegraph/api/ArthasApiTest.java: ########## @@ -0,0 +1,56 @@ +/* + * 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.hugegraph.api; + +import org.junit.Before; +import org.junit.Test; + +import jakarta.ws.rs.core.Response; + +public class ArthasApiTest extends BaseApiTest { + + private static final String ARTHAS_START_PATH = "/arthas"; + private static final String ARTHAS_API_BASE_URL = "http://127.0.0.1:8561"; + private static final String ARTHAS_API_PATH = "/api"; + + @Before + public void testArthasStart() { + Response r = client().get(ARTHAS_START_PATH); + assertResponseStatus(200, r); + } + + @Test + public void testArthasApi() { + Review Comment: expect to remove the blank line ########## hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java: ########## @@ -264,4 +264,35 @@ public static synchronized ServerOptions instance() { disallowEmpty(), true ); + + + public static final ConfigOption<String> ARTHAS_TELNET_PORT = + new ConfigOption<>( + "arthas.telnetPort", Review Comment: expect "telnet_port" style ########## hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java: ########## @@ -264,4 +264,35 @@ public static synchronized ServerOptions instance() { disallowEmpty(), true ); + + Review Comment: one blank line is ok ########## hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.hugegraph.api.arthas; + +import java.util.HashMap; + +import org.apache.hugegraph.api.API; +import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.config.ServerOptions; +import org.apache.hugegraph.util.JsonUtil; + +import com.codahale.metrics.annotation.Timed; +import com.taobao.arthas.agent.attach.ArthasAgent; + +import jakarta.inject.Singleton; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; + +@Path("arthas") +@Singleton +public class ArthasAPI extends API { + + @Context + private jakarta.inject.Provider<HugeConfig> configProvider; + + @GET Review Comment: use PUT for state updating ########## hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.hugegraph.api.arthas; + +import java.util.HashMap; + +import org.apache.hugegraph.api.API; +import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.config.ServerOptions; +import org.apache.hugegraph.util.JsonUtil; + +import com.codahale.metrics.annotation.Timed; +import com.taobao.arthas.agent.attach.ArthasAgent; + +import jakarta.inject.Singleton; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; + +@Path("arthas") +@Singleton +public class ArthasAPI extends API { + + @Context + private jakarta.inject.Provider<HugeConfig> configProvider; + + @GET + @Timed + @Produces(APPLICATION_JSON_WITH_CHARSET) + public Object arthasStart() { + HugeConfig config = this.configProvider.get(); + HashMap<String, String> configMap = new HashMap<>(4); + configMap.put("arthas.telnetPort", config.get(ServerOptions.ARTHAS_TELNET_PORT)); + configMap.put("arthas.httpPort", config.get(ServerOptions.ARTHAS_HTTP_PORT)); + configMap.put("arthas.ip", config.get(ServerOptions.ARTHAS_IP)); + configMap.put("arthas.disabledCommands", + config.get(ServerOptions.ARTHAS_DISABLED_COMMANDS)); + ArthasAgent.attach(configMap); + + DashResponse retPose = new DashResponse(); + retPose.setData(JsonUtil.toJson(configMap)); + retPose.setStatus(200); Review Comment: we can use http status, so don't need a extra status code here. it's ok to just return the configMap ########## hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java: ########## @@ -264,4 +264,35 @@ public static synchronized ServerOptions instance() { disallowEmpty(), true ); + + + public static final ConfigOption<String> ARTHAS_TELNET_PORT = + new ConfigOption<>( + "arthas.telnetPort", + "arthas provides telnet ports to the outside", + disallowEmpty(), + "8562" + ); + public static final ConfigOption<String> ARTHAS_HTTP_PORT = + new ConfigOption<>( + "arthas.httpPort", + "arthas provides http ports to the outside", + disallowEmpty(), + "8561" + ); + public static final ConfigOption<String> ARTHAS_IP = + new ConfigOption<>( + "arthas.ip", + "arthas bound ip", + disallowEmpty(), + "0.0.0.0" + ); + public static final ConfigOption<String> ARTHAS_DISABLED_COMMANDS = + new ConfigOption<>( + "arthas.disabledCommands", + "arthas disabled commands", + disallowEmpty(), + "jad" + ); + Review Comment: expect to be removed ########## hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.hugegraph.api.arthas; + +import java.util.HashMap; + +import org.apache.hugegraph.api.API; +import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.config.ServerOptions; +import org.apache.hugegraph.util.JsonUtil; + +import com.codahale.metrics.annotation.Timed; +import com.taobao.arthas.agent.attach.ArthasAgent; + +import jakarta.inject.Singleton; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; + +@Path("arthas") +@Singleton +public class ArthasAPI extends API { + + @Context + private jakarta.inject.Provider<HugeConfig> configProvider; + + @GET + @Timed + @Produces(APPLICATION_JSON_WITH_CHARSET) + public Object arthasStart() { Review Comment: prefer startArthas ########## hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java: ########## @@ -264,4 +264,35 @@ public static synchronized ServerOptions instance() { disallowEmpty(), true ); + + + public static final ConfigOption<String> ARTHAS_TELNET_PORT = + new ConfigOption<>( + "arthas.telnetPort", + "arthas provides telnet ports to the outside", + disallowEmpty(), + "8562" + ); Review Comment: a blank line is expected here ########## hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.hugegraph.api.arthas; + +import java.util.HashMap; + +import org.apache.hugegraph.api.API; +import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.config.ServerOptions; +import org.apache.hugegraph.util.JsonUtil; + +import com.codahale.metrics.annotation.Timed; +import com.taobao.arthas.agent.attach.ArthasAgent; + +import jakarta.inject.Singleton; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; + +@Path("arthas") +@Singleton +public class ArthasAPI extends API { + + @Context + private jakarta.inject.Provider<HugeConfig> configProvider; + + @GET + @Timed + @Produces(APPLICATION_JSON_WITH_CHARSET) + public Object arthasStart() { + HugeConfig config = this.configProvider.get(); + HashMap<String, String> configMap = new HashMap<>(4); + configMap.put("arthas.telnetPort", config.get(ServerOptions.ARTHAS_TELNET_PORT)); + configMap.put("arthas.httpPort", config.get(ServerOptions.ARTHAS_HTTP_PORT)); + configMap.put("arthas.ip", config.get(ServerOptions.ARTHAS_IP)); + configMap.put("arthas.disabledCommands", + config.get(ServerOptions.ARTHAS_DISABLED_COMMANDS)); + ArthasAgent.attach(configMap); + + DashResponse retPose = new DashResponse(); Review Comment: retPose means response? ########## hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java: ########## @@ -264,4 +264,35 @@ public static synchronized ServerOptions instance() { disallowEmpty(), true ); + + + public static final ConfigOption<String> ARTHAS_TELNET_PORT = + new ConfigOption<>( + "arthas.telnetPort", + "arthas provides telnet ports to the outside", + disallowEmpty(), + "8562" + ); + public static final ConfigOption<String> ARTHAS_HTTP_PORT = + new ConfigOption<>( + "arthas.httpPort", + "arthas provides http ports to the outside", + disallowEmpty(), + "8561" + ); + public static final ConfigOption<String> ARTHAS_IP = + new ConfigOption<>( + "arthas.ip", + "arthas bound ip", + disallowEmpty(), + "0.0.0.0" + ); + public static final ConfigOption<String> ARTHAS_DISABLED_COMMANDS = + new ConfigOption<>( + "arthas.disabledCommands", + "arthas disabled commands", Review Comment: could you please add more details ########## hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java: ########## @@ -264,4 +264,35 @@ public static synchronized ServerOptions instance() { disallowEmpty(), true ); + + + public static final ConfigOption<String> ARTHAS_TELNET_PORT = + new ConfigOption<>( + "arthas.telnetPort", + "arthas provides telnet ports to the outside", + disallowEmpty(), + "8562" + ); + public static final ConfigOption<String> ARTHAS_HTTP_PORT = + new ConfigOption<>( + "arthas.httpPort", + "arthas provides http ports to the outside", + disallowEmpty(), + "8561" + ); + public static final ConfigOption<String> ARTHAS_IP = + new ConfigOption<>( + "arthas.ip", + "arthas bound ip", + disallowEmpty(), + "0.0.0.0" + ); + public static final ConfigOption<String> ARTHAS_DISABLED_COMMANDS = + new ConfigOption<>( + "arthas.disabledCommands", Review Comment: ditto ########## hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.hugegraph.api.arthas; + +import java.util.HashMap; + +import org.apache.hugegraph.api.API; +import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.config.ServerOptions; +import org.apache.hugegraph.util.JsonUtil; + +import com.codahale.metrics.annotation.Timed; +import com.taobao.arthas.agent.attach.ArthasAgent; + +import jakarta.inject.Singleton; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; + +@Path("arthas") +@Singleton +public class ArthasAPI extends API { + + @Context + private jakarta.inject.Provider<HugeConfig> configProvider; + + @GET + @Timed + @Produces(APPLICATION_JSON_WITH_CHARSET) + public Object arthasStart() { + HugeConfig config = this.configProvider.get(); + HashMap<String, String> configMap = new HashMap<>(4); + configMap.put("arthas.telnetPort", config.get(ServerOptions.ARTHAS_TELNET_PORT)); + configMap.put("arthas.httpPort", config.get(ServerOptions.ARTHAS_HTTP_PORT)); + configMap.put("arthas.ip", config.get(ServerOptions.ARTHAS_IP)); + configMap.put("arthas.disabledCommands", + config.get(ServerOptions.ARTHAS_DISABLED_COMMANDS)); + ArthasAgent.attach(configMap); Review Comment: do we need to handle exceptions here ########## hugegraph-api/src/main/java/org/apache/hugegraph/api/arthas/ArthasAPI.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.hugegraph.api.arthas; + +import java.util.HashMap; + +import org.apache.hugegraph.api.API; +import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.config.ServerOptions; +import org.apache.hugegraph.util.JsonUtil; + +import com.codahale.metrics.annotation.Timed; +import com.taobao.arthas.agent.attach.ArthasAgent; + +import jakarta.inject.Singleton; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Context; + +@Path("arthas") +@Singleton +public class ArthasAPI extends API { + + @Context + private jakarta.inject.Provider<HugeConfig> configProvider; + + @GET + @Timed + @Produces(APPLICATION_JSON_WITH_CHARSET) + public Object arthasStart() { + HugeConfig config = this.configProvider.get(); + HashMap<String, String> configMap = new HashMap<>(4); + configMap.put("arthas.telnetPort", config.get(ServerOptions.ARTHAS_TELNET_PORT)); + configMap.put("arthas.httpPort", config.get(ServerOptions.ARTHAS_HTTP_PORT)); + configMap.put("arthas.ip", config.get(ServerOptions.ARTHAS_IP)); + configMap.put("arthas.disabledCommands", + config.get(ServerOptions.ARTHAS_DISABLED_COMMANDS)); + ArthasAgent.attach(configMap); Review Comment: what happens if we call it multiple times -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
