Skip to content

Commit 29cc848

Browse files
committed
[pinpoint-apm#10776] Add open telemetry metric
1 parent 79cc88f commit 29cc848

File tree

82 files changed

+4548
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4548
-6
lines changed

agent-module/agent/src/main/resources/profiles/local/pinpoint.config

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,4 +1430,13 @@ profiler.kotlin.coroutines.record.cancel=false
14301430
###########################################################
14311431
profiler.resilience4j.enable=true
14321432
profiler.resilience4j.trace.circuit-breaker=true
1433-
profiler.resilience4j.mark.error.circuit-breaker=false
1433+
profiler.resilience4j.mark.error.circuit-breaker=false
1434+
1435+
###########################################################
1436+
# Open telemetry metrics
1437+
###########################################################
1438+
profiler.micrometer.otlp.enabled=true
1439+
profiler.micrometer.otlp.url=http://127.0.0.1:15200/opentelemetry
1440+
profiler.micrometer.otlp.step=30s
1441+
profiler.micrometer.otlp.batchSize=10000
1442+

agent-module/agent/src/main/resources/profiles/release/pinpoint.config

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,4 +1453,12 @@ profiler.kotlin.coroutines.record.cancel=false
14531453
###########################################################
14541454
profiler.resilience4j.enable=true
14551455
profiler.resilience4j.trace.circuit-breaker=true
1456-
profiler.resilience4j.mark.error.circuit-breaker=false
1456+
profiler.resilience4j.mark.error.circuit-breaker=false
1457+
1458+
###########################################################
1459+
# Open telemetry metrics
1460+
###########################################################
1461+
profiler.micrometer.otlp.enabled=true
1462+
profiler.micrometer.otlp.url=http://127.0.0.1:15200/opentelemetry
1463+
profiler.micrometer.otlp.step=30s
1464+
profiler.micrometer.otlp.batchSize=10000

agent-module/profiler/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,15 @@
167167
</exclusion>
168168
</exclusions>
169169
</dependency>-->
170-
171170
<dependency>
172171
<groupId>org.mapstruct</groupId>
173172
<artifactId>mapstruct</artifactId>
174173
</dependency>
174+
<dependency>
175+
<groupId>io.micrometer</groupId>
176+
<artifactId>micrometer-registry-otlp</artifactId>
177+
<version>1.9.2</version>
178+
</dependency>
175179
</dependencies>
176180

177181
<build>

agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/config/DefaultMonitorConfig.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.navercorp.pinpoint.profiler.context.monitor.config;
1818

1919
import com.navercorp.pinpoint.common.config.Value;
20-
20+
import com.navercorp.pinpoint.common.util.StringUtils;
2121
public class DefaultMonitorConfig implements MonitorConfig {
2222

2323
public static final int DEFAULT_AGENT_STAT_COLLECTION_INTERVAL_MS = 5 * 1000;
@@ -49,6 +49,50 @@ public class DefaultMonitorConfig implements MonitorConfig {
4949
@Value("${profiler.jvm.stat.collect.detailed.metrics}")
5050
private boolean profilerJvmStatCollectDetailedMetrics = false;
5151

52+
@Value("${profiler.micrometer.otlp.enabled}")
53+
private boolean micrometerEnable = false;
54+
55+
@Value("${profiler.micrometer.otlp.url}")
56+
private String micrometerUrl;
57+
58+
@Value("${profiler.micrometer.otlp.step}")
59+
private String micrometerStep;
60+
61+
@Value("${profiler.micrometer.otlp.batchSize}")
62+
private String micrometerBatchSize;
63+
64+
@Value("${pinpoint.applicationName}")
65+
private String applicationName;
66+
67+
@Value("${pinpoint.agentId}")
68+
private String agentId;
69+
70+
public DefaultMonitorConfig() {
71+
if (StringUtils.isEmpty(agentId)) {
72+
agentId = System.getProperty("pinpoint.agentId");
73+
}
74+
if (StringUtils.isEmpty(applicationName)) {
75+
applicationName = System.getProperty("pinpoint.applicationName");
76+
}
77+
}
78+
79+
@Override
80+
public boolean isMicrometerEnable() { return micrometerEnable; }
81+
82+
@Override
83+
public String getMicrometerUrl() { return micrometerUrl; }
84+
85+
@Override
86+
public String getMicrometerStep() { return micrometerStep; }
87+
88+
@Override
89+
public String getMicrometerBatchSize() { return micrometerBatchSize; }
90+
91+
@Override
92+
public String getApplicationName() { return applicationName; }
93+
94+
public String getAgentId() { return agentId;}
95+
5296
@Override
5397
public int getProfileJvmStatCollectIntervalMs() {
5498
return profileJvmStatCollectIntervalMs;
@@ -118,6 +162,12 @@ public String toString() {
118162
", profileJvmStatCollectIntervalMs=" + profileJvmStatCollectIntervalMs +
119163
", profileJvmStatBatchSendCount=" + profileJvmStatBatchSendCount +
120164
", profilerJvmStatCollectDetailedMetrics=" + profilerJvmStatCollectDetailedMetrics +
165+
", micrometerEnable=" + micrometerEnable +
166+
", micrometerUrl=" + micrometerUrl +
167+
", micrometerStep=" + micrometerStep +
168+
", micrometerBatchSize=" + micrometerBatchSize +
169+
", micrometerHostName=" + agentId +
170+
", micrometerHostGroupName=" + applicationName +
121171
'}';
122172
}
123173
}

agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/config/MonitorConfig.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,16 @@ public interface MonitorConfig {
3939

4040
int getCompletedUriStatDataLimitSize();
4141

42+
boolean isMicrometerEnable();
43+
44+
String getMicrometerUrl();
45+
46+
String getMicrometerStep();
47+
48+
String getMicrometerBatchSize();
49+
50+
String getApplicationName();
51+
52+
String getAgentId();
53+
4254
}

agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/DefaultAgentStatMonitor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector;
3434
import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot;
3535
import com.navercorp.pinpoint.profiler.monitor.metric.MetricType;
36+
import com.navercorp.pinpoint.profiler.monitor.micrometer.MicrometerCollectingJob;
3637
import org.apache.logging.log4j.LogManager;
3738
import org.apache.logging.log4j.Logger;
3839

@@ -105,6 +106,11 @@ public DefaultAgentStatMonitor(@StatDataSender DataSender<MetricType> dataSender
105106
runnableList.add(uriStatCollectingJob);
106107
}
107108

109+
if (monitorConfig.isMicrometerEnable()) {
110+
new MicrometerCollectingJob(monitorConfig.getMicrometerUrl(), monitorConfig.getMicrometerStep(),
111+
monitorConfig.getMicrometerBatchSize(), monitorConfig.getApplicationName(), monitorConfig.getAgentId());
112+
}
113+
108114
this.statMonitorJob = new StatMonitorJob(runnableList);
109115

110116
preLoadClass(agentId, agentStartTimestamp, agentStatCollector);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2017 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.navercorp.pinpoint.profiler.monitor.micrometer;
18+
19+
import io.micrometer.core.instrument.Clock;
20+
import io.micrometer.core.instrument.binder.jvm.*;
21+
import io.micrometer.core.instrument.binder.system.DiskSpaceMetrics;
22+
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
23+
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
24+
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
25+
import io.micrometer.registry.otlp.OtlpConfig;
26+
import io.micrometer.registry.otlp.OtlpMeterRegistry;
27+
import org.apache.logging.log4j.LogManager;
28+
import org.apache.logging.log4j.Logger;
29+
30+
import java.io.File;
31+
import java.util.Properties;
32+
33+
public class MicrometerCollectingJob {
34+
35+
private final Logger logger = LogManager.getLogger(this.getClass());
36+
37+
private final OtlpMeterRegistry meterRegistry;
38+
39+
public MicrometerCollectingJob(String micrometerUrl, String micrometerStep, String micrometerBatchSize, String applicationName, String agentId) {
40+
this.meterRegistry = new OtlpMeterRegistry(getOtlpConfig(micrometerUrl, micrometerStep, micrometerBatchSize, "", applicationName, agentId), Clock.SYSTEM);
41+
bindMetrics();
42+
}
43+
44+
private void bindMetrics() {
45+
// jvm
46+
new ClassLoaderMetrics().bindTo(meterRegistry);
47+
new JvmCompilationMetrics().bindTo(meterRegistry);
48+
new JvmGcMetrics().bindTo(meterRegistry);
49+
new JvmHeapPressureMetrics().bindTo(meterRegistry);
50+
new JvmInfoMetrics().bindTo(meterRegistry);
51+
new JvmMemoryMetrics().bindTo(meterRegistry);
52+
new JvmThreadMetrics().bindTo(meterRegistry);
53+
54+
// system
55+
new DiskSpaceMetrics(new File("/")).bindTo(meterRegistry); // add other paths with user input?
56+
new FileDescriptorMetrics().bindTo(meterRegistry);
57+
new ProcessorMetrics().bindTo(meterRegistry);
58+
new UptimeMetrics().bindTo(meterRegistry);
59+
}
60+
61+
private OtlpConfig getOtlpConfig(String micrometerUrl, String micrometerStep, String micrometerBatchSize,
62+
String serviceName, String applicationName, String agentId) {
63+
Properties propertiesConfig = new Properties();
64+
propertiesConfig.put("otlp.url", micrometerUrl);
65+
propertiesConfig.put("otlp.step", String.valueOf(micrometerStep));
66+
propertiesConfig.put("otlp.batchSize", String.valueOf(micrometerBatchSize));
67+
propertiesConfig.put("otlp.resourceAttributes", "service.namespace=" + serviceName + ",service.name=" + applicationName + ",pinpoint.agentId=" + agentId);
68+
OtlpConfig otlpConfig = (key -> (String) propertiesConfig.get(key));
69+
return otlpConfig;
70+
}
71+
}

collector-starter/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
<groupId>com.navercorp.pinpoint</groupId>
6969
<artifactId>pinpoint-exceptiontrace-collector</artifactId>
7070
</dependency>
71+
<dependency>
72+
<groupId>com.navercorp.pinpoint</groupId>
73+
<artifactId>pinpoint-otlpmetric-collector</artifactId>
74+
</dependency>
7175
</dependencies>
7276

7377
<build>

collector-starter/src/main/java/com/navercorp/pinpoint/collector/starter/multi/application/PinpointCollectorStarter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.navercorp.pinpoint.inspector.collector.InspectorCollectorConfig;
1818
import com.navercorp.pinpoint.log.collector.LogCollectorModule;
1919
import com.navercorp.pinpoint.metric.collector.MetricCollectorApp;
20+
import com.navercorp.pinpoint.otlp.collector.OtlpMetricCollectorConfig;
2021
import com.navercorp.pinpoint.redis.RedisPropertySources;
2122
import com.navercorp.pinpoint.uristat.collector.UriStatCollectorConfig;
2223
import org.springframework.boot.Banner;
@@ -79,7 +80,9 @@ public static void main(String[] args) {
7980

8081
if (types.hasType(CollectorType.METRIC)) {
8182
logger.info(String.format("Start %s collector", CollectorType.METRIC));
82-
SpringApplicationBuilder metricAppBuilder = createAppBuilder(builder, 15200, MetricCollectorApp.class);
83+
SpringApplicationBuilder metricAppBuilder = createAppBuilder(builder, 15200,
84+
MetricCollectorApp.class,
85+
OtlpMetricCollectorConfig.class);
8386
metricAppBuilder.listeners(new AdditionalProfileListener("metric"));
8487
metricAppBuilder.build().run(args);
8588
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.navercorp.pinpoint.collector.service;
2+
3+
import jakarta.validation.Valid;
4+
5+
public interface OtlpMetricService {
6+
void save(@Valid Object data);
7+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.navercorp.pinpoint</groupId>
8+
<artifactId>pinpoint-otlpmetric</artifactId>
9+
<version>3.0.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>pinpoint-otlpmetric-collector</artifactId>
13+
<properties>
14+
<jdk.version>17</jdk.version>
15+
<jdk.home>${env.JAVA_17_HOME}</jdk.home>
16+
</properties>
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-context</artifactId>
21+
<version>6.0.13</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.navercorp.pinpoint</groupId>
25+
<artifactId>pinpoint-pinot-config</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.navercorp.pinpoint</groupId>
29+
<artifactId>pinpoint-pinot-kafka</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.opentelemetry.proto</groupId>
33+
<artifactId>opentelemetry-proto</artifactId>
34+
<version>0.19.0-alpha</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework</groupId>
38+
<artifactId>spring-web</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>jakarta.validation</groupId>
42+
<artifactId>jakarta.validation-api</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.navercorp.pinpoint</groupId>
46+
<artifactId>pinpoint-commons-server</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework</groupId>
50+
<artifactId>spring-webmvc</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>com.navercorp.pinpoint</groupId>
54+
<artifactId>pinpoint-otlpmetric-common</artifactId>
55+
</dependency>
56+
</dependencies>
57+
58+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.navercorp.pinpoint.otlp.collector;
18+
19+
import com.navercorp.pinpoint.pinot.config.PinotConfiguration;
20+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
21+
import org.springframework.context.annotation.ComponentScan;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.context.annotation.Import;
24+
import org.springframework.context.annotation.PropertySource;
25+
26+
@Configuration
27+
@Import({
28+
WebMvcConfig.class,
29+
PinotConfiguration.class,
30+
OtlpMetricKafkaConfiguration.class})
31+
@ComponentScan({
32+
"com.navercorp.pinpoint.otlp.collector.controller",
33+
"com.navercorp.pinpoint.otlp.collector.dao",
34+
"com.navercorp.pinpoint.otlp.collector.service",
35+
"com.navercorp.pinpoint.otlp.collector.mapper",
36+
})
37+
@PropertySource({OtlpMetricCollectorConfig.KAFKA_TOPIC_PROPERTIES})
38+
@ConditionalOnProperty(name = "pinpoint.modules.collector.otlpmetric.enabled", havingValue = "true")
39+
public class OtlpMetricCollectorConfig {
40+
public static final String KAFKA_TOPIC_PROPERTIES = "classpath:profiles/${pinpoint.profiles.active}/kafka-topic-otlpmetric.properties";
41+
}

0 commit comments

Comments
 (0)