Skip to content

Commit

Permalink
* debug thread model (timer)
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin.guo committed Jul 19, 2021
1 parent ba59cef commit ec1e7a2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
Expand Up @@ -30,6 +30,10 @@ public class Query {

private String podName;

private String fieldSelector;

private String labelSelector;

private Long clusterId;

private String config;
Expand Down
Expand Up @@ -55,6 +55,11 @@ public void afterPropertiesSet() throws Exception {

@Override
public CompletableFuture<List<Container>> collect(Query query) {
String fieldSelector = StrUtil.isBlank(query.getFieldSelector()) ?
String.format("metadata.name=%s", query.getPodName()) :
String.format("metadata.name=%s,%s", query.getPodName(), query.getFieldSelector());
String labelSelector = query.getLabelSelector();

CompletableFuture<List<Container>> future = new CompletableFuture<>();
CoreV1Api api;
try {
Expand All @@ -64,7 +69,8 @@ public CompletableFuture<List<Container>> collect(Query query) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(query.getConfig().getBytes());
api = new CoreV1Api(Config.fromConfig(byteArrayInputStream));
}
api.listPodForAllNamespacesAsync(null, null, String.format("metadata.name=%s", query.getPodName()), null,

api.listPodForAllNamespacesAsync(null, null, fieldSelector, labelSelector,
null, null, null, null, null,
new ApiCallback<V1PodList>() {
@Override
Expand Down
Expand Up @@ -63,7 +63,7 @@ public CompletableFuture<List<Pod>> collect(Query query) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(query.getConfig().getBytes());
api = new CoreV1Api(Config.fromConfig(byteArrayInputStream));
}
api.listPodForAllNamespacesAsync(null, null, null, null,
api.listPodForAllNamespacesAsync(null, null, query.getFieldSelector(), query.getLabelSelector(),
null, null, null, null, null,
new ApiCallback<V1PodList>() {
@Override
Expand Down
Expand Up @@ -88,6 +88,12 @@ public class CollectorTimer implements InitializingBean {
@Value("${chaos.collector.period}")
private Integer period;

@Value("${chaos.collector.search.fieldSelector}")
private String fieldSelector;

@Value("${chaos.collector.search.labelSelector}")
private String labelSelector;

@Autowired
private ApplicationContext applicationContext;

Expand Down Expand Up @@ -193,8 +199,10 @@ private void podCollect(PodCollector collector, Query query) {
q.setClusterId(query.getClusterId());
q.setConfig(query.getConfig());
q.setNodeName(node.getNodeName());
CompletableFuture<List<Pod>> future = collector.collect(q);
q.setFieldSelector(fieldSelector) ;
q.setLabelSelector(labelSelector);

CompletableFuture<List<Pod>> future = collector.collect(q);
QueryWrapper<DeviceDO> queryWrapper = QueryWrapperBuilder.build();
queryWrapper.lambda().eq(DeviceDO::getType, DeviceType.POD.getCode());
deviceMapper.update(DeviceDO.builder().lastPingTime(DateUtil.date()).build(), queryWrapper);
Expand Down Expand Up @@ -260,6 +268,8 @@ private void containerCollect(ContainerCollector collector, Query query) {
q.setClusterId(query.getClusterId());
q.setConfig(query.getConfig());
q.setPodName(devicePod.getPodName());
q.setFieldSelector(fieldSelector) ;
q.setLabelSelector(labelSelector);

CompletableFuture<List<Container>> future = collector.collect(q);
future.handle((containers, e) -> {
Expand Down
3 changes: 3 additions & 0 deletions chaosblade-box-web/src/main/resources/application.yml
Expand Up @@ -61,6 +61,9 @@ chaos:
enable: false
type: kube_api
period: 30
search:
fieldSelector:
labelSelector:
prometheus:
api:
metric:
Expand Down

0 comments on commit ec1e7a2

Please sign in to comment.