You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "doleyzi (via GitHub)" <gi...@apache.org> on 2024/04/11 08:12:25 UTC
[PR] [INLONG-9977][Audit] Audit-service increases the capabilities of openapi [inlong]
doleyzi opened a new pull request, #9978:
URL: https://github.com/apache/inlong/pull/9978
### Prepare a Pull Request
- Fixes #9977
### Motivation

*In order to improve the concurrency and decoupling of audit external services, audit-service needs to provide a complete set of external openapi.*
### Modifications
*By adding an http interface to provide external audit data, there is less coupling with other modules..*
--
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: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-9977][Audit] Audit-service increases the capabilities of openapi [inlong]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9978:
URL: https://github.com/apache/inlong/pull/9978#discussion_r1560649047
##########
inlong-audit/audit-service/src/main/java/org/apache/inlong/audit/cache/AbstractCache.java:
##########
@@ -82,7 +83,11 @@ public Cache<String, StatData> getCache() {
* @return
*/
public List<StatData> getData(String key) {
- return Arrays.asList(cache.getIfPresent(key));
+ StatData statData = cache.getIfPresent(key);
+ if (null == statData) {
+ return new LinkedList<>();
+ }
+ return Arrays.asList(statData);
Review Comment:
```suggestion
return Collections.singletonList(statData);
```
--
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: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-9977][Audit] Audit-service increases the capabilities of openapi [inlong]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9978:
URL: https://github.com/apache/inlong/pull/9978#discussion_r1560940261
##########
inlong-audit/bin/service-stop.sh:
##########
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+#
+# 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.
+#
+
+# this program kills the audit store
+ps -ef |grep "audit-service" | grep -v grep|awk '{print $2}' | xargs kill -9
Review Comment:
shutdown service gracefully is preferred than forcefully(kill -9)
--
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: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-9977][Audit] Audit-service increases the capabilities of openapi [inlong]
Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang commented on code in PR #9978:
URL: https://github.com/apache/inlong/pull/9978#discussion_r1560638344
##########
inlong-audit/pom.xml:
##########
@@ -37,6 +37,7 @@
<module>audit-sdk</module>
<module>audit-release</module>
<module>audit-docker</module>
+ <module>audit-service</module>
Review Comment:
add `audit-docker` to the end.
##########
inlong-audit/audit-service/src/main/java/org/apache/inlong/audit/entities/JdbcConfig.java:
##########
@@ -0,0 +1,31 @@
+/*
+ * 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.inlong.audit.entities;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class JdbcConfig {
+
+ String driverClass;
+ String JdbcUrl;
+ String userName;
+ String passWord;
Review Comment:
```suggestion
String password;
```
--
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: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-9977][Audit] Audit-service increases the capabilities of openapi [inlong]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #9978:
URL: https://github.com/apache/inlong/pull/9978#discussion_r1560940261
##########
inlong-audit/bin/service-stop.sh:
##########
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+#
+# 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.
+#
+
+# this program kills the audit store
+ps -ef |grep "audit-service" | grep -v grep|awk '{print $2}' | xargs kill -9
Review Comment:
shutdown service gracefully is preferred than forcefully(kill =9)
--
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: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-9977][Audit] Audit-service increases the capabilities of openapi [inlong]
Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang merged PR #9978:
URL: https://github.com/apache/inlong/pull/9978
--
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: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-9977][Audit] Audit-service increases the capabilities of openapi [inlong]
Posted by "justinwwhuang (via GitHub)" <gi...@apache.org>.
justinwwhuang commented on code in PR #9978:
URL: https://github.com/apache/inlong/pull/9978#discussion_r1560650705
##########
inlong-audit/audit-service/src/main/java/org/apache/inlong/audit/service/ApiService.java:
##########
@@ -0,0 +1,217 @@
+/*
+ * 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.inlong.audit.service;
+
+import org.apache.inlong.audit.cache.DayCache;
+import org.apache.inlong.audit.cache.HalfHourCache;
+import org.apache.inlong.audit.cache.HourCache;
+import org.apache.inlong.audit.cache.TenMinutesCache;
+import org.apache.inlong.audit.config.Configuration;
+import org.apache.inlong.audit.entities.AuditCycle;
+import org.apache.inlong.audit.entities.StatData;
+import org.apache.inlong.audit.utils.CacheUtils;
+
+import com.google.common.util.concurrent.RateLimiter;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+import com.sun.net.httpserver.HttpServer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executors;
+
+import static org.apache.inlong.audit.config.OpenApiConstants.AUDIT_ID;
+import static org.apache.inlong.audit.config.OpenApiConstants.AUDIT_TAG;
+import static org.apache.inlong.audit.config.OpenApiConstants.BIND_PORT;
+import static org.apache.inlong.audit.config.OpenApiConstants.DEFAULT_API_BACKLOG_SIZE;
+import static org.apache.inlong.audit.config.OpenApiConstants.DEFAULT_API_REAL_LIMITER_QPS;
+import static org.apache.inlong.audit.config.OpenApiConstants.DEFAULT_AUDIT_TAG;
+import static org.apache.inlong.audit.config.OpenApiConstants.DEFAULT_DAY_API_PATH;
+import static org.apache.inlong.audit.config.OpenApiConstants.DEFAULT_HOUR_API_PATH;
+import static org.apache.inlong.audit.config.OpenApiConstants.DEFAULT_MINUTE_10_API_PATH;
+import static org.apache.inlong.audit.config.OpenApiConstants.DEFAULT_MINUTE_30_API_PATH;
+import static org.apache.inlong.audit.config.OpenApiConstants.DEFAULT_POOL_SIZE;
+import static org.apache.inlong.audit.config.OpenApiConstants.END_TIME;
+import static org.apache.inlong.audit.config.OpenApiConstants.HTTP_RESPOND_CODE;
+import static org.apache.inlong.audit.config.OpenApiConstants.INLONG_GROUP_Id;
+import static org.apache.inlong.audit.config.OpenApiConstants.INLONG_STREAM_Id;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_API_BACKLOG_SIZE;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_API_POOL_SIZE;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_API_REAL_LIMITER_QPS;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_DAY_API_PATH;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_HOUR_API_PATH;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_HTTP_BODY_ERR_DATA;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_HTTP_BODY_ERR_MSG;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_HTTP_BODY_SUCCESS;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_HTTP_HEADER_CONTENT_TYPE;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_MINUTE_10_API_PATH;
+import static org.apache.inlong.audit.config.OpenApiConstants.KEY_MINUTE_30_API_PATH;
+import static org.apache.inlong.audit.config.OpenApiConstants.START_TIME;
+import static org.apache.inlong.audit.config.OpenApiConstants.VALUE_HTTP_HEADER_CONTENT_TYPE;
+
+public class ApiService {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApiService.class);
+
+ public void start() {
+ initHttpServer();
+ }
+
+ public void stop() {
+
+ }
+
+ private void initHttpServer() {
+ try {
+ HttpServer server = HttpServer.create(new InetSocketAddress(BIND_PORT),
+ Configuration.getInstance().get(KEY_API_BACKLOG_SIZE, DEFAULT_API_BACKLOG_SIZE));
+ server.setExecutor(Executors.newFixedThreadPool(
+ Configuration.getInstance().get(KEY_API_POOL_SIZE, DEFAULT_POOL_SIZE)));
+ server.createContext(Configuration.getInstance().get(KEY_DAY_API_PATH, DEFAULT_DAY_API_PATH),
+ new AuditHandler(AuditCycle.DAY));
+ server.createContext(Configuration.getInstance().get(KEY_HOUR_API_PATH, DEFAULT_HOUR_API_PATH),
+ new AuditHandler(AuditCycle.HOUR));
+ server.createContext(Configuration.getInstance().get(KEY_MINUTE_10_API_PATH, DEFAULT_MINUTE_10_API_PATH),
+ new AuditHandler(AuditCycle.MINUTE_10));
+ server.createContext(Configuration.getInstance().get(KEY_MINUTE_30_API_PATH, DEFAULT_MINUTE_30_API_PATH),
+ new AuditHandler(AuditCycle.MINUTE_30));
+ server.start();
+ } catch (Exception e) {
+ LOGGER.error("Init http server has exception!", e);
+ }
+ }
+
+ static class AuditHandler implements HttpHandler, AutoCloseable {
+
+ private final AuditCycle apiType;
+ private final RateLimiter limiter;
+
+ public AuditHandler(AuditCycle apiType) {
+ this.apiType = apiType;
+ limiter = RateLimiter.create(Configuration.getInstance().get(KEY_API_REAL_LIMITER_QPS,
+ DEFAULT_API_REAL_LIMITER_QPS));
+ }
+
+ @Override
+ public void handle(HttpExchange exchange) {
+ if (null != limiter) {
+ limiter.acquire();
+ }
+
+ try (OutputStream os = exchange.getResponseBody()) {
+ JsonObject responseJson = new JsonObject();
+
+ Map<String, String> params = parseRequestURI(exchange.getRequestURI().getQuery());
+ if (!checkParams(params)) {
+ handleInvalidParams(responseJson, exchange);
+ } else {
+ handleLegalParams(responseJson, params);
+ }
+
+ byte[] bytes = responseJson.toString().getBytes();
Review Comment:
Do we need to specify the encoding format here?
--
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: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org