diff --git a/.github/workflows/ozhera-prometheus-agent-package.yml b/.github/workflows/ozhera-prometheus-agent-package.yml index 056e5e3d8..01f8bf2e9 100644 --- a/.github/workflows/ozhera-prometheus-agent-package.yml +++ b/.github/workflows/ozhera-prometheus-agent-package.yml @@ -12,16 +12,16 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - check-build-8: + check-build-21: name: ozhera-prometheus-agent test runs-on: ubuntu-latest steps: - name: Setup Maven Action uses: s4u/setup-maven-action@v1.7.0 with: - java-version: 8 + java-version: 21 #settings-properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]' - run: echo ' false ossrh ossrh-snapshot https://s01.oss.sonatype.org/content/repositories/snapshots ossrh ossrh-snapshot https://s01.oss.sonatype.org/content/repositories/snapshots artifactory artifactory github ${env.GITHUB_ACTOR} ${env.GITHUB_TOKEN} ' > ~/.m2/settings.xml - - run: cd ozhera-prometheus-agent; mvn -U clean package --fail-at-end -Dmaven.test.skip=true \ No newline at end of file + - run: cd ozhera-prometheus-agent; mvn -U clean package --fail-at-end -Dmaven.test.skip=true diff --git a/ozhera-monitor/ozhera-monitor-service/pom.xml b/ozhera-monitor/ozhera-monitor-service/pom.xml index f6356b597..d194aa354 100644 --- a/ozhera-monitor/ozhera-monitor-service/pom.xml +++ b/ozhera-monitor/ozhera-monitor-service/pom.xml @@ -264,8 +264,8 @@ run.mone - hera-prometheus-agent-api - 1.0.0-SNAPSHOT + ozhera-prometheus-agent-api + 1.0.0-jdk21-SNAPSHOT diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-api/pom.xml b/ozhera-prometheus-agent/ozhera-prometheus-agent-api/pom.xml index 7ec10ac6a..d11e505ef 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-api/pom.xml +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-api/pom.xml @@ -6,7 +6,7 @@ ozhera-prometheus-agent run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT 4.0.0 @@ -18,7 +18,7 @@ ozhera-prometheus-agent-common run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-client/pom.xml b/ozhera-prometheus-agent/ozhera-prometheus-agent-client/pom.xml index 1279083e2..826309506 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-client/pom.xml +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-client/pom.xml @@ -6,7 +6,7 @@ ozhera-prometheus-agent run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT 4.0.0 @@ -16,12 +16,12 @@ ozhera-prometheus-agent-common run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT ozhera-prometheus-agent-service run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-client/src/main/java/com/xiaomi/youpin/prometheus/agent/alertManagerClient/AlertManagerClient.java b/ozhera-prometheus-agent/ozhera-prometheus-agent-client/src/main/java/com/xiaomi/youpin/prometheus/agent/alertManagerClient/AlertManagerClient.java index 620252ae1..aa7396d6e 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-client/src/main/java/com/xiaomi/youpin/prometheus/agent/alertManagerClient/AlertManagerClient.java +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-client/src/main/java/com/xiaomi/youpin/prometheus/agent/alertManagerClient/AlertManagerClient.java @@ -24,6 +24,7 @@ import java.util.*; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; import static com.xiaomi.youpin.prometheus.agent.Commons.HTTP_POST; @@ -52,6 +53,8 @@ public class AlertManagerClient implements Client { private static final Gson gson = new Gson(); + private ReentrantLock lock = new ReentrantLock(); + @PostConstruct public void init() { backFilePath = filePath + ".bak"; @@ -184,14 +187,19 @@ private Map transAnnotation2Map(String annotations) { return annotationMap; } - private synchronized AlertManagerConfig getRuleAlertConfig(String path) { - log.info("AlertManagerClient getRuleAlertConfig path : {}", path); - String content = FileUtil.LoadFile(path); - AlertManagerConfig alertManagerConfig = YamlUtil.toObject(content, AlertManagerConfig.class); - log.info("AlertManagerClient config : {}", alertManagerConfig); - //System.out.println(content); - //Convert to AlertManager configuration class. - return alertManagerConfig; + private AlertManagerConfig getRuleAlertConfig(String path) { + lock.lock(); + try { + log.info("AlertManagerClient getRuleAlertConfig path : {}", path); + String content = FileUtil.LoadFile(path); + AlertManagerConfig alertManagerConfig = YamlUtil.toObject(content, AlertManagerConfig.class); + log.info("AlertManagerClient config : {}", alertManagerConfig); + //System.out.println(content); + //Convert to AlertManager configuration class. + return alertManagerConfig; + }finally { + lock.unlock(); + } } private void writeAlertManagerConfig2Yaml(AlertManagerConfig alertManagerConfig) { diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-client/src/main/java/com/xiaomi/youpin/prometheus/agent/prometheusClient/PrometheusClient.java b/ozhera-prometheus-agent/ozhera-prometheus-agent-client/src/main/java/com/xiaomi/youpin/prometheus/agent/prometheusClient/PrometheusClient.java index 00eb02722..2506fc38b 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-client/src/main/java/com/xiaomi/youpin/prometheus/agent/prometheusClient/PrometheusClient.java +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-client/src/main/java/com/xiaomi/youpin/prometheus/agent/prometheusClient/PrometheusClient.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; import static com.xiaomi.youpin.prometheus.agent.Commons.HTTP_GET; import static com.xiaomi.youpin.prometheus.agent.Commons.HTTP_POST; @@ -58,6 +59,8 @@ public class PrometheusClient implements Client { public static final Gson gson = new Gson(); private List localConfigs = new ArrayList<>(); + private ReentrantLock lock = new ReentrantLock(); + @PostConstruct public void init() { backFilePath = filePath + ".bak"; @@ -159,39 +162,49 @@ public void CompareAndReload() { } - private synchronized ArrayList mergeDbAndFileJobs(PrometheusConfig prometheusConfig) { - if (prometheusConfig == null || prometheusConfig.getScrape_configs().size() == 0 || prometheusConfig.getGlobal() == null) { - //If the configuration is faulty, end it directly - log.error("prometheusConfig null and return"); - return null; + private ArrayList mergeDbAndFileJobs(PrometheusConfig prometheusConfig) { + lock.lock(); + try { + if (prometheusConfig == null || prometheusConfig.getScrape_configs().size() == 0 || prometheusConfig.getGlobal() == null) { + //If the configuration is faulty, end it directly + log.error("prometheusConfig null and return"); + return null; + } + //Compare the prometheus data with the data to be reloaded + List promScrapeConfig = prometheusConfig.getScrape_configs(); + HashMap configMap = new HashMap<>(); + promScrapeConfig.forEach(item -> { + configMap.put(item.getJob_name(), item); + }); + //The job in the file will be overwritten by db. db prevails + localConfigs.forEach(item -> { + configMap.put(item.getJob_name(), item); + }); + ArrayList configList = new ArrayList<>(); + configMap.forEach((k, v) -> { + configList.add(v); + }); + log.info("prometheusYMLJobNum: {},dbPEndingJobNum: {} after merge JobNum: {}", promScrapeConfig.size(), + localConfigs.size(), configList.size()); + return configList; + }finally { + lock.unlock(); } - //Compare the prometheus data with the data to be reloaded - List promScrapeConfig = prometheusConfig.getScrape_configs(); - HashMap configMap = new HashMap<>(); - promScrapeConfig.forEach(item -> { - configMap.put(item.getJob_name(), item); - }); - //The job in the file will be overwritten by db. db prevails - localConfigs.forEach(item -> { - configMap.put(item.getJob_name(), item); - }); - ArrayList configList = new ArrayList<>(); - configMap.forEach((k, v) -> { - configList.add(v); - }); - log.info("prometheusYMLJobNum: {},dbPEndingJobNum: {} after merge JobNum: {}", promScrapeConfig.size(), - localConfigs.size(), configList.size()); - return configList; } - private synchronized PrometheusConfig getPrometheusConfig(String path) { - log.info("PrometheusClient getPrometheusConfig path : {}", path); - String content = FileUtil.LoadFile(path); - PrometheusConfig prometheusConfig = YamlUtil.toObject(content, PrometheusConfig.class); - log.info("PrometheusClient config : {}", prometheusConfig); - //System.out.println(content); - // Convert to Prometheus configuration class - return prometheusConfig; + private PrometheusConfig getPrometheusConfig(String path) { + lock.lock(); + try { + log.info("PrometheusClient getPrometheusConfig path : {}", path); + String content = FileUtil.LoadFile(path); + PrometheusConfig prometheusConfig = YamlUtil.toObject(content, PrometheusConfig.class); + log.info("PrometheusClient config : {}", prometheusConfig); + //System.out.println(content); + // Convert to Prometheus configuration class + return prometheusConfig; + }finally { + lock.unlock(); + } } private void writePrometheusConfig2Yaml(PrometheusConfig prometheusConfig) { diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-common/pom.xml b/ozhera-prometheus-agent/ozhera-prometheus-agent-common/pom.xml index b5f295e0f..89effceb7 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-common/pom.xml +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-common/pom.xml @@ -6,7 +6,7 @@ ozhera-prometheus-agent run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT 4.0.0 @@ -108,7 +108,7 @@ org.springframework spring-beans - 5.3.8 + 5.3.29 compile @@ -121,7 +121,7 @@ org.springframework.boot spring-boot-starter-test - 2.7.10 + 2.7.15 org.springframework.boot @@ -134,7 +134,7 @@ org.springframework.boot spring-boot-starter-web - 2.2.0.RELEASE + 2.7.15 org.springframework @@ -155,31 +155,31 @@ org.springframework.boot spring-boot-starter-test - 2.2.0.RELEASE + 2.7.15 org.springframework spring-beans - 5.2.0.RELEASE + 5.3.29 org.springframework spring-core - 5.2.0.RELEASE + 5.3.29 org.springframework spring-context - 5.2.0.RELEASE + 5.3.29 org.springframework spring-test - 5.2.0.RELEASE + 5.3.29 diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-common/src/main/java/com/xiaomi/youpin/prometheus/agent/util/FileUtil.java b/ozhera-prometheus-agent/ozhera-prometheus-agent-common/src/main/java/com/xiaomi/youpin/prometheus/agent/util/FileUtil.java index a8af06972..2f485ef5d 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-common/src/main/java/com/xiaomi/youpin/prometheus/agent/util/FileUtil.java +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-common/src/main/java/com/xiaomi/youpin/prometheus/agent/util/FileUtil.java @@ -6,34 +6,48 @@ import org.apache.commons.io.FileUtils; import java.io.File; +import java.util.concurrent.locks.ReentrantLock; @Slf4j public class FileUtil { + + private static ReentrantLock lock = new ReentrantLock(); + @SneakyThrows - public static synchronized String LoadFile(String path) { - log.info("FileUtil LoadFile path: {}", path); - File file = new File(path); - if (!file.exists() || !isCanReadFile(file)) { - //Unreadable, non-existent, then exit. - return ""; + public static String LoadFile(String path) { + lock.lock(); + try { + log.info("FileUtil LoadFile path: {}", path); + File file = new File(path); + if (!file.exists() || !isCanReadFile(file)) { + //Unreadable, non-existent, then exit. + return ""; + } + String content = FileUtils.readFileToString(file, "UTF-8"); + return content; + }finally { + lock.unlock(); } - String content = FileUtils.readFileToString(file, "UTF-8"); - return content; } @SneakyThrows - public static synchronized String WriteFile(String path, String content) { - log.info("FileUtil WriteFile path: {}", path); - File file = new File(path); - if (!file.exists() || !isCanWriteFile(file)) { - //Does not exist, cannot be written, then exit. - return ""; + public static String WriteFile(String path, String content) { + lock.lock(); + try { + log.info("FileUtil WriteFile path: {}", path); + File file = new File(path); + if (!file.exists() || !isCanWriteFile(file)) { + //Does not exist, cannot be written, then exit. + return ""; + } + if (path.equals("/usr/local/etc/prometheus.yml")) { + log.info("checkNullFile path: {},content: {}", path, content); + } + FileUtils.write(file, content); + return "success"; + }finally { + lock.unlock(); } - if (path.equals("/usr/local/etc/prometheus.yml")) { - log.info("checkNullFile path: {},content: {}", path, content); - } - FileUtils.write(file, content); - return "success"; } //Check file existence @@ -46,11 +60,16 @@ public static boolean IsHaveFile(String path) { //Delete file. @SneakyThrows - public static synchronized boolean DeleteFile(String path) { - log.info("FileUtil DeleteFile path: {}", path); - File file = new File(path); - boolean delete = file.delete(); - return delete; + public static boolean DeleteFile(String path) { + lock.lock(); + try { + log.info("FileUtil DeleteFile path: {}", path); + File file = new File(path); + boolean delete = file.delete(); + return delete; + }finally { + lock.unlock(); + } } //Check the readability of the document. @@ -71,22 +90,32 @@ private static boolean isCanWriteFile(File file) { //Rename file @SneakyThrows - public static synchronized boolean RenameFile(String oldPath, String newPath) { - log.info("FileUtil RenameFile oldPath: {},newPath: {}", oldPath, newPath); - File file = new File(oldPath); - if (!file.exists()) { - return false; + public static boolean RenameFile(String oldPath, String newPath) { + lock.lock(); + try { + log.info("FileUtil RenameFile oldPath: {},newPath: {}", oldPath, newPath); + File file = new File(oldPath); + if (!file.exists()) { + return false; + } + boolean res = file.renameTo(new File(newPath)); + return res; + }finally { + lock.unlock(); } - boolean res = file.renameTo(new File(newPath)); - return res; } @SneakyThrows - public static synchronized void GenerateFile(String path) { - log.info("FileUtil GenerateFile path: {}", path); - File file = new File(path); - if (!file.exists()) { - file.createNewFile(); + public static void GenerateFile(String path) { + lock.lock(); + try { + log.info("FileUtil GenerateFile path: {}", path); + File file = new File(path); + if (!file.exists()) { + file.createNewFile(); + } + }finally { + lock.unlock(); } } diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-common/src/main/java/com/xiaomi/youpin/prometheus/agent/util/YamlUtil.java b/ozhera-prometheus-agent/ozhera-prometheus-agent-common/src/main/java/com/xiaomi/youpin/prometheus/agent/util/YamlUtil.java index ee0138d9a..cf9e2be11 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-common/src/main/java/com/xiaomi/youpin/prometheus/agent/util/YamlUtil.java +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-common/src/main/java/com/xiaomi/youpin/prometheus/agent/util/YamlUtil.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.StringWriter; +import java.util.concurrent.locks.ReentrantLock; @Slf4j public class YamlUtil { @@ -23,16 +24,22 @@ public class YamlUtil { public static Object obj = new Object(); - public static synchronized T toObject(String yamlStr, Class clazz) { - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - mapper.findAndRegisterModules(); + private static ReentrantLock lock = new ReentrantLock(); + + public static T toObject(String yamlStr, Class clazz) { + lock.lock(); try { - return mapper.readValue(yamlStr, clazz); - } catch (JsonProcessingException e) { - log.error(e.getMessage(), e); + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + mapper.findAndRegisterModules(); + try { + return mapper.readValue(yamlStr, clazz); + } catch (JsonProcessingException e) { + log.error(e.getMessage(), e); + } + return null; + }finally { + lock.unlock(); } - return null; - } /** @@ -41,19 +48,24 @@ public static synchronized T toObject(String yamlStr, Class clazz) { * @param object Object * @return YAML string */ - public static synchronized String toYaml(Object object) { - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - mapper.findAndRegisterModules(); - mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)); - StringWriter stringWriter = new StringWriter(); + public static String toYaml(Object object) { + lock.lock(); try { - mapper.writeValue(stringWriter, object); - return stringWriter.toString(); - } catch (IOException e) { - e.printStackTrace(); + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + mapper.findAndRegisterModules(); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)); + StringWriter stringWriter = new StringWriter(); + try { + mapper.writeValue(stringWriter, object); + return stringWriter.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + }finally { + lock.unlock(); } - return null; } } diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-dao/pom.xml b/ozhera-prometheus-agent/ozhera-prometheus-agent-dao/pom.xml index 11b75b9d8..46eb27383 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-dao/pom.xml +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-dao/pom.xml @@ -6,7 +6,7 @@ ozhera-prometheus-agent run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT 4.0.0 @@ -16,7 +16,7 @@ ozhera-prometheus-agent-common run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT run.mone @@ -34,7 +34,7 @@ org.springframework.boot spring-boot-starter-jdbc - 2.2.0.RELEASE + 2.7.15 diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-server/Dockerfile b/ozhera-prometheus-agent/ozhera-prometheus-agent-server/Dockerfile new file mode 100644 index 000000000..0710cea5e --- /dev/null +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-server/Dockerfile @@ -0,0 +1,6 @@ +FROM openjdk:21-jdk-bookworm +MAINTAINER youpin-biz-arch@xiaomi.com +RUN mkdir -p /home/work/prometheus-agent/ +RUN mkdir -p /home/work/log/prometheus-agent/ +COPY ./target/ozhera-prometheus-agent-server-1.0.0-jdk21-SNAPSHOT.jar /home/work/prometheus-agent/ +ENTRYPOINT ["sh","-c","java -Xms512M -Xmx512M -XX:+UseZGC --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/sun.reflect=ALL-UNNAMED --add-opens java.base/java.xml=ALL-UNNAMED --add-exports java.base/sun.reflect.annotation=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-exports java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED -Duser.timezone=Asia/Shanghai -jar /home/work/prometheus-agent/ozhera-prometheus-agent-server-1.0.0-jdk21-SNAPSHOT.jar"] \ No newline at end of file diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-server/pom.xml b/ozhera-prometheus-agent/ozhera-prometheus-agent-server/pom.xml index e1aefdaeb..7d9d609d7 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-server/pom.xml +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-server/pom.xml @@ -5,7 +5,7 @@ ozhera-prometheus-agent run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT 4.0.0 ozhera-prometheus-agent-server @@ -16,7 +16,7 @@ ozhera-prometheus-agent-client run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-service/pom.xml b/ozhera-prometheus-agent/ozhera-prometheus-agent-service/pom.xml index e4a641a46..ea9c9f6d0 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-service/pom.xml +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-service/pom.xml @@ -5,7 +5,7 @@ ozhera-prometheus-agent run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT 4.0.0 @@ -17,13 +17,13 @@ org.springframework spring-jdbc - 5.2.0.RELEASE + 5.3.29 ozhera-prometheus-agent-api run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT commons-codec @@ -35,7 +35,7 @@ ozhera-prometheus-agent-common run.mone - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT @@ -62,7 +62,7 @@ run.mone ozhera-prometheus-agent-dao - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT run.mone diff --git a/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/impl/PrometheusIpServiceImpl.java b/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/impl/PrometheusIpServiceImpl.java index e542a5b7e..767f90b98 100644 --- a/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/impl/PrometheusIpServiceImpl.java +++ b/ozhera-prometheus-agent/ozhera-prometheus-agent-service/src/main/java/com/xiaomi/youpin/prometheus/agent/service/impl/PrometheusIpServiceImpl.java @@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; @Slf4j @Service @@ -77,6 +78,8 @@ public class PrometheusIpServiceImpl implements PrometheusIpServiceExtension { @NacosValue(value = "${jaeger_query_token}") private String jaegerQueryToken; + private ReentrantLock lock = new ReentrantLock(); + @PostConstruct public void init() { new ScheduledThreadPoolExecutor(1).scheduleWithFixedDelay(() -> { @@ -345,12 +348,15 @@ private String innerRequest(String data, String url, String apiKey, String metho } } - private synchronized ApiClient getClient() { + private ApiClient getClient() { + lock.lock(); try { return Config.defaultClient(); } catch (IOException e) { log.error("getClient error : {}",e.getMessage()); return null; + } finally { + lock.unlock(); } } diff --git a/ozhera-prometheus-agent/pom.xml b/ozhera-prometheus-agent/pom.xml index fbaed51d6..cb6e877af 100644 --- a/ozhera-prometheus-agent/pom.xml +++ b/ozhera-prometheus-agent/pom.xml @@ -6,7 +6,7 @@ 4.0.0 run.mone ozhera-prometheus-agent - 1.0.0-SNAPSHOT + 1.0.0-jdk21-SNAPSHOT pom @@ -23,7 +23,7 @@ org.projectlombok lombok - 1.18.24 + 1.18.30 @@ -58,6 +58,12 @@ 1.4-SNAPSHOT + + org.aspectj + aspectjweaver + 1.9.7 + + @@ -72,18 +78,11 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.11.0 - 1.8 - 1.8 - true - true - UTF-8 - - - ${project.basedir}/src/main/java - - + 21 + 21 + 21 @@ -173,16 +172,14 @@ - - central - maven-release-virtual - https://pkgs.d.xiaomi.net/artifactory/maven-release-virtual - - snapshots - maven-snapshot-virtual - https://pkgs.d.xiaomi.net/artifactory/maven-snapshot-virtual + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ +