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(home): add resourceKeys in supercache #832

Merged
merged 1 commit into from
Apr 8, 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 @@ -31,5 +31,6 @@ protected void refresh(Binder binder) {
@Data
public static class Materialize {
private Set<String> blacklist = new HashSet<>();
private Boolean traceWriteClose = Boolean.FALSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.holoinsight.server.apm.common.model.query.Duration;
import io.holoinsight.server.apm.common.model.query.MetricValues;
import io.holoinsight.server.apm.engine.postcal.MetricsManager;
import io.holoinsight.server.apm.engine.storage.MetricStorage;
import io.holoinsight.server.apm.server.service.MetricService;
import io.holoinsight.server.common.dao.entity.TenantOps;
import io.holoinsight.server.common.dao.mapper.TenantOpsMapper;
Expand All @@ -18,10 +17,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
Expand All @@ -32,6 +34,7 @@

@Component
@Slf4j
@Deprecated
public class ApmMetricMaterializer {

@Autowired
Expand Down Expand Up @@ -66,13 +69,13 @@ public class ApmMetricMaterializer {
new ThreadPoolExecutor(4, 4, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>(4096),
new BasicThreadFactory.Builder().namingPattern("apm-materialize-executor-%d").build());

@PostConstruct
public void start() {
long now = System.currentTimeMillis();
long nextPeriod = now / INTERVAL * INTERVAL + INTERVAL;
long wait = nextPeriod - now + DELAY;
SCHEDULER.scheduleAtFixedRate(this::materialize, wait, INTERVAL, TimeUnit.MILLISECONDS);
}
// @PostConstruct
// public void start() {
// long now = System.currentTimeMillis();
// long nextPeriod = now / INTERVAL * INTERVAL + INTERVAL;
// long wait = nextPeriod - now + DELAY;
// SCHEDULER.scheduleAtFixedRate(this::materialize, wait, INTERVAL, TimeUnit.MILLISECONDS);
// }

private void materialize() {
long now = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public String buildResourceVal(List<String> resourceKeys, Map<String, String> ta

@Override
public boolean productClosed(MonitorProductCode productCode, Map<String, String> tags) {
List<String> resourceKeys = superCacheService.getSc().getListValue("global_config",
"resource_keys", Collections.singletonList("tenant"));
List<String> resourceKeys = superCacheService.getSc().resourceKeys;
if (!switchOn || productCode == null || resourceKeys == null || tags == null
|| productClosed == null) {
return false;
Expand All @@ -119,8 +118,7 @@ public boolean productClosed(MonitorProductCode productCode, Map<String, String>
public Map<String, Set<String>> productCtl(MonitorProductCode code, Map<String, String> tags,
String action) throws Exception {
Map<String, Set<String>> result = new HashMap<>();
List<String> resourceKeys = superCacheService.getSc().getListValue("global_config",
"resource_keys", Collections.singletonList("tenant"));
List<String> resourceKeys = superCacheService.getSc().resourceKeys;
if (CollectionUtils.isEmpty(resourceKeys)) {
throw new RuntimeException("resource keys not found for code : " + code.getCode());
}
Expand All @@ -144,8 +142,7 @@ public Map<String, Set<String>> productCtl(MonitorProductCode code, Map<String,
@Override
public Map<String, Boolean> productStatus(Map<String, String> tags) throws Exception {
Map<String, Boolean> closed = new HashMap<>();
List<String> resourceKeys = superCacheService.getSc().getListValue("global_config",
"resource_keys", Collections.singletonList("tenant"));
List<String> resourceKeys = superCacheService.getSc().resourceKeys;
for (MonitorProductCode code : MonitorProductCode.values()) {
if (CollectionUtils.isEmpty(resourceKeys)) {
closed.put(code.getCode(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.holoinsight.server.query.grpc.QueryProto.QueryRequest;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand All @@ -25,6 +26,9 @@ public class SuperCache {

public Map<String /* metric table */, MetricInfo> metricInfoMap;

public List<String> resourceKeys;
public List<String> freePrefixes;

public String getStringValue(String type, String k) {

Map<String, MetaDataDictValue> kMap = this.metaDataDictValueMap.get(type);
Expand Down Expand Up @@ -56,4 +60,20 @@ public List<String> getListValue(String type, String k, List<String> defaultValu
}
return J.fromJson(meta.getDictValue(), new TypeToken<List<String>>() {}.getType());
}

public Boolean getBooleanValue(String type, String k) {

Map<String, MetaDataDictValue> kMap = this.metaDataDictValueMap.get(type);

if (null == kMap) {
return Boolean.FALSE;
}

MetaDataDictValue meta = kMap.get(k);

if (null == meta || StringUtils.isBlank(meta.getDictValue())) {
return Boolean.FALSE;
}
return Boolean.parseBoolean(meta.getDictValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -50,6 +51,10 @@ public void load() throws Exception {
ProdLog.info("[SuperCache][expressionMetricList] size: " + sc.expressionMetricList.size());

queryMetricInfoByPage(sc);
sc.resourceKeys =
sc.getListValue("global_config", "resource_keys", Collections.singletonList("tenant"));
sc.freePrefixes =
sc.getListValue("global_config", "free_metric_prefix", Collections.emptyList());
this.sc = sc;
ProdLog.info("[SuperCache] load end");
}
Expand Down
Loading