sonatype-lift[bot] commented on code in PR #11005: URL: https://github.com/apache/skywalking/pull/11005#discussion_r1246127916
########## oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java: ########## @@ -0,0 +1,154 @@ +/* + * 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.skywalking.oap.server.core.management.ui.menu; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import lombok.extern.slf4j.Slf4j; +import org.apache.skywalking.oap.server.core.query.type.MenuItem; +import org.apache.skywalking.oap.server.core.storage.StorageModule; +import org.apache.skywalking.oap.server.core.storage.management.UIMenuManagementDAO; +import org.apache.skywalking.oap.server.core.storage.query.IMetadataQueryDAO; +import org.apache.skywalking.oap.server.library.module.ModuleManager; +import org.apache.skywalking.oap.server.library.module.Service; +import org.apache.skywalking.oap.server.library.util.CollectionUtils; +import org.apache.skywalking.oap.server.library.util.StringUtil; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +@Slf4j Review Comment: <picture><img alt="4% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/4/display.svg"></picture> <b>*[UnnecessarilyFullyQualified](https://errorprone.info/bugpattern/UnnecessarilyFullyQualified):</b>* This fully qualified name is unambiguous to the compiler if imported. --- ```suggestion LoggerFactory ``` ââ <b>4 similar findings have been found in this PR</b> <details><summary>đ Expand here to view all instances of this finding</summary><br/> <div align=\"center\"> | **File Path** | **Line Number** | | ------------- | ------------- | | oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java | [41](https://github.com/apache/skywalking/blob/22721ce7709ef34b9bcbc15d9cb0054d980e37b9/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java#L41) | | oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java | [41](https://github.com/apache/skywalking/blob/22721ce7709ef34b9bcbc15d9cb0054d980e37b9/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java#L41) | | oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java | [41](https://github.com/apache/skywalking/blob/22721ce7709ef34b9bcbc15d9cb0054d980e37b9/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java#L41) | | oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java | [90](https://github.com/apache/skywalking/blob/22721ce7709ef34b9bcbc15d9cb0054d980e37b9/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java#L90) | <p><a href="https://lift.sonatype.com/results/github.com/apache/skywalking/01H42FYX06QZG7X4C6AQAH2HKV?t=ErrorProne|UnnecessarilyFullyQualified" target="_blank">Visit the Lift Web Console</a> to find more details in your report.</p></div></details> --- <details><summary>âšī¸ Expand to see all <b>@sonatype-lift</b> commands</summary> You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings. | **Command** | **Usage** | | ------------- | ------------- | | `@sonatype-lift ignore` | Leave out the above finding from this PR | | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR | | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file | **Note:** When talking to LiftBot, you need to **refresh** the page to see its response. <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details> ########## oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/management/ui/menu/UIMenuManagementService.java: ########## @@ -0,0 +1,154 @@ +/* + * 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.skywalking.oap.server.core.management.ui.menu; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import lombok.extern.slf4j.Slf4j; +import org.apache.skywalking.oap.server.core.query.type.MenuItem; +import org.apache.skywalking.oap.server.core.storage.StorageModule; +import org.apache.skywalking.oap.server.core.storage.management.UIMenuManagementDAO; +import org.apache.skywalking.oap.server.core.storage.query.IMetadataQueryDAO; +import org.apache.skywalking.oap.server.library.module.ModuleManager; +import org.apache.skywalking.oap.server.library.module.Service; +import org.apache.skywalking.oap.server.library.util.CollectionUtils; +import org.apache.skywalking.oap.server.library.util.StringUtil; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +@Slf4j +public class UIMenuManagementService implements Service, Runnable { + private static final String MENU_ID = "1"; + private static final Gson GSON = new Gson(); + private static final int MENU_GET_MAX_SECOND = 3; + + private UIMenuManagementDAO menuDAO; + private ModuleManager moduleManager; + private CompletableFuture<List<MenuItem>> menuItemFuture; + private boolean isMenuItemsBeenFetched = false; + private IMetadataQueryDAO metadataQueryDAO; + + public UIMenuManagementService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + this.menuItemFuture = new CompletableFuture<>(); + } + + private UIMenuManagementDAO getMenuDAO() { + if (menuDAO == null) { + menuDAO = moduleManager.find(StorageModule.NAME).provider().getService(UIMenuManagementDAO.class); + } + return menuDAO; + } + + private IMetadataQueryDAO getMetadataQueryDAO() { + if (metadataQueryDAO == null) { + metadataQueryDAO = moduleManager.find(StorageModule.NAME).provider().getService(IMetadataQueryDAO.class); + } + return metadataQueryDAO; + } + + public void saveMenuAndStartFetch(List<UIMenuItemSetting> menuItems, int fetchInterval) throws IOException { + // ignore if already existing + if (getMenuDAO().getMenu(MENU_ID) != null) { + startingFetchMenu(fetchInterval); + return; + } + + UIMenu menu = new UIMenu(); + menu.setMenuId(MENU_ID); + menu.setUpdateTime(System.currentTimeMillis()); + menu.setConfigurationJson(GSON.toJson(menuItems)); + + getMenuDAO().saveMenu(menu); + startingFetchMenu(fetchInterval); + } + + private void startingFetchMenu(int fetchIntervalSecond) { + Executors.newSingleThreadScheduledExecutor() + .scheduleWithFixedDelay(this, 0, fetchIntervalSecond, java.util.concurrent.TimeUnit.SECONDS); Review Comment: <picture><img alt="23% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/23/display.svg"></picture> <b>*[FutureReturnValueIgnored](https://errorprone.info/bugpattern/FutureReturnValueIgnored):</b>* Return value of methods returning Future must be checked. Ignoring returned Futures suppresses exceptions thrown from the code that completes the Future. --- <details><summary>âšī¸ Expand to see all <b>@sonatype-lift</b> commands</summary> You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings. | **Command** | **Usage** | | ------------- | ------------- | | `@sonatype-lift ignore` | Leave out the above finding from this PR | | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR | | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file | **Note:** When talking to LiftBot, you need to **refresh** the page to see its response. <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details> -- 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]
