Skip to content

Commit

Permalink
upgrade prometheus-agent to JDK21 (apache#158)
Browse files Browse the repository at this point in the history
* upgrade monitor to JDK21

* update

* upgrade tspandata to JDK21

* update tspan data workflow

* upgrade prometheus-agent to JDK21

* update prometheus-agent workflow jdk21
  • Loading branch information
jifengzhilong authored and shanwb committed Nov 29, 2023
1 parent 36994ef commit 72f23b4
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 144 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ozhera-prometheus-agent-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
java-version: 8
java-version: 21
#settings-properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'

- run: echo '<settings> <interactiveMode>false</interactiveMode> <profiles> <profile> <repositories> <repository> <snapshots /> <id>ossrh</id> <name>ossrh-snapshot</name> <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <snapshots /> <id>ossrh</id> <name>ossrh-snapshot</name> <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> </pluginRepository> </pluginRepositories> <id>artifactory</id> </profile> </profiles> <activeProfiles> <activeProfile>artifactory</activeProfile> </activeProfiles> <servers> <server> <id>github</id> <username>${env.GITHUB_ACTOR}</username> <password>${env.GITHUB_TOKEN}</password> </server> </servers> <mirrors/> <proxies/></settings>' > ~/.m2/settings.xml

- run: cd ozhera-prometheus-agent; mvn -U clean package --fail-at-end -Dmaven.test.skip=true
- run: cd ozhera-prometheus-agent; mvn -U clean package --fail-at-end -Dmaven.test.skip=true
4 changes: 2 additions & 2 deletions ozhera-monitor/ozhera-monitor-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@

<dependency>
<groupId>run.mone</groupId>
<artifactId>hera-prometheus-agent-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>ozhera-prometheus-agent-api</artifactId>
<version>1.0.0-jdk21-SNAPSHOT</version>
</dependency>


Expand Down
4 changes: 2 additions & 2 deletions ozhera-prometheus-agent/ozhera-prometheus-agent-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>ozhera-prometheus-agent</artifactId>
<groupId>run.mone</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-jdk21-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -18,7 +18,7 @@
<dependency>
<artifactId>ozhera-prometheus-agent-common</artifactId>
<groupId>run.mone</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-jdk21-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>ozhera-prometheus-agent</artifactId>
<groupId>run.mone</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-jdk21-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -16,12 +16,12 @@
<dependency>
<artifactId>ozhera-prometheus-agent-common</artifactId>
<groupId>run.mone</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-jdk21-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>ozhera-prometheus-agent-service</artifactId>
<groupId>run.mone</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-jdk21-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -184,14 +187,19 @@ private Map<String, String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,6 +59,8 @@ public class PrometheusClient implements Client {
public static final Gson gson = new Gson();
private List<Scrape_configs> localConfigs = new ArrayList<>();

private ReentrantLock lock = new ReentrantLock();

@PostConstruct
public void init() {
backFilePath = filePath + ".bak";
Expand Down Expand Up @@ -159,39 +162,49 @@ public void CompareAndReload() {

}

private synchronized ArrayList<Scrape_configs> 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<Scrape_configs> 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<Scrape_configs> promScrapeConfig = prometheusConfig.getScrape_configs();
HashMap<String, Scrape_configs> 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<Scrape_configs> 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<Scrape_configs> promScrapeConfig = prometheusConfig.getScrape_configs();
HashMap<String, Scrape_configs> 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<Scrape_configs> 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) {
Expand Down
18 changes: 9 additions & 9 deletions ozhera-prometheus-agent/ozhera-prometheus-agent-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>ozhera-prometheus-agent</artifactId>
<groupId>run.mone</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-jdk21-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -108,7 +108,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.3.8</version>
<version>5.3.29</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -121,7 +121,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.7.10</version>
<version>2.7.15</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
Expand All @@ -134,7 +134,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.0.RELEASE</version>
<version>2.7.15</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
Expand All @@ -155,31 +155,31 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.0.RELEASE</version>
<version>2.7.15</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.2.0.RELEASE</version>
<version>5.3.29</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.0.RELEASE</version>
<version>5.3.29</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
<version>5.3.29</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.0.RELEASE</version>
<version>5.3.29</version>
</dependency>

<dependency>
Expand Down
Loading

0 comments on commit 72f23b4

Please sign in to comment.