Skip to content

Commit 015b6e9

Browse files
authored
[ISSUE #4963] Updating version of pinpoint libraries to 3.0.0 (#5010)
* Upgrading version of pinpoint-profiler to 3.0 Signed-off-by: lmnewton <[email protected]> * Fixing issues with how transaction IDs are being passed, added test to test that parent context is being propagated. * Addressing checkstyle violations. Signed-off-by: Lindsay Newton <[email protected]> * Fixing import ordering issue for checkstyle. Signed-off-by: Lindsay Newton <[email protected]> --------- Signed-off-by: lmnewton <[email protected]> Signed-off-by: Lindsay Newton <[email protected]>
1 parent 3436e56 commit 015b6e9

File tree

3 files changed

+188
-56
lines changed

3 files changed

+188
-56
lines changed

Diff for: eventmesh-trace-plugin/eventmesh-trace-pinpoint/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
def pinpointVersion = "2.4.1"
18+
def pinpointVersion = "3.0.0"
1919

2020
dependencies {
2121
implementation project(":eventmesh-trace-plugin:eventmesh-trace-api")

Diff for: eventmesh-trace-plugin/eventmesh-trace-pinpoint/src/main/java/org/apache/eventmesh/trace/pinpoint/exporter/PinpointSpanExporter.java

+93-50
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import java.util.logging.Logger;
4141
import java.util.stream.Collectors;
4242

43+
import org.mapstruct.factory.Mappers;
44+
4345
import io.grpc.NameResolverProvider;
4446
import io.opentelemetry.api.common.Attributes;
4547
import io.opentelemetry.api.internal.OtelEncodingUtils;
@@ -55,6 +57,7 @@
5557

5658
import com.navercorp.pinpoint.bootstrap.context.SpanId;
5759
import com.navercorp.pinpoint.bootstrap.context.TraceId;
60+
import com.navercorp.pinpoint.common.profiler.util.TransactionIdUtils;
5861
import com.navercorp.pinpoint.common.trace.AnnotationKey;
5962
import com.navercorp.pinpoint.common.trace.ServiceType;
6063
import com.navercorp.pinpoint.common.util.JvmUtils;
@@ -67,6 +70,7 @@
6770
import com.navercorp.pinpoint.profiler.AgentInfoSender;
6871
import com.navercorp.pinpoint.profiler.JvmInformation;
6972
import com.navercorp.pinpoint.profiler.context.DefaultServerMetaDataRegistryService;
73+
import com.navercorp.pinpoint.profiler.context.DefaultSpanFactory;
7074
import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService;
7175
import com.navercorp.pinpoint.profiler.context.Span;
7276
import com.navercorp.pinpoint.profiler.context.SpanEvent;
@@ -75,12 +79,24 @@
7579
import com.navercorp.pinpoint.profiler.context.grpc.GrpcAgentInfoMessageConverter;
7680
import com.navercorp.pinpoint.profiler.context.grpc.GrpcSpanMessageConverter;
7781
import com.navercorp.pinpoint.profiler.context.grpc.config.GrpcTransportConfig;
78-
import com.navercorp.pinpoint.profiler.context.id.DefaultTraceId;
79-
import com.navercorp.pinpoint.profiler.context.id.DefaultTraceRoot;
82+
import com.navercorp.pinpoint.profiler.context.grpc.config.SpanAutoUriGetter;
83+
import com.navercorp.pinpoint.profiler.context.grpc.config.SpanUriGetter;
84+
import com.navercorp.pinpoint.profiler.context.grpc.mapper.AgentInfoMapper;
85+
import com.navercorp.pinpoint.profiler.context.grpc.mapper.AgentInfoMapperImpl;
86+
import com.navercorp.pinpoint.profiler.context.grpc.mapper.AnnotationValueMapper;
87+
import com.navercorp.pinpoint.profiler.context.grpc.mapper.JvmGcTypeMapper;
88+
import com.navercorp.pinpoint.profiler.context.grpc.mapper.JvmGcTypeMapperImpl;
89+
import com.navercorp.pinpoint.profiler.context.grpc.mapper.SpanMessageMapper;
90+
import com.navercorp.pinpoint.profiler.context.grpc.mapper.SpanMessageMapperImpl;
91+
import com.navercorp.pinpoint.profiler.context.id.DefaultTraceIdFactory;
92+
import com.navercorp.pinpoint.profiler.context.id.DefaultTraceRootFactory;
93+
import com.navercorp.pinpoint.profiler.context.id.TraceIdFactory;
8094
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;
95+
import com.navercorp.pinpoint.profiler.context.id.TraceRootFactory;
8196
import com.navercorp.pinpoint.profiler.context.provider.AgentInformationProvider;
8297
import com.navercorp.pinpoint.profiler.context.provider.grpc.DnsExecutorServiceProvider;
8398
import com.navercorp.pinpoint.profiler.context.provider.grpc.GrpcNameResolverProvider;
99+
import com.navercorp.pinpoint.profiler.context.provider.grpc.SSLContextProvider;
84100
import com.navercorp.pinpoint.profiler.metadata.MetaDataType;
85101
import com.navercorp.pinpoint.profiler.monitor.metric.gc.JvmGcType;
86102
import com.navercorp.pinpoint.profiler.receiver.ProfilerCommandLocatorBuilder;
@@ -117,29 +133,43 @@ public final class PinpointSpanExporter implements SpanExporter {
117133
private final String applicationName;
118134

119135
private final GrpcTransportConfig grpcTransportConfig;
136+
private final SSLContextProvider sslContextProvider;
120137

121138
private final HeaderFactory headerFactory;
122139

123140
private final AgentInfoSender agentInfoSender;
124141

125142
private final SpanGrpcDataSender spanGrpcDataSender;
126143

144+
private final JvmGcTypeMapper jvmGcTypeMapper = new JvmGcTypeMapperImpl();
145+
private final AgentInfoMapper agentInfoMapper = new AgentInfoMapperImpl(jvmGcTypeMapper);
146+
147+
private final SpanUriGetter spanUriGetter = new SpanAutoUriGetter();
148+
private final AnnotationValueMapper annotationValueMapper = Mappers.getMapper(AnnotationValueMapper.class);
149+
private final SpanMessageMapper spanMessageMapper = new SpanMessageMapperImpl(annotationValueMapper, spanUriGetter);
150+
127151
public PinpointSpanExporter(final String agentId,
128-
final String agentName,
129-
final String applicationName,
130-
final GrpcTransportConfig grpcTransportConfig) {
152+
final String agentName,
153+
final String applicationName,
154+
final GrpcTransportConfig grpcTransportConfig) {
131155

132156
this.agentId = Objects.requireNonNull(agentId, "agentId cannot be null");
133157
this.agentName = Objects.requireNonNull(agentName, "agentName cannot be null");
134158
this.applicationName = Objects.requireNonNull(applicationName, "applicationName cannot be null");
135159
this.grpcTransportConfig = Objects.requireNonNull(grpcTransportConfig, "grpcTransportConfig cannot be null");
136160

161+
if (grpcTransportConfig.getSslOption() != null) {
162+
this.sslContextProvider = new SSLContextProvider(grpcTransportConfig);
163+
} else {
164+
this.sslContextProvider = null;
165+
}
166+
137167
this.headerFactory = new AgentHeaderFactory(
138-
agentId,
139-
agentName,
140-
applicationName,
141-
ServiceType.UNDEFINED.getCode(),
142-
agentStartTime);
168+
agentId,
169+
agentName,
170+
applicationName,
171+
ServiceType.UNDEFINED.getCode(),
172+
agentStartTime);
143173

144174
this.agentInfoSender = createAgentInfoSender();
145175
this.agentInfoSender.start();
@@ -155,7 +185,7 @@ private AgentInfoSender createAgentInfoSender() {
155185
grpcTransportConfig.getAgentCollectorIp(),
156186
grpcTransportConfig.getAgentCollectorPort(),
157187
grpcTransportConfig.getAgentSenderExecutorQueueSize(),
158-
new GrpcAgentInfoMessageConverter(),
188+
new GrpcAgentInfoMessageConverter(agentInfoMapper),
159189
reconnectExecutor,
160190
scheduledExecutorService,
161191
agentChannelFactory,
@@ -171,17 +201,17 @@ private AgentInfoSender createAgentInfoSender() {
171201
ServiceType.STAND_ALONE);
172202

173203
final JvmInformation jvmInformation = new JvmInformation(
174-
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION),
175-
JvmGcType.UNKNOWN);
204+
JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION),
205+
JvmGcType.UNKNOWN);
176206

177207
final ServerMetaDataRegistryService serverMetaDataRegistryService = new DefaultServerMetaDataRegistryService(
178-
Collections.emptyList());
208+
Collections.emptyList());
179209
serverMetaDataRegistryService.setServerName(EventMeshTraceConstants.SERVICE_NAME);
180210

181211
final AgentInfoFactory agentInfoFactory = new AgentInfoFactory(
182-
agentInformationProvider.createAgentInformation(),
183-
serverMetaDataRegistryService,
184-
jvmInformation);
212+
agentInformationProvider.createAgentInformation(),
213+
serverMetaDataRegistryService,
214+
jvmInformation);
185215

186216
return new AgentInfoSender.Builder(agentGrpcDataSender, agentInfoFactory).build();
187217
}
@@ -193,41 +223,45 @@ private SpanGrpcDataSender createSpanGrpcDataSender() {
193223
new GrpcSpanMessageConverter(
194224
agentId,
195225
ServiceType.STAND_ALONE.getCode(),
196-
new GrpcSpanProcessorV2());
226+
new GrpcSpanProcessorV2(),
227+
this.spanMessageMapper);
197228

198229
final StreamState streamState =
199230
new SimpleStreamState(
200231
grpcTransportConfig.getSpanClientOption().getLimitCount(),
201232
grpcTransportConfig.getSpanClientOption().getLimitTime());
202233

203234
return new SpanGrpcDataSender(
204-
grpcTransportConfig.getSpanCollectorIp(),
205-
grpcTransportConfig.getSpanCollectorPort(),
206-
grpcTransportConfig.getSpanSenderExecutorQueueSize(),
207-
messageConverter,
208-
reconnectExecutor,
209-
spanChannelFactory,
210-
streamState);
235+
grpcTransportConfig.getSpanCollectorIp(),
236+
grpcTransportConfig.getSpanCollectorPort(),
237+
grpcTransportConfig.getSpanSenderExecutorQueueSize(),
238+
messageConverter,
239+
reconnectExecutor,
240+
spanChannelFactory,
241+
streamState,
242+
grpcTransportConfig.getSpanRpcMaxAgeMillis());
211243
}
212244

213245
private ChannelFactory createAgentChannelFactory() {
214-
final ChannelFactoryBuilder channelFactoryBuilder =
215-
new DefaultChannelFactoryBuilder(AGENT_CHANNEL_FACTORY);
246+
final ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder(AGENT_CHANNEL_FACTORY);
216247
channelFactoryBuilder.setHeaderFactory(headerFactory);
217248
channelFactoryBuilder.setNameResolverProvider(nameResolverProvider);
218-
channelFactoryBuilder.setSslOption(grpcTransportConfig.getSslOption());
249+
if (this.sslContextProvider != null) {
250+
channelFactoryBuilder.setSslContext(this.sslContextProvider.get());
251+
}
219252
channelFactoryBuilder.setClientOption(grpcTransportConfig.getAgentClientOption());
220253
channelFactoryBuilder.setExecutorQueueSize(grpcTransportConfig.getAgentChannelExecutorQueueSize());
221254

222255
return channelFactoryBuilder.build();
223256
}
224257

225258
private ChannelFactory createSpanChannelFactory() {
226-
final ChannelFactoryBuilder channelFactoryBuilder =
227-
new DefaultChannelFactoryBuilder(SPAN_CHANNEL_FACTORY);
259+
final ChannelFactoryBuilder channelFactoryBuilder = new DefaultChannelFactoryBuilder(SPAN_CHANNEL_FACTORY);
228260
channelFactoryBuilder.setHeaderFactory(headerFactory);
229261
channelFactoryBuilder.setNameResolverProvider(nameResolverProvider);
230-
channelFactoryBuilder.setSslOption(grpcTransportConfig.getSslOption());
262+
if (this.sslContextProvider != null) {
263+
channelFactoryBuilder.setSslContext(this.sslContextProvider.get());
264+
}
231265
channelFactoryBuilder.setClientOption(grpcTransportConfig.getSpanClientOption());
232266
channelFactoryBuilder.setExecutorQueueSize(grpcTransportConfig.getSpanChannelExecutorQueueSize());
233267

@@ -289,12 +323,21 @@ private Span toSpan(final SpanData spanData) {
289323
}
290324
});
291325

292-
final TraceId traceId = new DefaultTraceId(agentId, startTimestamp, transactionId, parentSpanId[0], spanId,
293-
(short) spanData.getKind().ordinal());
294-
295-
final TraceRoot traceRoot = new DefaultTraceRoot(traceId, this.agentId, startTimestamp, transactionId);
326+
final TraceIdFactory traceIdFactory = new DefaultTraceIdFactory(this.agentId, startTimestamp);
327+
final TraceRootFactory traceRootFactory = new DefaultTraceRootFactory(this.agentId, traceIdFactory);
328+
329+
final TraceRoot traceRoot;
330+
if (parentSpanId[0] == SpanId.NULL) {
331+
traceRoot = traceRootFactory.newTraceRoot(transactionId);
332+
} else {
333+
final TraceId traceId = traceIdFactory.continueTraceId(
334+
TransactionIdUtils.formatString(this.agentId, startTimestamp, transactionId), parentSpanId[0],
335+
spanId, (short) spanData.getKind().ordinal());
336+
traceRoot = traceRootFactory.continueTraceRoot(traceId, transactionId);
337+
}
296338

297-
final Span span = new Span(traceRoot);
339+
final DefaultSpanFactory spanFactory = new DefaultSpanFactory();
340+
final Span span = spanFactory.newSpan(traceRoot);
298341

299342
final StatusData statusData = spanData.getStatus();
300343
if (statusData != null) {
@@ -315,15 +358,15 @@ private Span toSpan(final SpanData spanData) {
315358
span.setRemoteAddr(UNKNOWN_REQ_IP);
316359

317360
Optional.ofNullable(spanData.getAttributes())
318-
.ifPresent(attributes -> {
319-
span.addAnnotation(Annotations.of(AnnotationKey.HTTP_PARAM_ENTITY.getCode(),
320-
JsonUtils.toJSONString(attributes)));
321-
attributes.forEach((key, value) -> {
322-
if (REQ_IP.equals(key.getKey())) {
323-
span.setRemoteAddr(String.valueOf(value));
324-
}
361+
.ifPresent(attributes -> {
362+
span.addAnnotation(Annotations.of(AnnotationKey.HTTP_PARAM_ENTITY.getCode(),
363+
JsonUtils.toJSONString(attributes)));
364+
attributes.forEach((key, value) -> {
365+
if (REQ_IP.equals(key.getKey())) {
366+
span.setRemoteAddr(String.valueOf(value));
367+
}
368+
});
325369
});
326-
});
327370

328371
if (CollectionUtils.isNotEmpty(spanData.getEvents())) {
329372
final AtomicInteger sequence = new AtomicInteger();
@@ -342,7 +385,7 @@ private SpanEvent toSpanEvent(final EventData eventData) {
342385
spanEvent.setServiceType(ServiceType.INTERNAL_METHOD.getCode());
343386
spanEvent.setEndPoint(eventData.getName());
344387
spanEvent.addAnnotation(Annotations.of(AnnotationKey.HTTP_PARAM_ENTITY.getCode(),
345-
JsonUtils.toJSONString(eventData.getAttributes())));
388+
JsonUtils.toJSONString(eventData.getAttributes())));
346389
spanEvent.setElapsedTime((int) toMillis(eventData.getEpochNanos()));
347390
return spanEvent;
348391
}
@@ -354,16 +397,16 @@ private static long toMillis(final long epochNanos) {
354397
private static long hex32StringToLong(final String hex32String) {
355398
final CharSequence charSequence = new StringBuilder().append(hex32String);
356399
return OtelEncodingUtils.isValidBase16String(charSequence)
357-
? OtelEncodingUtils.longFromBase16String(charSequence, 0)
358-
& OtelEncodingUtils.longFromBase16String(charSequence, 16)
359-
: hex32String.hashCode();
400+
? OtelEncodingUtils.longFromBase16String(charSequence, 0)
401+
& OtelEncodingUtils.longFromBase16String(charSequence, 16)
402+
: hex32String.hashCode();
360403
}
361404

362405
private static long hex16StringToLong(final String hex16String) {
363406
final CharSequence charSequence = new StringBuilder().append(hex16String);
364407
return OtelEncodingUtils.isValidBase16String(charSequence)
365-
? OtelEncodingUtils.longFromBase16String(charSequence, 0)
366-
: hex16String.hashCode();
408+
? OtelEncodingUtils.longFromBase16String(charSequence, 0)
409+
: hex16String.hashCode();
367410
}
368411

369412
private static String getEndpoint(final Resource resource) {

0 commit comments

Comments
 (0)