moremind commented on code in PR #4812: URL: https://github.com/apache/shenyu/pull/4812#discussion_r1254394684
########## shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/main/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClient.java: ########## @@ -0,0 +1,206 @@ +/* + * 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.shenyu.plugin.huawei.lts.client; + +import com.alibaba.fastjson.JSONObject; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.huaweicloud.lts.appender.JavaSDKAppender; +import com.huaweicloud.lts.producer.Producer; +import com.huaweicloud.lts.producer.Result; +import com.huaweicloud.lts.producer.exception.ProducerException; +import com.huaweicloud.lts.producer.exception.ResultFailedException; +import com.huaweicloud.lts.producer.model.log.LogContent; +import com.huaweicloud.lts.producer.model.log.LogItem; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.common.concurrent.ShenyuThreadFactory; +import org.apache.shenyu.plugin.huawei.lts.config.HuaweiLogCollectConfig; +import org.apache.shenyu.plugin.logging.common.client.AbstractLogConsumeClient; +import org.apache.shenyu.plugin.logging.common.constant.GenericLoggingConstant; +import org.apache.shenyu.plugin.logging.common.entity.ShenyuRequestLog; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.lang.NonNull; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class HuaweiLtsLogCollectClient extends AbstractLogConsumeClient<HuaweiLogCollectConfig.HuaweiLtsLogConfig, ShenyuRequestLog> { + + private Producer producer; + + private String logGroupId; + + private String logStreamId; + + private String projectId; + + private ThreadPoolExecutor threadExecutor; + + @Override + public void initClient0(@NonNull final HuaweiLogCollectConfig.HuaweiLtsLogConfig huaweiLtsLogConfig) { + final String accessKeyId = huaweiLtsLogConfig.getAccessKeyId(); + final String accessKeySecret = huaweiLtsLogConfig.getAccessKeySecret(); + final String regionName = huaweiLtsLogConfig.getRegionName(); + this.projectId = huaweiLtsLogConfig.getProjectId(); + this.logGroupId = huaweiLtsLogConfig.getLogGroupId(); + this.logStreamId = huaweiLtsLogConfig.getLogStreamId(); + if (StringUtils.isBlank(accessKeyId) || StringUtils.isBlank(accessKeySecret) || StringUtils.isBlank(projectId) + || StringUtils.isBlank(regionName) || StringUtils.isBlank(logGroupId) || StringUtils.isBlank(logStreamId)) { + LOG.error("init Huawei lts client error, please check projectId, accessKeyId, accessKeySecret, regionName, logGroupId or logStreamId"); + return; + } + JavaSDKAppender appender = JavaSDKAppender.custom() + // 华为云帐号的项目ID(project id) + .setProjectId(projectId) + // 华为云帐号的AK + .setAccessKeyId(accessKeyId) + // 华为云帐号的SK + .setAccessKeySecret(accessKeySecret) + // 云日志服务的区域 + .setRegionName(regionName) + // 单个Appender能缓存的日志大小上限 + .setTotalSizeInBytes(huaweiLtsLogConfig.getTotalSizeInBytes()) + // producer发送日志时阻塞时间 + .setMaxBlockMs(huaweiLtsLogConfig.getMaxBlockMs()) + // producer发送单批日志量上限 + .setBatchSizeThresholdInBytes(huaweiLtsLogConfig.getBatchSizeThresholdInBytes()) + // producer发送单批日志条数上限 Review Comment: not comment with . -- 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]
