Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: log some bug fix and opzimize #496

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.apache.ozhera.log.agent.channel;

import cn.hutool.system.SystemUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xiaomi.data.push.common.SafeRun;
Expand All @@ -25,6 +26,9 @@
import com.xiaomi.mone.file.common.FileInfoCache;
import com.xiaomi.mone.file.listener.DefaultMonitorListener;
import com.xiaomi.mone.file.ozhera.HeraFileMonitor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ozhera.log.agent.channel.file.MonitorFile;
import org.apache.ozhera.log.agent.channel.memory.AgentMemoryService;
import org.apache.ozhera.log.agent.channel.memory.ChannelMemory;
Expand All @@ -37,9 +41,6 @@
import org.apache.ozhera.log.api.model.meta.FilterConf;
import org.apache.ozhera.log.api.model.msg.LineMessage;
import org.apache.ozhera.log.common.PathUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -102,6 +103,8 @@ public class WildcardChannelServiceImpl extends AbstractChannelService {

private DefaultMonitorListener defaultMonitorListener;

private HeraFileMonitor fileMonitor;


public WildcardChannelServiceImpl(MsgExporter msgExporter, AgentMemoryService memoryService,
ChannelDefine channelDefine, FilterChain chain, String memoryBasePath) {
Expand Down Expand Up @@ -143,7 +146,7 @@ private void startCollectFile(Long channelId, Input input, String ip) {
String restartFile = buildRestartFilePath();
FileInfoCache.ins().load(restartFile);

HeraFileMonitor monitor = createFileMonitor(input.getPatternCode(), ip);
fileMonitor = createFileMonitor(input.getPatternCode(), ip);

String fileExpression = buildFileExpression(input.getLogPattern());

Expand All @@ -157,7 +160,7 @@ private void startCollectFile(Long channelId, Input input, String ip) {
// Compile the file expression pattern
Pattern pattern = Pattern.compile(fileExpression);
for (String monitorPath : monitorPaths) {
fileCollFutures.add(ExecutorUtil.submit(() -> monitorFileChanges(monitor, monitorPath, pattern)));
fileCollFutures.add(ExecutorUtil.submit(() -> monitorFileChanges(fileMonitor, monitorPath, pattern)));
}
} catch (Exception e) {
log.error("startCollectFile error, channelId: {}, input: {}, ip: {}", channelId, GSON.toJson(input), ip, e);
Expand Down Expand Up @@ -223,6 +226,9 @@ private void monitorFileChanges(HeraFileMonitor monitor, String monitorPath, Pat
try {
log.info("monitorFileChanges,directory:{}", monitorPath);
monitor.reg(monitorPath, filePath -> {
if (SystemUtil.getOsInfo().isWindows()) {
return true;
}
boolean matches = pattern.matcher(filePath).matches();
log.debug("file: {}, matches: {}", filePath, matches);
return matches;
Expand Down Expand Up @@ -441,6 +447,7 @@ public void deleteCollFile(String directory) {

@Override
public void close() {
fileMonitor.stop();
log.info("Delete the current collection task,channelId:{}", channelDefine.getChannelId());
//2. stop exporting
this.msgExporter.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static TSpanData toTSpanData(String[] array) {
span.setKind(toTKind(spanKind));
span.setEvents(toTEventList(JSONArray.parseArray(decodeLineBreak(array[MessageUtil.EVENTS]))));
span.setTotalRecordedEvents(span.getEventsSize());
span.setResource(
span.setResouce(
toTResource(JSONObject.parseObject(array[MessageUtil.REOUSCES]), specialAttrMap));
span.setExtra(toTExtra(specialAttrMap));
// using links["ref_type=CHILD_OF"] as parent span context and using left as links
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private void stopOldJobForTail(LogtailConfig logTailConfig, SinkConfig sinkConfi
* @param newMilogSpaceData
*/
private void initNewJob(MilogSpaceData newMilogSpaceData) {
stopOldJobsIfNeeded();
log.info("Start all tasks to restart the current space,spaceData:{}", gson.toJson(newMilogSpaceData));
Map<Long, LogtailConfig> newLogTailConfigMap = new HashMap<>();
Map<Long, SinkConfig> newSinkConfigMap = new HashMap<>();
Expand All @@ -262,9 +263,24 @@ private void initNewJob(MilogSpaceData newMilogSpaceData) {
oldSinkConfigMap = newSinkConfigMap;
}

private void stopOldJobsIfNeeded() {
if (!oldLogTailConfigMap.isEmpty()) {
for (LogtailConfig value : oldLogTailConfigMap.values()) {
jobManager.stopJob(value);
}
oldLogTailConfigMap.clear();
}
if (!oldSinkConfigMap.isEmpty()) {
for (SinkConfig value : oldSinkConfigMap.values()) {
stopOldJobsForStore(value.getLogstoreId());
}
oldSinkConfigMap.clear();
}
}

private void startTailPer(SinkConfig sinkConfig, LogtailConfig logTailConfig, Long logSpaceId) {
if (null == logSpaceId) {
log.warn("startTailPer error,logSpaceId is null,LogTailConfig:{}", gson.toJson(logTailConfig));
if (null == logSpaceId || null == logTailConfig || null == logTailConfig.getLogtailId()) {
log.error("logSpaceId or logTailConfig or logTailId is null,sinkConfig:{},logTailConfig:{},logSpaceId:{}", gson.toJson(sinkConfig), gson.toJson(logTailConfig), spaceId);
return;
}
Boolean isStart = streamCommonExtension.preCheckTaskExecution(sinkConfig, logTailConfig, logSpaceId);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@
<dependency>
<groupId>run.mone</groupId>
<artifactId>file</artifactId>
<version>1.5.1-jdk21</version>
<version>1.6.0-jdk21</version>
</dependency>
<dependency>
<groupId>run.mone</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public Map<String, Object> buildSpanData(TSpanData tSpanData) {
// build logs
spanData.put(HeraTraceSpanColumn.logs, GSON.toJson(buildLogs(tSpanData.getEvents())));
// build process
spanData.put(HeraTraceSpanColumn.process, GSON.toJson(buildProcess(tSpanData.getExtra().getServiceName(), tSpanData.getResource())));
spanData.put(HeraTraceSpanColumn.process, GSON.toJson(buildProcess(tSpanData.getExtra().getServiceName(), tSpanData.getResouce())));
return spanData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public String buildJaegerES(TSpanData tSpanData) {
// build logs
jaegerESDomain.setLogs(buildLogs(tSpanData.getEvents()));
// build process
jaegerESDomain.setProcess(buildProcess(tSpanData.getExtra().getServiceName(), tSpanData.getResource()));
jaegerESDomain.setProcess(buildProcess(tSpanData.getExtra().getServiceName(), tSpanData.getResouce()));
return JSONObject.toJSONString(jaegerESDomain, SerializerFeature.WriteMapNullValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public MetricsParseResult metricsParse(TSpanData tSpanData) {
}
}
// Gets the properties in process
TResource resource = tSpanData.getResource();
TResource resource = tSpanData.getResouce();
if (resource != null) {
TAttributes resourceAttributes = resource.getAttributes();
List<TAttributeKey> resourceKeys = resourceAttributes.getKeys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static TSpanData toTSpanData(String[] array) {
span.setKind(toTKind(spanKind));
span.setEvents(toTEventList(JSONArray.parseArray(decodeLineBreak(array[MessageUtil.EVENTS]))));
span.setTotalRecordedEvents(span.getEventsSize());
span.setResource(
span.setResouce(
toTResource(JSONObject.parseObject(array[MessageUtil.REOUSCES]), specialAttrMap));
span.setExtra(toTExtra(specialAttrMap));
// using links["ref_type=CHILD_OF"] as parent span context and using left as links
Expand Down
Loading