22
22
import java .util .logging .Logger ;
23
23
import zipkin .Annotation ;
24
24
import zipkin .BinaryAnnotation ;
25
- import zipkin .Constants ;
26
25
import zipkin .Endpoint ;
27
26
import zipkin .Span ;
28
27
import zipkin2 .internal .Node ;
@@ -41,7 +40,7 @@ static class ClockSkew {
41
40
final Endpoint endpoint ;
42
41
final long skew ;
43
42
44
- public ClockSkew (Endpoint endpoint , long skew ) {
43
+ ClockSkew (Endpoint endpoint , long skew ) {
45
44
this .endpoint = endpoint ;
46
45
this .skew = skew ;
47
46
}
@@ -115,38 +114,39 @@ static void adjust(Node<Span> node, @Nullable ClockSkew skewFromParent) {
115
114
// Is there any skew in the current span?
116
115
ClockSkew skew = getClockSkew (node .value ());
117
116
if (skew != null ) {
118
- // the current span's skew may be a different endpoint than skewFromParent, adjust again.
117
+ // the current span's skew may be a different endpoint than its parent, so adjust again.
119
118
node .value (adjustTimestamps (node .value (), skew ));
120
- } else {
121
- if (skewFromParent != null && isLocalSpan (node .value ())) {
122
- //Propagate skewFromParent to local spans
123
- skew = skewFromParent ;
124
- }
119
+ } else if (skewFromParent != null && isSingleHostSpan (node .value ())) {
120
+ // Assumes we are on the same host: propagate skew from our parent
121
+ skew = skewFromParent ;
125
122
}
126
123
// propagate skew to any children
127
124
for (Node <Span > child : node .children ()) {
128
125
adjust (child , skew );
129
126
}
130
127
}
131
128
132
- static boolean isLocalSpan (Span span ) {
133
- Endpoint endPoint = null ;
129
+ static boolean isSingleHostSpan (Span span ) {
130
+ Endpoint endpoint = null ;
134
131
for (int i = 0 , length = span .annotations .size (); i < length ; i ++) {
135
132
Annotation annotation = span .annotations .get (i );
136
- if (endPoint == null ) {
137
- endPoint = annotation .endpoint ;
133
+ if (endpoint == null ) {
134
+ endpoint = annotation .endpoint ;
135
+ continue ;
138
136
}
139
- if (endPoint != null && ! endPoint .equals (annotation .endpoint )) {
140
- return false ;
137
+ if (! endpoint .equals (annotation .endpoint )) {
138
+ return false ; // there's a mix of endpoints in this span
141
139
}
142
140
}
143
141
for (int i = 0 , length = span .binaryAnnotations .size (); i < length ; i ++) {
144
142
BinaryAnnotation binaryAnnotation = span .binaryAnnotations .get (i );
145
- if (endPoint == null ) {
146
- endPoint = binaryAnnotation .endpoint ;
143
+ if (binaryAnnotation .type != BinaryAnnotation .Type .STRING ) continue ;
144
+ if (endpoint == null ) {
145
+ endpoint = binaryAnnotation .endpoint ;
146
+ continue ;
147
147
}
148
- if (endPoint != null && ! endPoint .equals (binaryAnnotation .endpoint )) {
149
- return false ;
148
+ if (! endpoint .equals (binaryAnnotation .endpoint )) {
149
+ return false ; // there's a mix of endpoints in this span
150
150
}
151
151
}
152
152
return true ;
@@ -179,7 +179,7 @@ static Span adjustTimestamps(Span span, ClockSkew skew) {
179
179
for (int i = 0 , length = span .binaryAnnotations .size (); i < length ; i ++) {
180
180
BinaryAnnotation b = span .binaryAnnotations .get (i );
181
181
if (b .endpoint == null ) continue ;
182
- if (b .key .equals (Constants . LOCAL_COMPONENT ) && ipsMatch (skew .endpoint , b .endpoint )) {
182
+ if (b .key .equals ("lc" ) && ipsMatch (skew .endpoint , b .endpoint )) {
183
183
return span .toBuilder ().timestamp (spanTimestamp - skew .skew ).build ();
184
184
}
185
185
}
@@ -190,21 +190,19 @@ static boolean ipsMatch(Endpoint skew, Endpoint that) {
190
190
if (skew .ipv6 != null && that .ipv6 != null ) {
191
191
if (Arrays .equals (skew .ipv6 , that .ipv6 )) return true ;
192
192
}
193
- if (skew .ipv4 != 0 && that .ipv4 != 0 ) {
194
- if (skew .ipv4 == that .ipv4 ) return true ;
195
- }
196
- return false ;
193
+ if (skew .ipv4 == 0 && that .ipv4 == 0 ) return false ;
194
+ return skew .ipv4 == that .ipv4 ;
197
195
}
198
196
199
197
/** Use client/server annotations to determine if there's clock skew. */
200
198
@ Nullable
201
199
static ClockSkew getClockSkew (Span span ) {
202
200
Map <String , Annotation > annotations = asMap (span .annotations );
203
201
204
- Annotation clientSend = annotations .get (Constants . CLIENT_SEND );
205
- Annotation clientRecv = annotations .get (Constants . CLIENT_RECV );
206
- Annotation serverRecv = annotations .get (Constants . SERVER_RECV );
207
- Annotation serverSend = annotations .get (Constants . SERVER_SEND );
202
+ Annotation clientSend = annotations .get ("cs" );
203
+ Annotation clientRecv = annotations .get ("cr" );
204
+ Annotation serverRecv = annotations .get ("sr" );
205
+ Annotation serverSend = annotations .get ("ss" );
208
206
209
207
boolean oneWay = false ;
210
208
if (clientSend == null || serverRecv == null ) {
@@ -247,7 +245,6 @@ static ClockSkew getClockSkew(Span span) {
247
245
}
248
246
}
249
247
250
-
251
248
return null ;
252
249
}
253
250
0 commit comments