Skip to content

Commit

Permalink
feat: add test case of logmonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
霄鸿 committed May 9, 2024
1 parent 75c8f19 commit 52dfd40
Show file tree
Hide file tree
Showing 17 changed files with 1,236 additions and 278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package io.holoinsight.server.home.task.crawler;

import io.holoinsight.server.common.dao.entity.MetricInfo;
import io.holoinsight.server.home.dal.model.dto.IntegrationProductDTO;
import io.holoinsight.server.home.task.AbstractMetricCrawlerBuilder;
import io.holoinsight.server.home.task.MetricCrawler;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -29,10 +28,11 @@
@Slf4j
@MetricCrawler(code = "io.holoinsight.plugin.ApmPlugin")
public class ApmMetricCrawlerBuilder extends AbstractMetricCrawlerBuilder {

@Override
public List<MetricInfo> buildEntity(IntegrationProductDTO integrationProduct) {
protected List<MetricInfo> getMetricInfoList(String metric, List<String> tags,
MetricInfo metricInfoTemplate) {
List<MetricInfo> metricInfoList = new ArrayList<>();

metricInfoList.add(genMetricInfo(GLOBAL_TENANT, GLOBAL_WORKSPACE, GLOBAL_ORGANIZATION, "apm",
"Endpoint", "endpoint_cpm", "apm_endpoint_cpm", "endpoint calls per minute", NUMBER_UNIT,
60, Arrays.asList("endpointName", "serviceName")));
Expand Down Expand Up @@ -82,10 +82,4 @@ public List<MetricInfo> buildEntity(IntegrationProductDTO integrationProduct) {

return metricInfoList;
}

@Override
protected List<MetricInfo> getMetricInfoList(String metric, List<String> tags,
MetricInfo metricInfoTemplate) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static Map<String, Map<String, Object>> buildFilters(QueryExample queryEx


public static <R> List<R> filterData(Collection<Map<String, Object>> items,
Map<String, Map<String, Object>> filters, Function<Map, R> func) {
Map<String, Map<String, Object>> filters, Function<Map<String, Object>, R> func) {
Map<String, Object> eqFilters = filters.get(EQ_FILTERS_KEY);
Stream<Map<String, Object>> dataStream = items.stream();
if (eqFilters != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public List<Map<String, Object>> addUkValues(String tableName, List<Map<String,

// 所有元数据都需要 关键字 _type
if (!row.containsKey(default_type)) {
logger.info("[addUkValues] has not _type, table={}, row={}.", tableName, row.toString());
logger.info("[addUkValues] has not _type, table={}, row={}.", tableName, row);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,14 @@ public abstract class SqlDataCoreService extends AbstractDataCoreService {

public static final int BATCH_INSERT_SIZE = 5;
public static final int LIMIT = 1000;
// public static final int CLEAN_TASK_PERIOD = 3600;
protected MetaDimDataService metaDimDataService;
protected SuperCacheService superCacheService;

// private static final long DEFAULT_DEL_DURATION = 3 * 24 * 60 * 60 * 1000;
// public static final ScheduledThreadPoolExecutor cleanMeatExecutor =
// new ScheduledThreadPoolExecutor(2, r -> new Thread(r, "meta-clean-scheduler"));

// private void cleanMeta() {
// StopWatch stopWatch = StopWatch.createStarted();
// try {
// long cleanMetaDataDuration = getCleanMetaDataDuration();
// long end = System.currentTimeMillis() - cleanMetaDataDuration;
// logger.info("[META-CLEAN] the cleaning task will clean up the data before {}", end);
// Integer count = metaDimDataService.cleanMetaData(new Date(end));
// logger.info("[META-CLEAN] cleaned up {} pieces of data before {}, cost: {}", count, end,
// stopWatch.getTime());
// } catch (Exception e) {
// logger.error("[META-CLEAN] an exception occurred in the cleanup task", e);
// }
// }

public SqlDataCoreService(MetaDimDataService metaDimDataService,
SuperCacheService superCacheService) {
this.metaDimDataService = metaDimDataService;
this.superCacheService = superCacheService;


//
// int initialDelay = new Random().nextInt(CLEAN_TASK_PERIOD);
// logger.info("[META-CLEAN] clean task will scheduled after {}", initialDelay);
// cleanMeatExecutor.scheduleAtFixedRate(this::cleanMeta, initialDelay, CLEAN_TASK_PERIOD,
// TimeUnit.SECONDS);
}

public Integer queryChangedMeta(Date start, Date end, Boolean containDeleted,
Expand Down Expand Up @@ -127,6 +102,7 @@ public Pair<Integer, Integer> insertOrUpdate(String tableName, List<Map<String,
});
List<MetaDimData> metaDataList =
metaDimDataService.selectByUks(tableName, ukToUpdateOrInsertRow.keySet());
logger.info("selectByUks, table={}, metaDataList={}", tableName, metaDataList.size());
Pair<Integer, Integer> sameAndExistSize;
if (!CollectionUtils.isEmpty(metaDataList)) {
sameAndExistSize = doUpdate(tableName, metaDataList, ukToUpdateOrInsertRow);
Expand Down Expand Up @@ -184,7 +160,7 @@ public Pair<Integer, Integer> doUpdate(String tableName, List<MetaDimData> metaD
for (MetaDimData metaData : metaDataList) {
String uk = metaData.getUk();
existUkSize++;
Map<String, Object> updateOrInsertRow = ukToUpdateOrInsertRow.remove(uk);
Map<String, Object> updateOrInsertRow = ukToUpdateOrInsertRow.get(uk);
Map<String, Object> cachedRows = getMetaByCacheUk(tableName, uk);
Pair<Boolean, Object> sameWithDbAnnotations =
sameWithDbAnnotations(metaData, updateOrInsertRow);
Expand Down
Loading

0 comments on commit 52dfd40

Please sign in to comment.