@@ -255,69 +255,120 @@ func (t *TracingController) ConstructEnvoyFilters() ([]*config.Config, error) {
255
255
return configs , nil
256
256
}
257
257
258
- config := & config.Config {
259
- Meta : config.Meta {
260
- GroupVersionKind : gvk .EnvoyFilter ,
261
- Name : higressTracingEnvoyFilterName ,
262
- Namespace : namespace ,
263
- },
264
- Spec : & networking.EnvoyFilter {
265
- ConfigPatches : []* networking.EnvoyFilter_EnvoyConfigObjectPatch {
266
- {
267
- ApplyTo : networking .EnvoyFilter_NETWORK_FILTER ,
268
- Match : & networking.EnvoyFilter_EnvoyConfigObjectMatch {
269
- Context : networking .EnvoyFilter_GATEWAY ,
270
- ObjectTypes : & networking.EnvoyFilter_EnvoyConfigObjectMatch_Listener {
271
- Listener : & networking.EnvoyFilter_ListenerMatch {
272
- FilterChain : & networking.EnvoyFilter_ListenerMatch_FilterChainMatch {
273
- Filter : & networking.EnvoyFilter_ListenerMatch_FilterMatch {
274
- Name : "envoy.filters.network.http_connection_manager" ,
275
- },
276
- },
258
+ configPatches := []* networking.EnvoyFilter_EnvoyConfigObjectPatch {
259
+ {
260
+ ApplyTo : networking .EnvoyFilter_NETWORK_FILTER ,
261
+ Match : & networking.EnvoyFilter_EnvoyConfigObjectMatch {
262
+ Context : networking .EnvoyFilter_GATEWAY ,
263
+ ObjectTypes : & networking.EnvoyFilter_EnvoyConfigObjectMatch_Listener {
264
+ Listener : & networking.EnvoyFilter_ListenerMatch {
265
+ FilterChain : & networking.EnvoyFilter_ListenerMatch_FilterChainMatch {
266
+ Filter : & networking.EnvoyFilter_ListenerMatch_FilterMatch {
267
+ Name : "envoy.filters.network.http_connection_manager" ,
277
268
},
278
269
},
279
270
},
280
- Patch : & networking.EnvoyFilter_Patch {
281
- Operation : networking .EnvoyFilter_Patch_MERGE ,
282
- Value : util .BuildPatchStruct (tracingConfig ),
283
- },
284
271
},
285
- {
286
- ApplyTo : networking .EnvoyFilter_HTTP_FILTER ,
287
- Match : & networking.EnvoyFilter_EnvoyConfigObjectMatch {
288
- Context : networking .EnvoyFilter_GATEWAY ,
289
- ObjectTypes : & networking.EnvoyFilter_EnvoyConfigObjectMatch_Listener {
290
- Listener : & networking.EnvoyFilter_ListenerMatch {
291
- FilterChain : & networking.EnvoyFilter_ListenerMatch_FilterChainMatch {
292
- Filter : & networking.EnvoyFilter_ListenerMatch_FilterMatch {
293
- Name : "envoy.filters.network.http_connection_manager" ,
294
- SubFilter : & networking.EnvoyFilter_ListenerMatch_SubFilterMatch {
295
- Name : "envoy.filters.http.router" ,
296
- },
297
- },
272
+ },
273
+ Patch : & networking.EnvoyFilter_Patch {
274
+ Operation : networking .EnvoyFilter_Patch_MERGE ,
275
+ Value : util .BuildPatchStruct (tracingConfig ),
276
+ },
277
+ },
278
+ {
279
+ ApplyTo : networking .EnvoyFilter_HTTP_FILTER ,
280
+ Match : & networking.EnvoyFilter_EnvoyConfigObjectMatch {
281
+ Context : networking .EnvoyFilter_GATEWAY ,
282
+ ObjectTypes : & networking.EnvoyFilter_EnvoyConfigObjectMatch_Listener {
283
+ Listener : & networking.EnvoyFilter_ListenerMatch {
284
+ FilterChain : & networking.EnvoyFilter_ListenerMatch_FilterChainMatch {
285
+ Filter : & networking.EnvoyFilter_ListenerMatch_FilterMatch {
286
+ Name : "envoy.filters.network.http_connection_manager" ,
287
+ SubFilter : & networking.EnvoyFilter_ListenerMatch_SubFilterMatch {
288
+ Name : "envoy.filters.http.router" ,
298
289
},
299
290
},
300
291
},
301
292
},
302
- Patch : & networking.EnvoyFilter_Patch {
303
- Operation : networking .EnvoyFilter_Patch_MERGE ,
304
- Value : util .BuildPatchStruct (`{
293
+ },
294
+ },
295
+ Patch : & networking.EnvoyFilter_Patch {
296
+ Operation : networking .EnvoyFilter_Patch_MERGE ,
297
+ Value : util .BuildPatchStruct (`{
305
298
"name":"envoy.filters.http.router",
306
299
"typed_config":{
307
300
"@type": "type.googleapis.com/envoy.extensions.filters.http.router.v3.Router",
308
301
"start_child_span": true
309
302
}
310
303
}` ),
311
- },
312
- },
313
304
},
314
305
},
315
306
}
316
307
308
+ patches := t .constructTracingExtendPatches (tracing )
309
+ configPatches = append (configPatches , patches ... )
310
+
311
+ config := & config.Config {
312
+ Meta : config.Meta {
313
+ GroupVersionKind : gvk .EnvoyFilter ,
314
+ Name : higressTracingEnvoyFilterName ,
315
+ Namespace : namespace ,
316
+ },
317
+ Spec : & networking.EnvoyFilter {
318
+ ConfigPatches : configPatches ,
319
+ },
320
+ }
321
+
317
322
configs = append (configs , config )
318
323
return configs , nil
319
324
}
320
325
326
+ func tracingClusterName (port , service string ) string {
327
+ return fmt .Sprintf ("outbound|%s||%s" , port , service )
328
+ }
329
+
330
+ func (t * TracingController ) constructHTTP2ProtocolOptionsPatch (port , service string ) * networking.EnvoyFilter_EnvoyConfigObjectPatch {
331
+ http2ProtocolOptions := `{"typed_extension_protocol_options": {
332
+ "envoy.extensions.upstreams.http.v3.HttpProtocolOptions": {
333
+ "@type": "type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions",
334
+ "explicit_http_config": {
335
+ "http2_protocol_options": {}
336
+ }
337
+ }
338
+ }}`
339
+
340
+ return & networking.EnvoyFilter_EnvoyConfigObjectPatch {
341
+ ApplyTo : networking .EnvoyFilter_CLUSTER ,
342
+ Match : & networking.EnvoyFilter_EnvoyConfigObjectMatch {
343
+ Context : networking .EnvoyFilter_GATEWAY ,
344
+ ObjectTypes : & networking.EnvoyFilter_EnvoyConfigObjectMatch_Cluster {
345
+ Cluster : & networking.EnvoyFilter_ClusterMatch {
346
+ Name : tracingClusterName (port , service ),
347
+ },
348
+ },
349
+ },
350
+ Patch : & networking.EnvoyFilter_Patch {
351
+ Operation : networking .EnvoyFilter_Patch_MERGE ,
352
+ Value : util .BuildPatchStruct (http2ProtocolOptions ),
353
+ },
354
+ }
355
+ }
356
+
357
+ func (t * TracingController ) constructTracingExtendPatches (tracing * Tracing ) []* networking.EnvoyFilter_EnvoyConfigObjectPatch {
358
+ if tracing == nil {
359
+ return nil
360
+ }
361
+ var patches []* networking.EnvoyFilter_EnvoyConfigObjectPatch
362
+ if skywalking := tracing .Skywalking ; skywalking != nil {
363
+ patches = append (patches , t .constructHTTP2ProtocolOptionsPatch (skywalking .Port , skywalking .Service ))
364
+ }
365
+ if otel := tracing .OpenTelemetry ; otel != nil {
366
+ patches = append (patches , t .constructHTTP2ProtocolOptionsPatch (otel .Port , otel .Service ))
367
+ }
368
+
369
+ return patches
370
+ }
371
+
321
372
func (t * TracingController ) constructTracingTracer (tracing * Tracing , namespace string ) string {
322
373
tracingConfig := ""
323
374
timeout := float32 (tracing .Timeout ) / 1000
@@ -338,7 +389,7 @@ func (t *TracingController) constructTracingTracer(tracing *Tracing, namespace s
338
389
},
339
390
"grpc_service": {
340
391
"envoy_grpc": {
341
- "cluster_name": "outbound|%s|| %s"
392
+ "cluster_name": "%s"
342
393
},
343
394
"timeout": "%.3fs"
344
395
}
@@ -349,7 +400,7 @@ func (t *TracingController) constructTracingTracer(tracing *Tracing, namespace s
349
400
}
350
401
}
351
402
}
352
- }` , namespace , skywalking .AccessToken , skywalking .Port , skywalking .Service , timeout , tracing .Sampling )
403
+ }` , namespace , skywalking .AccessToken , tracingClusterName ( skywalking .Port , skywalking .Service ) , timeout , tracing .Sampling )
353
404
}
354
405
355
406
if tracing .Zipkin != nil {
@@ -363,7 +414,7 @@ func (t *TracingController) constructTracingTracer(tracing *Tracing, namespace s
363
414
"name": "envoy.tracers.zipkin",
364
415
"typed_config": {
365
416
"@type": "type.googleapis.com/envoy.config.trace.v3.ZipkinConfig",
366
- "collector_cluster": "outbound|%s|| %s",
417
+ "collector_cluster": "%s",
367
418
"collector_endpoint": "/api/v2/spans",
368
419
"collector_hostname": "higress-gateway",
369
420
"collector_endpoint_version": "HTTP_JSON",
@@ -375,7 +426,7 @@ func (t *TracingController) constructTracingTracer(tracing *Tracing, namespace s
375
426
}
376
427
}
377
428
}
378
- }` , zipkin .Port , zipkin .Service , tracing .Sampling )
429
+ }` , tracingClusterName ( zipkin .Port , zipkin .Service ) , tracing .Sampling )
379
430
}
380
431
381
432
if tracing .OpenTelemetry != nil {
@@ -392,7 +443,7 @@ func (t *TracingController) constructTracingTracer(tracing *Tracing, namespace s
392
443
"service_name": "higress-gateway.%s",
393
444
"grpc_service": {
394
445
"envoy_grpc": {
395
- "cluster_name": "outbound|%s|| %s"
446
+ "cluster_name": "%s"
396
447
},
397
448
"timeout": "%.3fs"
398
449
}
@@ -403,7 +454,7 @@ func (t *TracingController) constructTracingTracer(tracing *Tracing, namespace s
403
454
}
404
455
}
405
456
}
406
- }` , namespace , opentelemetry .Port , opentelemetry .Service , timeout , tracing .Sampling )
457
+ }` , namespace , tracingClusterName ( opentelemetry .Port , opentelemetry .Service ) , timeout , tracing .Sampling )
407
458
}
408
459
return tracingConfig
409
460
}
0 commit comments