1818
1919package org .apache .skywalking .oap .server .storage .plugin .banyandb .trace ;
2020
21- import com .google .common .collect .ImmutableSet ;
2221import javax .annotation .Nullable ;
2322import org .apache .skywalking .apm .network .language .agent .v3 .SegmentObject ;
2423import org .apache .skywalking .apm .network .language .agent .v3 .SpanObject ;
24+ import org .apache .skywalking .apm .network .language .agent .v3 .SpanType ;
2525import org .apache .skywalking .banyandb .v1 .client .AbstractQuery ;
2626import org .apache .skywalking .banyandb .v1 .client .TimestampRange ;
2727import org .apache .skywalking .banyandb .v1 .client .TraceQuery ;
2828import org .apache .skywalking .banyandb .v1 .client .TraceQueryResponse ;
29+ import org .apache .skywalking .oap .server .core .Const ;
30+ import org .apache .skywalking .oap .server .core .CoreModule ;
2931import org .apache .skywalking .oap .server .core .analysis .IDManager ;
3032import org .apache .skywalking .oap .server .core .analysis .manual .searchtag .Tag ;
3133import org .apache .skywalking .oap .server .core .analysis .manual .segment .SegmentRecord ;
34+ import org .apache .skywalking .oap .server .core .config .NamingControl ;
3235import org .apache .skywalking .oap .server .core .query .PaginationUtils ;
3336import org .apache .skywalking .oap .server .core .query .input .Duration ;
3437import org .apache .skywalking .oap .server .core .query .input .TraceQueryCondition ;
4144import org .apache .skywalking .oap .server .core .storage .query .ITraceQueryV2DAO ;
4245import org .apache .skywalking .oap .server .core .storage .query .proto .Source ;
4346import org .apache .skywalking .oap .server .core .storage .query .proto .SpanWrapper ;
47+ import org .apache .skywalking .oap .server .library .module .ModuleManager ;
4448import org .apache .skywalking .oap .server .library .util .BooleanUtils ;
4549import org .apache .skywalking .oap .server .library .util .CollectionUtils ;
4650import org .apache .skywalking .oap .server .library .util .StringUtil ;
5054import java .util .ArrayList ;
5155import java .util .Collections ;
5256import java .util .List ;
53- import java .util .Set ;
5457import org .apache .skywalking .oap .server .storage .plugin .banyandb .stream .AbstractBanyanDBDAO ;
5558
5659public class BanyanDBTraceQueryDAO extends AbstractBanyanDBDAO implements ITraceQueryV2DAO {
57- private static final Set <String > BASIC_TAGS = ImmutableSet .of (SegmentRecord .TRACE_ID ,
58- SegmentRecord .IS_ERROR ,
59- SegmentRecord .SERVICE_ID ,
60- SegmentRecord .SERVICE_INSTANCE_ID ,
61- SegmentRecord .ENDPOINT_ID ,
62- SegmentRecord .LATENCY ,
63- SegmentRecord .START_TIME ,
64- SegmentRecord .TAGS
65- );
66-
67- private static final Set <String > TAGS = ImmutableSet .of (SegmentRecord .TRACE_ID ,
68- SegmentRecord .IS_ERROR ,
69- SegmentRecord .SERVICE_ID ,
70- SegmentRecord .SERVICE_INSTANCE_ID ,
71- SegmentRecord .ENDPOINT_ID ,
72- SegmentRecord .LATENCY ,
73- SegmentRecord .START_TIME ,
74- SegmentRecord .SEGMENT_ID ,
75- SegmentRecord .DATA_BINARY );
7660 private final int segmentQueryMaxSize ;
61+ private final ModuleManager moduleManager ;
62+ private NamingControl namingControl ;
7763
78- public BanyanDBTraceQueryDAO (BanyanDBStorageClient client , int segmentQueryMaxSize ) {
64+ public BanyanDBTraceQueryDAO (BanyanDBStorageClient client , int segmentQueryMaxSize , ModuleManager moduleManager ) {
7965 super (client );
8066 this .segmentQueryMaxSize = segmentQueryMaxSize ;
67+ this .moduleManager = moduleManager ;
8168 }
8269
8370 @ Override
@@ -239,20 +226,34 @@ private List<SegmentRecord> buildRecords(TraceQueryResponse resp) throws IOExcep
239226 SegmentRecord segmentRecord = new SegmentRecord ();
240227 segmentRecord .setSegmentId (segmentObject .getTraceSegmentId ());
241228 segmentRecord .setTraceId (segmentObject .getTraceId ());
242- String serviceId = IDManager .ServiceID .buildId (segmentObject .getService (), true );
229+ String serviceName = Const .EMPTY_STRING ;
230+ String instanceName = Const .EMPTY_STRING ;
231+ String endpointName = Const .EMPTY_STRING ;
232+ serviceName = getNamingControl ().formatServiceName (segmentObject .getService ());
233+ instanceName = getNamingControl ().formatInstanceName (segmentObject .getServiceInstance ());
234+ String serviceId = IDManager .ServiceID .buildId (serviceName , true );
243235 segmentRecord .setServiceId (serviceId );
244- String serviceInstanceId = IDManager .ServiceInstanceID .buildId (serviceId , segmentObject . getServiceInstance () );
236+ String serviceInstanceId = IDManager .ServiceInstanceID .buildId (serviceId , instanceName );
245237 segmentRecord .setServiceInstanceId (serviceInstanceId );
246238 long startTimestamp = 0 ;
247239 long endTimestamp = 0 ;
240+
248241 for (SpanObject span : segmentObject .getSpansList ()) {
249242 if (startTimestamp == 0 || startTimestamp > span .getStartTime ()) {
250243 startTimestamp = span .getStartTime ();
251244 }
252245 if (span .getEndTime () > endTimestamp ) {
253246 endTimestamp = span .getEndTime ();
254247 }
248+ if (span .getSpanId () == 0 ) {
249+ endpointName = getNamingControl ().formatEndpointName (serviceName , span .getOperationName ());
250+ }
251+ if (SpanType .Entry .equals (span .getSpanType ())) {
252+ endpointName = getNamingControl ().formatEndpointName (serviceName , span .getOperationName ());
253+ }
255254 }
255+ String endpointId = IDManager .EndpointID .buildId (serviceId , endpointName );
256+ segmentRecord .setEndpointId (endpointId );
256257 final long accurateDuration = endTimestamp - startTimestamp ;
257258 int duration = accurateDuration > Integer .MAX_VALUE ? Integer .MAX_VALUE : (int ) accurateDuration ;
258259 segmentRecord .setLatency (duration );
@@ -264,4 +265,13 @@ private List<SegmentRecord> buildRecords(TraceQueryResponse resp) throws IOExcep
264265 }
265266 return segmentRecords ;
266267 }
268+
269+ private NamingControl getNamingControl () {
270+ if (namingControl == null ) {
271+ this .namingControl = moduleManager .find (CoreModule .NAME )
272+ .provider ()
273+ .getService (NamingControl .class );
274+ }
275+ return namingControl ;
276+ }
267277}
0 commit comments