caishunfeng commented on code in PR #13332: URL: https://github.com/apache/dolphinscheduler/pull/13332#discussion_r1101362916
########## dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/RemoteLogUtils.java: ########## @@ -0,0 +1,72 @@ +/* + * 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.dolphinscheduler.common.log.remote; + +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.common.utils.PropertyUtils; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class RemoteLogUtils { + + private static final Logger logger = LoggerFactory.getLogger(RemoteLogUtils.class); Review Comment: can we use `@Slf4j` like #13509 ########## dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/RemoteLogService.java: ########## @@ -0,0 +1,50 @@ +/* + * 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.dolphinscheduler.common.log.remote; + +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.common.utils.PropertyUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +@Component +public class RemoteLogService { + + private static final Logger logger = LoggerFactory.getLogger(RemoteLogService.class); + + @Async("remoteLogHandleExecutor") + public void asyncSendRemoteLog(String logPath) { + if (RemoteLogUtils.isRemoteLoggingEnable()) { + logger.info("Start to send log {} to remote target {}", logPath, + PropertyUtils.getString(Constants.REMOTE_LOGGING_TARGET)); + + RemoteLogHandler remoteLogHandler = RemoteLogHandlerFactory.getRemoteLogHandler(); + if (remoteLogHandler != null) { + remoteLogHandler.sendRemoteLog(logPath); + } else { + logger.error("remote log handler is null"); + } + + logger.info("Succeed to send log {} to remote target {}", logPath, + PropertyUtils.getString(Constants.REMOTE_LOGGING_TARGET)); Review Comment: ```suggestion if (remoteLogHandler == null) { logger.error("remote log handler is null"); return; } remoteLogHandler.sendRemoteLog(logPath); logger.info("Succeed to send log {} to remote target {}", logPath, PropertyUtils.getString(Constants.REMOTE_LOGGING_TARGET)); ``` ########## dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java: ########## @@ -100,6 +101,10 @@ public AbstractCommandExecutor(Consumer<LinkedBlockingQueue<String>> logHandler, this.taskRequest = taskRequest; this.logger = logger; this.logBuffer = new LinkedBlockingQueue<>(); + + if (this.taskRequest != null) { + this.taskRequest.setLogHandleEnable(true); Review Comment: Why set default true? Please add some comments. ########## dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/RemoteLogUtils.java: ########## @@ -0,0 +1,72 @@ +/* + * 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.dolphinscheduler.common.log.remote; + +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.common.utils.PropertyUtils; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class RemoteLogUtils { + + private static final Logger logger = LoggerFactory.getLogger(RemoteLogUtils.class); + + private static RemoteLogService remoteLogService; + + @Autowired + private RemoteLogService autowiredRemoteLogService; + + @PostConstruct + private void init() { + remoteLogService = autowiredRemoteLogService; + } + + public static void sendRemoteLog(String logPath) { + if (isRemoteLoggingEnable()) { + // send task logs to remote storage asynchronously + remoteLogService.asyncSendRemoteLog(logPath); + } + } + + public static void getRemoteLog(String logPath) { + if (isRemoteLoggingEnable()) { + logger.info("Start to get log {} from remote target {}", logPath, + PropertyUtils.getString(Constants.REMOTE_LOGGING_TARGET)); + + RemoteLogHandler remoteLogHandler = RemoteLogHandlerFactory.getRemoteLogHandler(); + if (remoteLogHandler != null) { + remoteLogHandler.getRemoteLog(logPath); + } else { + logger.error("remote log handler is null"); + } + + logger.info("Succeed to get log {} from remote target {}", logPath, + PropertyUtils.getString(Constants.REMOTE_LOGGING_TARGET)); Review Comment: ```suggestion if (remoteLogHandler == null) { logger.error("remote log handler is null"); return; } remoteLogHandler.getRemoteLog(logPath); logger.info("Succeed to get log {} from remote target {}", logPath, PropertyUtils.getString(Constants.REMOTE_LOGGING_TARGET)); ``` ########## dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote/RemoteLogHandlerFactory.java: ########## @@ -0,0 +1,41 @@ +/* + * 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.dolphinscheduler.common.log.remote; + +import org.apache.dolphinscheduler.common.constants.Constants; +import org.apache.dolphinscheduler.common.utils.PropertyUtils; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class RemoteLogHandlerFactory { + + public RemoteLogHandler getRemoteLogHandler() { + if (RemoteLogUtils.isRemoteLoggingEnable()) { + if ("OSS".equals(PropertyUtils.getUpperCaseString(Constants.REMOTE_LOGGING_TARGET))) { + OssRemoteLogHandler ossRemoteLogHandler = new OssRemoteLogHandler(); + ossRemoteLogHandler.init(); + return ossRemoteLogHandler; + } else { + return null; + } + } else { + return null; + } Review Comment: ```suggestion if (!RemoteLogUtils.isRemoteLoggingEnable()) { return null; } if (!"OSS".equals(PropertyUtils.getUpperCaseString(Constants.REMOTE_LOGGING_TARGET))) { return null; } OssRemoteLogHandler ossRemoteLogHandler = new OssRemoteLogHandler(); ossRemoteLogHandler.init(); return ossRemoteLogHandler; ``` ########## dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/processor/LoggerRequestProcessor.java: ########## @@ -172,6 +173,24 @@ private byte[] getFileContentBytes(String filePath) { return new byte[0]; } + private byte[] getFileContentBytesFromRemote(String filePath) { + RemoteLogUtils.getRemoteLog(filePath); + return getFileContentBytesFromLocal(filePath); + } + + private byte[] getFileContentBytes(String filePath) { + File file = new File(filePath); + if (file.exists()) { + return getFileContentBytesFromLocal(filePath); + } else { + if (RemoteLogUtils.isRemoteLoggingEnable()) { + return getFileContentBytesFromRemote(filePath); + } else { + return getFileContentBytesFromLocal(filePath); + } + } Review Comment: ```suggestion if (file.exists()) { return getFileContentBytesFromLocal(filePath); } if (RemoteLogUtils.isRemoteLoggingEnable()) { return getFileContentBytesFromRemote(filePath); } return getFileContentBytesFromLocal(filePath); ``` -- 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]
