openshift - Red Hat Service Mesh:自定义标头转换为 x-b3-traceId 丢失
问题描述
我正在尝试将遗留系统与托管在 Red Hat OpenShift 平台上的微服务集成。该服务是入口网关后面的 Java 应用程序。旧版应用程序将唯一操作标识符作为自定义标头传递uniqueId
。该微服务利用了对 Jaeger 的 openshift 服务网格支持,因此我可以传递诸如此类的跟踪标头x-b3-traceid
并在 Jaeger UI 中查看请求跟踪。不幸的是,旧版应用程序无法修改,也不会发送 jaeger 标头,但uniqueId
符合 jaeger 规则,并且似乎可以用于跟踪。
我正在尝试转换uniqueId
为x-b3-traceid
特使过滤器。问题是我可以将它复制到任何其他标题,但不能修改x-b3-*
标题。x-b3-*
无论我在 envoy 过滤器中做什么,Istio 都会不断生成新的标头集。请参阅下面的过滤器代码。
我尝试了不同的过滤器位置(在入口网关上、在 pod sidecar 上、在 envoy.router 之前等)。似乎没有任何作用。谁能推荐我如何将自定义标头作为服务网格的 jaeger 的 traceId 传递?我可以创建一个自定义代理服务,将一个标头与另一个标头进行转换,但它看起来是多余的。是否可以仅使用服务网格来实现?
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: call-id-filter
namespace: mynamespace
spec:
filters:
- filterConfig:
inlineCode: |
function envoy_on_request(request_handle)
headers = request_handle:headers()
uniqueId=headers:get("uniqueId")
if (uniqueId ~= nil) then
request_handle:headers():add("x-b3-traceid", uniqueId) -- istio overwrites these values
request_handle:headers():add("x-b3-spanid", "myspan")
request_handle:headers():add("x-b3-sampled", "1")
request_handle:headers():add("my-custom-unique-id", uniqueId) -- works fine
request_handle:logCritical("envoy filter setting x-b3-traceid with"..uniqueId)
end
end
filterName: envoy.lua
filterType: HTTP
insertPosition:
index: FIRST
listenerMatch:
listenerType: GATEWAY
portNumber: 9011
workloadLabels:
app: istio-ingressgateway