This is an automated email from the ASF dual-hosted git repository.
wangtao29 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozhera.git
The following commit(s) were added to refs/heads/master by this push:
new 7742a6e3 feat: new interfaces that the agent can call (#641)
7742a6e3 is described below
commit 7742a6e38e82bde674b7f6f0a1c24b3aa70b8f21
Author: Xue <[email protected]>
AuthorDate: Thu Mar 12 15:37:24 2026 +0800
feat: new interfaces that the agent can call (#641)
* feat: Some interfaces about space
* feat: Some interfaces about store and tail
* fix: fix some params
* fix: fix version
* fix: fix version
* fix: Modify the calling plan
* fix: fix version
* fix: Modify the version of the dependency
* fix: Modify the version of the dependency
* fix: correct the incorrect comments.
* fix: correct the incorrect comments.
* fix: add the Apache open-source file header
---
ozhera-log/log-api/pom.xml | 6 +-
.../ozhera/log/api/model/agent/AgentApiResult.java | 92 +++++
.../ozhera/log/api/model/agent/SpaceInfo.java | 39 ++
.../ozhera/log/api/model/agent/StoreInfo.java | 82 ++++
.../ozhera/log/api/model/agent/TailInfo.java | 114 ++++++
.../ozhera/log/api/model/agent/UserInfo.java | 37 ++
.../ozhera/log/api/service/LogAgentApiService.java | 59 +++
ozhera-log/log-manager/pom.xml | 4 +-
.../manager/controller/MilogConfigController.java | 2 +
.../ozhera/log/manager/service/BaseService.java | 2 +-
.../service/impl/LogAgentApiServiceImpl.java | 454 +++++++++++++++++++++
.../manager/service/impl/LogSpaceServiceImpl.java | 4 +-
.../service/impl/MilogAiAnalysisServiceImpl.java | 32 +-
13 files changed, 913 insertions(+), 14 deletions(-)
diff --git a/ozhera-log/log-api/pom.xml b/ozhera-log/log-api/pom.xml
index bd3b1de2..c212ff9e 100644
--- a/ozhera-log/log-api/pom.xml
+++ b/ozhera-log/log-api/pom.xml
@@ -29,7 +29,7 @@ http://www.apache.org/licenses/LICENSE-2.0
<modelVersion>4.0.0</modelVersion>
<artifactId>log-api</artifactId>
- <version>2.2.7-SNAPSHOT</version>
+ <version>2.2.8-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -44,6 +44,10 @@ http://www.apache.org/licenses/LICENSE-2.0
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
</dependencies>
<build>
diff --git
a/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/AgentApiResult.java
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/AgentApiResult.java
new file mode 100644
index 00000000..e677108f
--- /dev/null
+++
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/AgentApiResult.java
@@ -0,0 +1,92 @@
+/*
+ * 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.ozhera.log.api.model.agent;
+
+import com.google.gson.Gson;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class AgentApiResult {
+
+ private static final Gson GSON = new Gson();
+ private static final String SUCCESS_MESSAGE = "success";
+
+ private boolean success;
+ private String message;
+ private Map<String, Object> data;
+
+ private AgentApiResult(boolean success, String message, Map<String,
Object> data) {
+ this.success = success;
+ this.message = message;
+ this.data = data;
+ }
+
+ public static String success() {
+ return GSON.toJson(new AgentApiResult(true, SUCCESS_MESSAGE, null));
+ }
+
+ public static String fail(String message) {
+ return GSON.toJson(new AgentApiResult(false, message, null));
+ }
+
+ public static Builder successBuilder() {
+ return new Builder(true, SUCCESS_MESSAGE);
+ }
+
+ public static Builder failBuilder(String message) {
+ return new Builder(false, message);
+ }
+
+ public boolean isSuccess() {
+ return success;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public Map<String, Object> getData() {
+ return data;
+ }
+
+ public static class Builder {
+ private boolean success;
+ private String message;
+ private Map<String, Object> data;
+
+ private Builder(boolean success, String message) {
+ this.success = success;
+ this.message = message;
+ }
+
+ public Builder addData(String key, Object value) {
+ if (this.data == null) {
+ this.data = new LinkedHashMap<>();
+ }
+ this.data.put(key, value);
+ return this;
+ }
+
+ public String build() {
+ return GSON.toJson(new AgentApiResult(success, message, data));
+ }
+ }
+}
diff --git
a/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/SpaceInfo.java
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/SpaceInfo.java
new file mode 100644
index 00000000..07696af4
--- /dev/null
+++
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/SpaceInfo.java
@@ -0,0 +1,39 @@
+/*
+ * 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.ozhera.log.api.model.agent;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class SpaceInfo implements Serializable {
+ private Long spaceId;
+
+ private String spaceName;
+
+ private String spaceDescription;
+
+ private UserInfo userInfo;
+}
diff --git
a/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/StoreInfo.java
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/StoreInfo.java
new file mode 100644
index 00000000..2a638c07
--- /dev/null
+++
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/StoreInfo.java
@@ -0,0 +1,82 @@
+/*
+ * 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.ozhera.log.api.model.agent;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class StoreInfo implements Serializable {
+
+ private Long storeId;
+
+ private Long spaceId;
+
+ private String storeName;
+
+ private Integer machineRoom;
+
+ private String logType;
+
+ private Integer mqResourceId;
+
+ private String columnTypeList =
"date,keyword,keyword,text,text,keyword,keyword,text,keyword,keyword,keyword,keyword,keyword,keyword,keyword,long";
+
+ private String keyList =
"timestamp:1,level:1,traceId:1,threadName:1,className:1,line:1,methodName:1,message:1,podName:1,logstore:3,logsource:3,mqtopic:3,mqtag:3,logip:3,tail:3,linenumber:3";
+
+ private String keysName = "";
+
+ private boolean selectCustomIndex;
+
+ private Integer shardCnt = 1;
+
+ private Integer storePeriod = 180;
+
+ private Integer esResourceId;
+
+ private UserInfo userInfo;
+
+ public String isValidParam(boolean isCreate) {
+ if (spaceId == null || spaceId < 0) {
+ return "The space id cannot be empty!";
+ }
+ if (storeName == null || storeName.isEmpty()) {
+ return "The store name cannot be empty!";
+ }
+ if (userInfo == null || userInfo.getUser() == null ||
userInfo.getUser().isEmpty()) {
+ return "The user information is empty. Please provide the correct
user information!";
+ }
+ if (!isCreate) {
+ if (storeId == null || storeId < 0) {
+ return "The store id cannot be empty!";
+ }
+ if (userInfo.getUserType() == null) {
+ return "The user type cannot be empty!";
+ }
+ }
+ return null;
+ }
+
+}
diff --git
a/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/TailInfo.java
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/TailInfo.java
new file mode 100644
index 00000000..5ecfe3ba
--- /dev/null
+++
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/TailInfo.java
@@ -0,0 +1,114 @@
+/*
+ * 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.ozhera.log.api.model.agent;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class TailInfo implements Serializable {
+
+ private Long id;
+
+ private Long spaceId;
+
+ private Long storeId;
+
+ private Long milogAppId;
+
+ private Long appId;
+
+ private String appName;
+
+ private Long envId;
+
+ private String envName;
+
+ private List<String> ips;
+
+ private String tail;
+
+ private Integer parseType;
+
+ private String parseScript;
+
+ private String logPath;
+
+ private String valueList;
+
+ private String tailRate;
+
+ private Long ctime;
+
+ private Long utime;
+
+ private String logSplitExpress;
+
+ private String firstLineReg;
+
+ private Integer appType;
+
+ private Integer machineType;
+
+ private List<?> motorRooms;
+
+ private List<?> middlewareConfig;
+
+ private Integer deployWay;
+
+ private Integer batchSendSize = 20;
+
+ private Boolean collectionReady = true;
+
+ private String source;
+
+ private UserInfo userInfo;
+
+ public String isValidParam(boolean isCreate) {
+ if (spaceId == null || spaceId < 0) {
+ return "The space id cannot be empty!";
+ }
+ if (storeId == null || storeId < 0) {
+ return "The store id cannot be empty!";
+ }
+ if (tail == null || tail.isEmpty()) {
+ return "The tail name cannot be empty!";
+ }
+ if (logPath == null || logPath.isEmpty()) {
+ return "The log path cannot be empty!";
+ }
+ if (userInfo == null || userInfo.getUser() == null ||
userInfo.getUser().isEmpty()) {
+ return "The user information is empty. Please provide the correct
user information!";
+ }
+ if (!isCreate) {
+ if (id == null || id < 0) {
+ return "The tail id cannot be empty!";
+ }
+ }
+ return null;
+ }
+
+}
diff --git
a/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/UserInfo.java
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/UserInfo.java
new file mode 100644
index 00000000..f611af72
--- /dev/null
+++
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/model/agent/UserInfo.java
@@ -0,0 +1,37 @@
+/*
+ * 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.ozhera.log.api.model.agent;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class UserInfo implements Serializable {
+ private String user;
+
+ private Integer userType;
+
+ private String zone;
+}
diff --git
a/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/service/LogAgentApiService.java
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/service/LogAgentApiService.java
new file mode 100644
index 00000000..12d1552e
--- /dev/null
+++
b/ozhera-log/log-api/src/main/java/org/apache/ozhera/log/api/service/LogAgentApiService.java
@@ -0,0 +1,59 @@
+/*
+ * 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.ozhera.log.api.service;
+
+import org.apache.ozhera.log.api.model.agent.SpaceInfo;
+import org.apache.ozhera.log.api.model.agent.StoreInfo;
+import org.apache.ozhera.log.api.model.agent.TailInfo;
+
+public interface LogAgentApiService {
+
+ //---space---
+
+ String createSpace(SpaceInfo info);
+
+ String updateSpace(SpaceInfo info);
+
+ String deleteSpace(SpaceInfo info);
+
+ String getSpaceById(Long spaceId);
+
+ //---store---
+
+ String getStoresInSpace(Long spaceId);
+
+ String getStoreInfoById(StoreInfo info);
+
+ String createStore(StoreInfo info);
+
+ String updateStore(StoreInfo info);
+
+ String deleteStore(StoreInfo info);
+
+ //---tail---
+
+ String createTail(TailInfo info);
+
+ String updateTail(TailInfo info);
+
+ String deleteTail(TailInfo info);
+
+ String getTailById(Long tailId);
+
+}
diff --git a/ozhera-log/log-manager/pom.xml b/ozhera-log/log-manager/pom.xml
index a2bdf3c1..ff229d8f 100644
--- a/ozhera-log/log-manager/pom.xml
+++ b/ozhera-log/log-manager/pom.xml
@@ -28,7 +28,8 @@ http://www.apache.org/licenses/LICENSE-2.0
<modelVersion>4.0.0</modelVersion>
<artifactId>log-manager</artifactId>
- <version>2.2.9-SNAPSHOT</version>
+ <version>2.3.1-SNAPSHOT</version>
+
<properties>
<maven.compiler.source>21</maven.compiler.source>
@@ -214,6 +215,7 @@ http://www.apache.org/licenses/LICENSE-2.0
<dependency>
<groupId>org.apache.ozhera</groupId>
<artifactId>log-api</artifactId>
+ <version>2.2.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.ozhera</groupId>
diff --git
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/controller/MilogConfigController.java
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/controller/MilogConfigController.java
index 5280de41..98fdd9c4 100644
---
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/controller/MilogConfigController.java
+++
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/controller/MilogConfigController.java
@@ -26,6 +26,7 @@ import org.apache.ozhera.log.api.model.meta.NodeCollInfo;
import org.apache.ozhera.log.api.model.vo.TailLogProcessDTO;
import org.apache.ozhera.log.api.model.vo.UpdateLogProcessCmd;
import org.apache.ozhera.log.common.Result;
+import org.apache.ozhera.log.manager.common.context.MoneUserContext;
import org.apache.ozhera.log.manager.model.MilogSpaceParam;
import org.apache.ozhera.log.manager.model.bo.BatchQueryParam;
import org.apache.ozhera.log.manager.model.bo.LogTailParam;
@@ -41,6 +42,7 @@ import
org.apache.ozhera.log.manager.service.impl.LogSpaceServiceImpl;
import org.apache.ozhera.log.manager.service.impl.LogStoreServiceImpl;
import org.apache.ozhera.log.manager.service.impl.LogTailServiceImpl;
+
import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
diff --git
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/BaseService.java
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/BaseService.java
index f588cd26..a116dbbc 100644
---
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/BaseService.java
+++
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/BaseService.java
@@ -33,7 +33,7 @@ import static
org.apache.ozhera.log.common.Constant.DEFAULT_OPERATOR;
* @date 2021/12/20 15:56
*/
public class BaseService {
-
+
public void wrapMilogSpace(MilogSpaceDO ms, MilogSpaceParam param) {
ms.setSpaceName(param.getSpaceName());
ms.setTenantId(param.getTenantId());
diff --git
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogAgentApiServiceImpl.java
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogAgentApiServiceImpl.java
new file mode 100644
index 00000000..942bb56a
--- /dev/null
+++
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogAgentApiServiceImpl.java
@@ -0,0 +1,454 @@
+/*
+ * 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.ozhera.log.manager.service.impl;
+
+
+import com.xiaomi.mone.tpc.login.vo.AuthUserVo;
+import com.xiaomi.youpin.docean.plugin.dubbo.anno.Service;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ozhera.log.api.model.agent.AgentApiResult;
+import org.apache.ozhera.log.api.model.agent.SpaceInfo;
+import org.apache.ozhera.log.api.model.agent.StoreInfo;
+import org.apache.ozhera.log.api.model.agent.TailInfo;
+import org.apache.ozhera.log.api.model.agent.UserInfo;
+import org.apache.ozhera.log.api.service.HeraLogApiService;
+import org.apache.ozhera.log.api.service.LogAgentApiService;
+import org.apache.ozhera.log.common.Result;
+import org.apache.ozhera.log.exception.CommonError;
+import org.apache.ozhera.log.manager.common.context.MoneUserContext;
+import org.apache.ozhera.log.manager.domain.Tpc;
+import org.apache.ozhera.log.manager.model.MilogSpaceParam;
+import org.apache.ozhera.log.manager.model.bo.LogTailParam;
+import org.apache.ozhera.log.manager.model.dto.LogStoreDTO;
+import org.apache.ozhera.log.manager.model.dto.LogTailDTO;
+import org.apache.ozhera.log.manager.model.dto.MilogSpaceDTO;
+import org.apache.ozhera.log.manager.model.dto.MilogSpaceTreeDTO;
+import org.apache.ozhera.log.manager.model.dto.MotorRoomDTO;
+import org.apache.ozhera.log.manager.model.vo.LogStoreParam;
+import org.apache.ozhera.log.manager.service.HeralogHomePageService;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+@Slf4j
+@Service(interfaceClass = HeraLogApiService.class, group = "$dubbo.group",
timeout = 10000)
+public class LogAgentApiServiceImpl implements LogAgentApiService {
+
+ @Resource
+ private LogSpaceServiceImpl logSpaceService;
+
+ @Resource
+ private LogStoreServiceImpl logStoreService;
+
+ @Resource
+ private LogTailServiceImpl logTailService;
+
+ @Resource
+ private HeralogHomePageService heralogHomePageService;
+
+ @Resource
+ private Tpc tpc;
+
+ @Override
+ public String createSpace(SpaceInfo info) {
+ if (info.getSpaceName() == null || info.getSpaceName().isEmpty()) {
+ return AgentApiResult.fail("The space name cannot be empty!");
+ }
+ if (info.getSpaceDescription() == null ||
info.getSpaceDescription().isEmpty()) {
+ return AgentApiResult.fail("The space description cannot be
empty!");
+ }
+ if (info.getUserInfo().getUser() == null ||
info.getUserInfo().getUser().isEmpty()) {
+ return AgentApiResult.fail("The user information is empty. Please
provide the correct user information!");
+ }
+
+ MilogSpaceParam param = new MilogSpaceParam();
+ param.setSpaceName(info.getSpaceName());
+ param.setDescription(info.getSpaceDescription());
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<String> result = logSpaceService.newMilogSpace(param);
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Create space failed, the reason
for the failure is " + result.getMessage());
+ }
+ return AgentApiResult.successBuilder()
+ .addData("spaceId", result.getData())
+ .build();
+ } catch (Exception e) {
+ log.error("create space failed, name: {}, description: {}, error
msg: {}", info.getSpaceName(), info.getSpaceDescription(), e.getMessage());
+ return AgentApiResult.fail("Create space failed, the reason for
the failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String updateSpace(SpaceInfo info) {
+ if (info.getSpaceId() == null || info.getSpaceId() < 0) {
+ return AgentApiResult.fail("The space id cannot be empty!");
+ }
+ if (info.getSpaceName() == null || info.getSpaceName().isEmpty()) {
+ return AgentApiResult.fail("The space name cannot be empty!");
+ }
+ if (info.getSpaceDescription() == null ||
info.getSpaceDescription().isEmpty()) {
+ return AgentApiResult.fail("The space description cannot be
empty!");
+ }
+ if (info.getUserInfo().getUser() == null ||
info.getUserInfo().getUser().isEmpty()) {
+ return AgentApiResult.fail("The user information is empty. Please
provide the correct user information!");
+ }
+
+ MilogSpaceParam param = new MilogSpaceParam();
+ param.setId(info.getSpaceId());
+ param.setSpaceName(info.getSpaceName());
+ param.setDescription(info.getSpaceDescription());
+
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<String> result = logSpaceService.updateMilogSpace(param);
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Update space failed, the reason
for the failure is " + result.getMessage());
+ }
+ return AgentApiResult.success();
+ } catch (Exception e) {
+ log.error("Update space failed, name: {}, description: {}, error
msg: {}", info.getSpaceName(), info.getSpaceDescription(), e.getMessage());
+ return AgentApiResult.fail("Update space failed, the reason for
the failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String deleteSpace(SpaceInfo info) {
+ if (info.getSpaceId() == null || info.getSpaceId() < 0) {
+ return AgentApiResult.fail("The space id cannot be empty!");
+ }
+ if (info.getUserInfo().getUser() == null ||
info.getUserInfo().getUser().isEmpty() || info.getUserInfo().getUserType() ==
null) {
+ return AgentApiResult.fail("The user information is empty. Please
provide the correct user information!");
+ }
+
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<String> result =
logSpaceService.deleteMilogSpace(info.getSpaceId());
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Delete space failed, the reason
for the failure is " + result.getMessage());
+ }
+ return AgentApiResult.success();
+ } catch (Exception e) {
+ log.error("Delete space failed, space id: {}, error msg: {}",
info.getSpaceId(), e.getMessage());
+ return AgentApiResult.fail("Delete space failed, the reason for
the failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String getSpaceById(Long spaceId) {
+ try {
+ Result<MilogSpaceDTO> result =
logSpaceService.getMilogSpaceById(spaceId);
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Get space failed, the reason for
the failure is " + result.getMessage());
+ }
+ return AgentApiResult.successBuilder()
+ .addData("space", result.getData())
+ .build();
+ } catch (Exception e) {
+ log.error("Get space failed! space id: {}, message: {}", spaceId,
e.getMessage());
+ return AgentApiResult.fail("Get space failed, the reason for the
failure is " + e.getMessage());
+ }
+ }
+
+ @Override
+ public String getStoresInSpace(Long spaceId) {
+ try {
+ Result<List<MilogSpaceTreeDTO>> tree =
heralogHomePageService.getMilogSpaceTree(spaceId);
+ if (tree.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Failed to obtain the list of
stores in the current space, the reason is " + tree.getMessage());
+ }
+ return AgentApiResult.successBuilder()
+ .addData("stores", tree.getData())
+ .build();
+ } catch (Exception e) {
+ log.error("Failed to obtain the list of stores in the current
space, spaceId: {}, the reason is {}", spaceId, e.getMessage());
+ return AgentApiResult.fail("Failed to obtain the list of stores in
the current space, the reason is " + e.getMessage());
+ }
+ }
+
+ @Override
+ public String getStoreInfoById(StoreInfo info) {
+ if (info.getStoreId() == null || info.getStoreId() < 0) {
+ return AgentApiResult.fail("The store id cannot be empty!");
+ }
+ if (info.getUserInfo() == null || info.getUserInfo().getUser() == null
|| info.getUserInfo().getUser().isEmpty()) {
+ return AgentApiResult.fail("The user information is empty. Please
provide the correct user information!");
+ }
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<LogStoreDTO> result =
logStoreService.getLogStoreById(info.getStoreId());
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Get store failed, the reason for
the failure is " + result.getMessage());
+ }
+ return AgentApiResult.successBuilder()
+ .addData("store", result.getData())
+ .build();
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String createStore(StoreInfo info) {
+ String validationResult = info.isValidParam(true);
+ if (validationResult != null) {
+ return AgentApiResult.fail(validationResult);
+ }
+
+ LogStoreParam param = buildLogStoreParam(info, true);
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<String> result = logStoreService.newLogStore(param);
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Create store failed, the reason
for the failure is " + result.getMessage());
+ }
+ return AgentApiResult.success();
+ } catch (Exception e) {
+ log.error("Create store failed, name: {}, spaceId: {}, error msg:
{}", info.getStoreName(), info.getSpaceId(), e.getMessage());
+ return AgentApiResult.fail("Create store failed, the reason for
the failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String updateStore(StoreInfo info) {
+ String validationResult = info.isValidParam(false);
+ if (validationResult != null) {
+ return AgentApiResult.fail(validationResult);
+ }
+
+ LogStoreParam param = buildLogStoreParam(info, false);
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<String> result = logStoreService.newLogStore(param);
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Update store failed, the reason
for the failure is " + result.getMessage());
+ }
+ return AgentApiResult.success();
+ } catch (Exception e) {
+ log.error("Update store failed, name: {}, storeId: {}, error msg:
{}", info.getStoreName(), info.getStoreId(), e.getMessage());
+ return AgentApiResult.fail("Update store failed, the reason for
the failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String deleteStore(StoreInfo info) {
+ if (info.getStoreId() == null || info.getStoreId() < 0) {
+ return AgentApiResult.fail("The store id cannot be empty!");
+ }
+ if (info.getUserInfo() == null || info.getUserInfo().getUser() == null
|| info.getUserInfo().getUser().isEmpty()) {
+ return AgentApiResult.fail("The user information is empty. Please
provide the correct user information!");
+ }
+
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<Void> result =
logStoreService.deleteLogStore(info.getStoreId());
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Delete store failed, the reason
for the failure is " + result.getMessage());
+ }
+ return AgentApiResult.success();
+ } catch (Exception e) {
+ log.error("Delete store failed, storeId: {}, error msg: {}",
info.getStoreId(), e.getMessage());
+ return AgentApiResult.fail("Delete store failed, the reason for
the failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ private LogStoreParam buildLogStoreParam(StoreInfo info, boolean isCreate)
{
+ LogStoreParam param = new LogStoreParam();
+ if (!isCreate) {
+ param.setId(info.getStoreId());
+ }
+ param.setSpaceId(info.getSpaceId());
+ param.setLogstoreName(info.getStoreName());
+ param.setStorePeriod(info.getStorePeriod());
+ param.setShardCnt(info.getShardCnt());
+ param.setKeyList(info.getKeyList());
+ param.setColumnTypeList(info.getColumnTypeList());
+ if (info.getLogType() != null) {
+ param.setLogType(Integer.parseInt(info.getLogType()));
+ }
+ if (info.getMachineRoom() != null) {
+ param.setMachineRoom(String.valueOf(info.getMachineRoom()));
+ }
+ if (info.getMqResourceId() != null) {
+ param.setMqResourceId(Long.valueOf(info.getMqResourceId()));
+ }
+ if (info.getEsResourceId() != null) {
+ param.setEsResourceId(Long.valueOf(info.getEsResourceId()));
+ }
+ return param;
+ }
+
+ @Override
+ public String createTail(TailInfo info) {
+ String validationResult = info.isValidParam(true);
+ if (validationResult != null) {
+ return AgentApiResult.fail(validationResult);
+ }
+
+ LogTailParam param = buildLogTailParam(info, true);
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<LogTailDTO> result = logTailService.newMilogLogTail(param);
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Create tail failed, the reason for
the failure is " + result.getMessage());
+ }
+ return AgentApiResult.successBuilder()
+ .addData("tailId", result.getData().getId())
+ .build();
+ } catch (Exception e) {
+ log.error("Create tail failed, tail: {}, storeId: {}, error msg:
{}", info.getTail(), info.getStoreId(), e.getMessage());
+ return AgentApiResult.fail("Create tail failed, the reason for the
failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String updateTail(TailInfo info) {
+ String validationResult = info.isValidParam(false);
+ if (validationResult != null) {
+ return AgentApiResult.fail(validationResult);
+ }
+
+ LogTailParam param = buildLogTailParam(info, false);
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<Void> result = logTailService.updateMilogLogTail(param);
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Update tail failed, the reason for
the failure is " + result.getMessage());
+ }
+ return AgentApiResult.success();
+ } catch (Exception e) {
+ log.error("Update tail failed, tail: {}, tailId: {}, error msg:
{}", info.getTail(), info.getId(), e.getMessage());
+ return AgentApiResult.fail("Update tail failed, the reason for the
failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String deleteTail(TailInfo info) {
+ if (info.getId() == null || info.getId() < 0) {
+ return AgentApiResult.fail("The tail id cannot be empty!");
+ }
+ if (info.getUserInfo() == null || info.getUserInfo().getUser() == null
|| info.getUserInfo().getUser().isEmpty()) {
+ return AgentApiResult.fail("The user information is empty. Please
provide the correct user information!");
+ }
+
+ try {
+ setMoneUserContext(info.getUserInfo());
+ Result<Void> result = logTailService.deleteLogTail(info.getId());
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Delete tail failed, the reason for
the failure is " + result.getMessage());
+ }
+ return AgentApiResult.success();
+ } catch (Exception e) {
+ log.error("Delete tail failed, tailId: {}, error msg: {}",
info.getId(), e.getMessage());
+ return AgentApiResult.fail("Delete tail failed, the reason for the
failure is " + e.getMessage());
+ } finally {
+ MoneUserContext.clear();
+ }
+ }
+
+ @Override
+ public String getTailById(Long tailId) {
+ if (tailId == null || tailId < 0) {
+ return AgentApiResult.fail("The tail id cannot be empty!");
+ }
+
+ try {
+ Result<LogTailDTO> result =
logTailService.getMilogLogtailById(tailId);
+ if (result.getCode() != CommonError.Success.getCode()) {
+ return AgentApiResult.fail("Get tail failed, the reason for
the failure is " + result.getMessage());
+ }
+ return AgentApiResult.successBuilder()
+ .addData("tail", result.getData())
+ .build();
+ } catch (Exception e) {
+ log.error("Get tail failed, tailId: {}, error msg: {}", tailId,
e.getMessage());
+ return AgentApiResult.fail("Get tail failed, the reason for the
failure is " + e.getMessage());
+ }
+ }
+
+
+ private void setMoneUserContext(UserInfo userInfo) {
+ AuthUserVo authUserVo = new AuthUserVo();
+ authUserVo.setAccount(userInfo.getUser());
+ authUserVo.setUserType(userInfo.getUserType());
+ boolean isAdmin = tpc.isAdmin(userInfo.getUser(),
userInfo.getUserType());
+ MoneUserContext.setCurrentUser(authUserVo, isAdmin);
+ }
+
+ private LogTailParam buildLogTailParam(TailInfo info, boolean isCreate) {
+ LogTailParam param = new LogTailParam();
+ if (!isCreate) {
+ param.setId(info.getId());
+ }
+ param.setSpaceId(info.getSpaceId());
+ param.setStoreId(info.getStoreId());
+ param.setMilogAppId(info.getMilogAppId());
+ param.setAppId(info.getAppId());
+ param.setAppName(info.getAppName());
+ param.setEnvId(info.getEnvId());
+ param.setEnvName(info.getEnvName());
+ param.setIps(info.getIps());
+ param.setTail(info.getTail());
+ param.setParseType(info.getParseType());
+ param.setParseScript(info.getParseScript());
+ param.setLogPath(info.getLogPath());
+ param.setValueList(info.getValueList());
+ param.setTailRate(info.getTailRate());
+ param.setLogSplitExpress(info.getLogSplitExpress());
+ param.setFirstLineReg(info.getFirstLineReg());
+ param.setAppType(info.getAppType());
+ param.setMachineType(info.getMachineType());
+ param.setDeployWay(info.getDeployWay());
+ param.setBatchSendSize(info.getBatchSendSize());
+ param.setCollectionReady(info.getCollectionReady());
+
+ if (info.getMotorRooms() != null) {
+ List<MotorRoomDTO> motorRoomDTOList = new ArrayList<>();
+ for (Object item : info.getMotorRooms()) {
+ if (item instanceof MotorRoomDTO) {
+ motorRoomDTOList.add((MotorRoomDTO) item);
+ }
+ }
+ param.setMotorRooms(motorRoomDTOList);
+ }
+
+ if (info.getMiddlewareConfig() != null) {
+ param.setMiddlewareConfig(info.getMiddlewareConfig());
+ }
+
+ return param;
+ }
+}
diff --git
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogSpaceServiceImpl.java
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogSpaceServiceImpl.java
index 264448d8..dc2e113a 100644
---
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogSpaceServiceImpl.java
+++
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/LogSpaceServiceImpl.java
@@ -128,7 +128,7 @@ public class LogSpaceServiceImpl extends BaseService
implements LogSpaceService
return Result.failParam("Space is not associated with a permission
system");
}
- return Result.success();
+ return Result.success(String.valueOf(dbDO.getId()));
}
private void addMemberAsync(Long spaceId, List<String> otherAdmins) {
@@ -318,7 +318,7 @@ public class LogSpaceServiceImpl extends BaseService
implements LogSpaceService
if (milogSpaceDao.deleteMilogSpace(id)) {
logTailService.deleteConfigRemote(id, id,
MachineRegionEnum.CN_MACHINE.getEn(), LogStructureEnum.SPACE);
-
SPACE_ALL_CACHE.invalidate(buildCacheKey(milogSpace.getTenantId(),""));
+ SPACE_ALL_CACHE.invalidate(buildCacheKey(milogSpace.getTenantId(),
""));
com.xiaomi.youpin.infra.rpc.Result tpcResult =
spaceAuthService.deleteSpaceTpc(id, MoneUserContext.getCurrentUser().getUser(),
MoneUserContext.getCurrentUser().getUserType());
if (tpcResult == null || tpcResult.getCode() != 0) {
log.error("Remove the space without associated permission
system,space:[{}], tpcResult:[{}]", milogSpace, tpcResult);
diff --git
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/MilogAiAnalysisServiceImpl.java
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/MilogAiAnalysisServiceImpl.java
index d1c9a291..6d733027 100644
---
a/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/MilogAiAnalysisServiceImpl.java
+++
b/ozhera-log/log-manager/src/main/java/org/apache/ozhera/log/manager/service/impl/MilogAiAnalysisServiceImpl.java
@@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.ozhera.log.common.Config;
import org.apache.ozhera.log.common.Result;
import org.apache.ozhera.log.exception.CommonError;
+import org.apache.ozhera.log.manager.common.utils.LogStackTruncator;
import org.apache.ozhera.log.manager.common.context.MoneUserContext;
import org.apache.ozhera.log.manager.config.redis.RedisClientFactory;
import org.apache.ozhera.log.manager.mapper.MilogAiConversationMapper;
@@ -136,8 +137,21 @@ public class MilogAiAnalysisServiceImpl implements
MilogAiAnalysisService {
return Result.failParam("Store id is null");
}
- if (requestExceedLimit(tailLogAiAnalysisDTO.getLogs())) {
- return Result.failParam("The length of the input information
reaches the maximum limit");
+ // Smart truncation for long stack traces instead of rejecting
+ List<String> processedLogs = tailLogAiAnalysisDTO.getLogs();
+ if (requestExceedLimit(processedLogs)) {
+ LogStackTruncator.TruncationResult truncationResult =
LogStackTruncator.truncate(processedLogs);
+ if (truncationResult.wasTruncated()) {
+ processedLogs = truncationResult.getTruncatedLogs();
+ log.info("Logs truncated for AI analysis: originalTokens={},
truncatedTokens={}, language={}",
+ truncationResult.getOriginalTokenCount(),
+ truncationResult.getTruncatedTokenCount(),
+ truncationResult.getDetectedLanguage());
+ }
+ // Check again after truncation
+ if (requestExceedLimit(processedLogs)) {
+ return Result.failParam("The length of the input information
reaches the maximum limit even after truncation");
+ }
}
MoneUser user = MoneUserContext.getCurrentUser();
@@ -147,7 +161,7 @@ public class MilogAiAnalysisServiceImpl implements
MilogAiAnalysisService {
String answer = "";
try {
BotQAParam param = new BotQAParam();
-
param.setLatestQuestion(formatLogs(tailLogAiAnalysisDTO.getLogs()));
+ param.setLatestQuestion(formatLogs(processedLogs));
String paramJson = gson.toJson(param);
analysisBot.getRc().news.put(Message.builder().content(paramJson).build());
Message result = analysisBot.run().join();
@@ -161,7 +175,7 @@ public class MilogAiAnalysisServiceImpl implements
MilogAiAnalysisService {
long timestamp = System.currentTimeMillis();
String nowTimeStr =
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
conversation.setTime(nowTimeStr);
- conversation.setUser(formatLogs(tailLogAiAnalysisDTO.getLogs()));
+ conversation.setUser(formatLogs(processedLogs));
conversation.setBot(answer);
List<BotQAParam.QAParam> ModelHistory = new ArrayList<>();
@@ -194,11 +208,11 @@ public class MilogAiAnalysisServiceImpl implements
MilogAiAnalysisService {
Map<String, List<BotQAParam.QAParam>> cache =
getConversation(conversationId);
List<BotQAParam.QAParam> modelHistory = cache.get(MODEL_KEY);
List<BotQAParam.QAParam> originalHistory = cache.get(ORIGINAL_KEY);
- AnalysisResult analysisResult =
processHistoryConversation(conversationId, cache, tailLogAiAnalysisDTO);
+ AnalysisResult analysisResult =
processHistoryConversation(conversationId, cache, processedLogs);
String answer = analysisResult.getAnswer();
BotQAParam.QAParam conversation = new BotQAParam.QAParam();
conversation.setTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd
HH:mm:ss")));
- conversation.setUser(formatLogs(tailLogAiAnalysisDTO.getLogs()));
+ conversation.setUser(formatLogs(processedLogs));
conversation.setBot(answer);
if (analysisResult.getCompressedModelHistory() != null) {
List<BotQAParam.QAParam> compressedModelHistory =
analysisResult.getCompressedModelHistory();
@@ -218,14 +232,14 @@ public class MilogAiAnalysisServiceImpl implements
MilogAiAnalysisService {
}
- private AnalysisResult processHistoryConversation(Long conversationId,
Map<String, List<BotQAParam.QAParam>> cache, LogAiAnalysisDTO
tailLogAiAnalysisDTO) {
+ private AnalysisResult processHistoryConversation(Long conversationId,
Map<String, List<BotQAParam.QAParam>> cache, List<String> logs) {
List<BotQAParam.QAParam> modelHistory = cache.get(MODEL_KEY);
List<BotQAParam.QAParam> originalHistory = cache.get(ORIGINAL_KEY);
AnalysisResult res = new AnalysisResult();
try {
BotQAParam param = new BotQAParam();
param.setHistoryConversation(modelHistory);
-
param.setLatestQuestion(formatLogs(tailLogAiAnalysisDTO.getLogs()));
+ param.setLatestQuestion(formatLogs(logs));
String paramJson = gson.toJson(param);
if (TOKENIZER.countTokens(paramJson) < 70000) {
analysisBot.getRc().news.put(Message.builder().content(paramJson).build());
@@ -234,7 +248,7 @@ public class MilogAiAnalysisServiceImpl implements
MilogAiAnalysisService {
res.setAnswer(answer);
return res;
} else {
- return analysisAndCompression(modelHistory, originalHistory,
tailLogAiAnalysisDTO.getLogs(), conversationId);
+ return analysisAndCompression(modelHistory, originalHistory,
logs, conversationId);
}
} catch (InterruptedException e) {
log.error("An error occurred in the request for the large model,
err: {}", e.getMessage());
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]