diff --git a/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/model/dto/OpenmetricsScraperDTO.java b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/model/dto/OpenmetricsScraperDTO.java index dba9fedd2..b45489921 100644 --- a/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/model/dto/OpenmetricsScraperDTO.java +++ b/server/home/home-dal/src/main/java/io/holoinsight/server/home/dal/model/dto/OpenmetricsScraperDTO.java @@ -3,9 +3,11 @@ */ package io.holoinsight.server.home.dal.model.dto; -import lombok.Data; - import java.util.Date; +import java.util.List; + +import io.holoinsight.server.registry.model.OpenmetricsScraperTask; +import lombok.Data; @Data public class OpenmetricsScraperDTO { @@ -19,7 +21,8 @@ public class OpenmetricsScraperDTO { private String port; private String scrapeInterval; private String scrapeTimeout; - + private List relabelConfigs; + private List metricRelabelConfigs; private CloudMonitorRange collectRanges; @@ -42,5 +45,4 @@ public class OpenmetricsScraperDTO { * 修改者 */ private String modifier; - } diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/OpenmetricsScraperUpdateListener.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/OpenmetricsScraperUpdateListener.java index a2dfacdca..381df7399 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/OpenmetricsScraperUpdateListener.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/OpenmetricsScraperUpdateListener.java @@ -47,6 +47,8 @@ private void upsert(OpenmetricsScraperDTO openmetricsScraperDTO) { task.setScrapeInterval(openmetricsScraperDTO.getScrapeInterval()); task.setScrapeTimeout(openmetricsScraperDTO.getScrapeTimeout()); task.setScrapePort(openmetricsScraperDTO.getPort()); + task.setRelabelConfigs(openmetricsScraperDTO.getRelabelConfigs()); + task.setRelabelConfigs(openmetricsScraperDTO.getMetricRelabelConfigs()); // List targets = new ArrayList<>(); //// 暂时 mock 一下 diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/OpenmetricsScraperServiceImpl.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/OpenmetricsScraperServiceImpl.java index 1f4819f4d..e77e92d5a 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/OpenmetricsScraperServiceImpl.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/service/impl/OpenmetricsScraperServiceImpl.java @@ -3,6 +3,22 @@ */ package io.holoinsight.server.home.biz.service.impl; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.gson.reflect.TypeToken; + +import io.holoinsight.server.common.J; import io.holoinsight.server.home.biz.service.OpenmetricsScraperService; import io.holoinsight.server.home.common.util.EventBusHolder; import io.holoinsight.server.home.common.util.StringUtil; @@ -13,23 +29,15 @@ import io.holoinsight.server.home.dal.model.dto.OpenmetricsScraperDTO; import io.holoinsight.server.home.facade.page.MonitorPageRequest; import io.holoinsight.server.home.facade.page.MonitorPageResult; -import io.holoinsight.server.common.J; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.google.gson.reflect.TypeToken; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import io.holoinsight.server.registry.model.OpenmetricsScraperTask; @Service public class OpenmetricsScraperServiceImpl extends ServiceImpl implements OpenmetricsScraperService { + private static final Type RELABEL_CONFIG_LIST_TYPE = + new TypeToken>() {}.getType(); + @Autowired private OpenmetricsScraperConverter openmetricsScraperConverter; @@ -70,18 +78,25 @@ public void deleteById(Long id) { @Override public OpenmetricsScraperDTO toDTO(OpenmetricsScraper model) { - if (model.getConf() == null) { - model.setConf(new HashMap<>()); + Map conf = model.getConf(); + if (conf == null) { + conf = new HashMap<>(); + model.setConf(conf); } OpenmetricsScraperDTO dto = openmetricsScraperConverter.doToDTO(model); - dto.setMetricsPath(model.getConf().get("metricsPath")); - dto.setSchema(model.getConf().get("schema")); - dto.setScrapeInterval(model.getConf().get("scrapeInterval")); - dto.setScrapeTimeout(model.getConf().get("scrapeTimeout")); - dto.setPort(model.getConf().get("port")); - dto.setCollectRanges(J.fromJson(model.getConf().get("collectRanges"), - (new TypeToken() {}).getType())); + dto.setMetricsPath(conf.get("metricsPath")); + dto.setSchema(conf.get("schema")); + dto.setScrapeInterval(conf.get("scrapeInterval")); + dto.setScrapeTimeout(conf.get("scrapeTimeout")); + dto.setPort(conf.get("port")); + + dto.setRelabelConfigs(J.fromJson(conf.get("relabelConfigs"), RELABEL_CONFIG_LIST_TYPE)); + dto.setMetricRelabelConfigs( + J.fromJson(conf.get("metricRelabelConfigs"), RELABEL_CONFIG_LIST_TYPE)); + + dto.setCollectRanges( + J.fromJson(conf.get("collectRanges"), (new TypeToken() {}).getType())); return dto; } @@ -97,6 +112,8 @@ public OpenmetricsScraper toDO(OpenmetricsScraperDTO dto) { model.getConf().put("scrapeTimeout", dto.getScrapeTimeout()); model.getConf().put("port", dto.getPort()); model.getConf().put("collectRanges", J.toJson(dto.getCollectRanges())); + model.getConf().put("relabelConfigs", J.toJson(dto.getRelabelConfigs())); + model.getConf().put("metricRelabelConfigs", J.toJson(dto.getMetricRelabelConfigs())); return model; } diff --git a/server/registry/registry-model/src/main/java/io/holoinsight/server/registry/model/OpenmetricsScraperTask.java b/server/registry/registry-model/src/main/java/io/holoinsight/server/registry/model/OpenmetricsScraperTask.java index f45507170..b7f9e094a 100644 --- a/server/registry/registry-model/src/main/java/io/holoinsight/server/registry/model/OpenmetricsScraperTask.java +++ b/server/registry/registry-model/src/main/java/io/holoinsight/server/registry/model/OpenmetricsScraperTask.java @@ -3,14 +3,15 @@ */ package io.holoinsight.server.registry.model; +import java.util.List; +import java.util.Map; + import io.holoinsight.server.registry.model.integration.GaeaTask; +import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import java.util.List; -import java.util.Map; - @ToString @Getter @Setter @@ -25,5 +26,19 @@ public class OpenmetricsScraperTask extends GaeaTask { private Map labels; private Boolean honorLabels; private Boolean honorTimestamps; + private List relabelConfigs; + private List metricRelabelConfigs; + /** + * Prometheus relabel config + */ + @Data + public static class RelabelConfig { + private List sourceLabels; + private String targetLabel; + private String action; + private String separator; + private String replacement; + private String regex; + } }