From ac3f1b268f707d812ed20e5cf7b1d7c32d0533b7 Mon Sep 17 00:00:00 2001 From: Balazs Berta Date: Fri, 2 Jun 2023 15:24:53 +0200 Subject: [PATCH] Add tags, fix endopints, simplify grpc middleware, rebase to master --- components/bifrost/go.mod | 4 +- components/bifrost/go.sum | 7 +- experimental/java/go.mod | 4 +- experimental/java/go.sum | 7 +- experimental/mobile/go.mod | 4 +- experimental/mobile/go.sum | 7 +- go.mod | 4 +- go.sum | 2 +- go.work.sum | 1 + pkg/istio/istio.go | 10 +- pkg/istio/tracing/zipkin.go | 3 +- .../tracing/zipkin_grpc_client_middleware.go | 15 ++- pkg/istio/tracing/zipkin_grpc_middleware.go | 79 ------------- .../tracing/zipkin_http_client_middleware.go | 13 ++- pkg/istio/tracing/zipkin_http_middleware.go | 107 ++++++++++++++++-- 15 files changed, 146 insertions(+), 121 deletions(-) delete mode 100644 pkg/istio/tracing/zipkin_grpc_middleware.go diff --git a/components/bifrost/go.mod b/components/bifrost/go.mod index d169cd26..aedbcbdb 100644 --- a/components/bifrost/go.mod +++ b/components/bifrost/go.mod @@ -40,7 +40,7 @@ require ( github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/swag v0.21.1 // indirect - github.com/goccy/go-json v0.9.7 // indirect + github.com/goccy/go-json v0.10.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/gohobby/deepcopy v1.0.1 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect @@ -97,7 +97,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.21.0 // indirect - golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect + golang.org/x/crypto v0.5.0 // indirect golang.org/x/mod v0.9.0 // indirect golang.org/x/net v0.8.0 // indirect golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect diff --git a/components/bifrost/go.sum b/components/bifrost/go.sum index f040de3f..a97387b3 100644 --- a/components/bifrost/go.sum +++ b/components/bifrost/go.sum @@ -258,8 +258,9 @@ github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/ github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU= github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= +github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -728,8 +729,8 @@ golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 h1:x8vtB3zMecnlqZIwJNUUpwYKYSqCz5jXbiyv0ZJJZeI= -golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= +golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= diff --git a/experimental/java/go.mod b/experimental/java/go.mod index 00b27579..ce6335c7 100644 --- a/experimental/java/go.mod +++ b/experimental/java/go.mod @@ -42,7 +42,7 @@ require ( github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/swag v0.21.1 // indirect github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect - github.com/goccy/go-json v0.9.7 // indirect + github.com/goccy/go-json v0.10.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/gohobby/deepcopy v1.0.1 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect @@ -103,7 +103,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.21.0 // indirect - golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect + golang.org/x/crypto v0.5.0 // indirect golang.org/x/mod v0.9.0 // indirect golang.org/x/net v0.8.0 // indirect golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect diff --git a/experimental/java/go.sum b/experimental/java/go.sum index a7c08b05..057d5ffe 100644 --- a/experimental/java/go.sum +++ b/experimental/java/go.sum @@ -265,8 +265,9 @@ github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/e github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= +github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -750,8 +751,8 @@ golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 h1:x8vtB3zMecnlqZIwJNUUpwYKYSqCz5jXbiyv0ZJJZeI= -golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= +golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= diff --git a/experimental/mobile/go.mod b/experimental/mobile/go.mod index 4a49c15e..ea93088e 100644 --- a/experimental/mobile/go.mod +++ b/experimental/mobile/go.mod @@ -38,7 +38,7 @@ require ( github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/swag v0.21.1 // indirect - github.com/goccy/go-json v0.9.7 // indirect + github.com/goccy/go-json v0.10.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/gohobby/deepcopy v1.0.1 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect @@ -95,7 +95,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.21.0 // indirect - golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect + golang.org/x/crypto v0.5.0 // indirect golang.org/x/mod v0.9.0 // indirect golang.org/x/net v0.8.0 // indirect golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect diff --git a/experimental/mobile/go.sum b/experimental/mobile/go.sum index b40d87d9..84135e42 100644 --- a/experimental/mobile/go.sum +++ b/experimental/mobile/go.sum @@ -243,8 +243,9 @@ github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/ github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU= github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= +github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= @@ -647,8 +648,8 @@ golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 h1:x8vtB3zMecnlqZIwJNUUpwYKYSqCz5jXbiyv0ZJJZeI= -golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= +golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= diff --git a/go.mod b/go.mod index f0cda88b..4967860e 100644 --- a/go.mod +++ b/go.mod @@ -133,9 +133,9 @@ require ( go.opentelemetry.io/proto/otlp v0.18.0 // indirect go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.21.0 // indirect - golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect - golang.org/x/mod v0.9.0 // indirect + golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect golang.org/x/crypto v0.5.0 // indirect + golang.org/x/mod v0.9.0 // indirect golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect golang.org/x/sys v0.6.0 // indirect golang.org/x/term v0.6.0 // indirect diff --git a/go.sum b/go.sum index d7804629..a7a4b8f8 100644 --- a/go.sum +++ b/go.sum @@ -272,7 +272,6 @@ github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVL github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= @@ -932,6 +931,7 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/go.work.sum b/go.work.sum index 373c5fed..4b3db9e2 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1008,6 +1008,7 @@ golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= diff --git a/pkg/istio/istio.go b/pkg/istio/istio.go index 9dca46cf..4093c2a2 100644 --- a/pkg/istio/istio.go +++ b/pkg/istio/istio.go @@ -329,7 +329,7 @@ func (h *istioIntegrationHandler) GetHTTPTransport(transport http.RoundTripper) httpTransport := pwhttp.NewHTTPTransport(tp, streamHandler, logger) if h.zipkinTracer != nil { - httpTransport.AddMiddleware(tracing.NewZipkinHTTPClientTracingMiddleware(h.zipkinTracer)) + httpTransport.AddMiddleware(tracing.NewZipkinHTTPClientTracingMiddleware(h.zipkinTracer, h.environment)) } httpTransport.AddMiddleware(middleware.NewEnvoyHTTPHandlerMiddleware()) @@ -347,7 +347,7 @@ func (h *istioIntegrationHandler) GetGRPCDialOptions() ([]grpc.DialOption, error grpcDialer := pwgrpc.NewGRPCDialer(h.caClient, streamHandler, h.discoveryClient, h.logger) if h.zipkinTracer != nil { - grpcDialer.AddMiddleware(tracing.NewZipkinGRPCTracingMiddleware(h.zipkinTracer)) + grpcDialer.AddMiddleware(tracing.NewZipkinGRPCClientTracingMiddleware(h.zipkinTracer, h.environment)) } grpcDialer.AddMiddleware(middleware.NewEnvoyHTTPHandlerMiddleware()) @@ -374,11 +374,7 @@ func (h *istioIntegrationHandler) ListenAndServe(ctx context.Context, listenAddr httpHandler := pwhttp.NewHandler(handler, streamHandler, api.ListenerDirectionInbound) if h.zipkinTracer != nil { - httpHandler.AddMiddleware(tracing.NewZipkinHTTPTracingMiddleware(h.zipkinTracer)) - - // TODO(bertab) should it be merged with the http middleware? - // if including both will it duplicate spans? - // httpHandler.AddMiddleware(tracing.NewZipkinGRPCTracingMiddleware(h.zipkinTracer)) + httpHandler.AddMiddleware(tracing.NewZipkinHTTPTracingMiddleware(h.zipkinTracer, h.environment)) } httpHandler.AddMiddleware(middleware.NewEnvoyHTTPHandlerMiddleware()) diff --git a/pkg/istio/tracing/zipkin.go b/pkg/istio/tracing/zipkin.go index a13d04d2..48a0e41d 100644 --- a/pkg/istio/tracing/zipkin.go +++ b/pkg/istio/tracing/zipkin.go @@ -22,7 +22,8 @@ func SetupZipkinTracing(istioEnvironment *environment.IstioEnvironment, httpClie localIP = istioEnvironment.InstanceIPs[0] } - localEndpoint, err := zipkin.NewEndpoint("nasp", localIP) + serviceName := istioEnvironment.Labels["service.istio.io/canonical-name"] + "." + istioEnvironment.PodNamespace + localEndpoint, err := zipkin.NewEndpoint(serviceName, localIP) if err != nil { return nil, err } diff --git a/pkg/istio/tracing/zipkin_grpc_client_middleware.go b/pkg/istio/tracing/zipkin_grpc_client_middleware.go index c524983d..79aedfae 100644 --- a/pkg/istio/tracing/zipkin_grpc_client_middleware.go +++ b/pkg/istio/tracing/zipkin_grpc_client_middleware.go @@ -3,6 +3,8 @@ package tracing import ( "context" + "github.com/cisco-open/nasp/pkg/environment" + "github.com/openzipkin/zipkin-go" "github.com/openzipkin/zipkin-go/model" @@ -11,14 +13,16 @@ import ( ) type zipkinGRPCClientTracingMiddleware struct { - tracer *zipkin.Tracer + tracer *zipkin.Tracer + environment *environment.IstioEnvironment } var _ lhttp.HandleMiddleware = &zipkinGRPCClientTracingMiddleware{} -func NewZipkinGRPCClientTracingMiddleware(tracer *zipkin.Tracer) lhttp.HandleMiddleware { +func NewZipkinGRPCClientTracingMiddleware(tracer *zipkin.Tracer, meshConfig *environment.IstioEnvironment) lhttp.HandleMiddleware { h := &zipkinGRPCClientTracingMiddleware{ - tracer: tracer, + tracer: tracer, + environment: meshConfig, } return h } @@ -49,6 +53,11 @@ func (z zipkinGRPCClientTracingMiddleware) AfterRequest(req api.HTTPRequest, str zipkin.RemoteEndpoint(remoteEndpoint), ) + zipkin.TagHTTPMethod.Set(span, req.Method()) + zipkin.TagHTTPPath.Set(span, req.URL().Path) + zipkin.TagHTTPUrl.Set(span, req.URL().String()) + AddCommonZipkinTags(req, span, z.environment) + _ = InjectGRPCHeaders(req)(span.Context()) return req.WithContext(zipkin.NewContext(req.Context(), span)), stream diff --git a/pkg/istio/tracing/zipkin_grpc_middleware.go b/pkg/istio/tracing/zipkin_grpc_middleware.go deleted file mode 100644 index 3694a4e5..00000000 --- a/pkg/istio/tracing/zipkin_grpc_middleware.go +++ /dev/null @@ -1,79 +0,0 @@ -package tracing - -import ( - "context" - "strconv" - - "google.golang.org/grpc/status" - - "github.com/openzipkin/zipkin-go" - "github.com/openzipkin/zipkin-go/model" - - "github.com/cisco-open/nasp/pkg/proxywasm/api" - lhttp "github.com/cisco-open/nasp/pkg/proxywasm/http" -) - -type zipkinGRPCTracingMiddleware struct { - tracer *zipkin.Tracer -} - -var _ lhttp.HandleMiddleware = &zipkinGRPCTracingMiddleware{} - -func NewZipkinGRPCTracingMiddleware(tracer *zipkin.Tracer) lhttp.HandleMiddleware { - h := &zipkinGRPCTracingMiddleware{ - tracer: tracer, - } - return h -} - -func (z zipkinGRPCTracingMiddleware) BeforeRequest(req api.HTTPRequest, stream api.Stream) (api.HTTPRequest, api.Stream) { - tags := make(map[string]string) - - tags["grpc.method"] = req.Method() - - spanName := req.URL().String() - remoteEndpoint, _ := ExtractRemoteEndpoint(req) - - spanContext := z.tracer.Extract(ExtractGRPCHeaders(req)) - - span := z.tracer.StartSpan( - spanName, - zipkin.Kind(model.Server), - zipkin.Tags(tags), - zipkin.Parent(spanContext), - zipkin.RemoteEndpoint(remoteEndpoint), - ) - span.SetRemoteEndpoint(remoteEndpoint) - - if req.ContentLength() > 0 { - zipkin.TagHTTPRequestSize.Set(span, strconv.FormatInt(req.ContentLength(), 10)) - } - - _ = InjectGRPCHeaders(req)(span.Context()) - return req.WithContext(zipkin.NewContext(req.Context(), span)), stream -} - -func (z zipkinGRPCTracingMiddleware) AfterRequest(req api.HTTPRequest, stream api.Stream) (api.HTTPRequest, api.Stream) { - return req, stream -} - -func (z zipkinGRPCTracingMiddleware) BeforeResponse(ctx context.Context, resp api.HTTPResponse, stream api.Stream) (api.HTTPResponse, api.Stream) { - return resp, stream -} - -func (z zipkinGRPCTracingMiddleware) AfterResponse(ctx context.Context, resp api.HTTPResponse, stream api.Stream) (api.HTTPResponse, api.Stream) { - if span := zipkin.SpanFromContext(ctx); span != nil { - if resp.Error() != nil { - if status, ok := status.FromError(resp.Error()); ok { - zipkin.TagGRPCStatusCode.Set(span, strconv.Itoa(resp.StatusCode())) - zipkin.TagError.Set(span, status.Message()) - } else { - zipkin.TagError.Set(span, resp.Error().Error()) - } - } - - span.Finish() - } - - return resp, stream -} diff --git a/pkg/istio/tracing/zipkin_http_client_middleware.go b/pkg/istio/tracing/zipkin_http_client_middleware.go index 5dc914d6..0897bf0f 100644 --- a/pkg/istio/tracing/zipkin_http_client_middleware.go +++ b/pkg/istio/tracing/zipkin_http_client_middleware.go @@ -4,6 +4,8 @@ import ( "context" "strconv" + "github.com/cisco-open/nasp/pkg/environment" + "github.com/openzipkin/zipkin-go" "github.com/openzipkin/zipkin-go/model" @@ -12,14 +14,16 @@ import ( ) type zipkinHTTPClientTracingMiddleware struct { - tracer *zipkin.Tracer + tracer *zipkin.Tracer + environment *environment.IstioEnvironment } var _ lhttp.HandleMiddleware = &zipkinHTTPClientTracingMiddleware{} -func NewZipkinHTTPClientTracingMiddleware(tracer *zipkin.Tracer) lhttp.HandleMiddleware { +func NewZipkinHTTPClientTracingMiddleware(tracer *zipkin.Tracer, meshConfig *environment.IstioEnvironment) lhttp.HandleMiddleware { h := &zipkinHTTPClientTracingMiddleware{ - tracer: tracer, + tracer: tracer, + environment: meshConfig, } return h } @@ -41,7 +45,7 @@ func (z zipkinHTTPClientTracingMiddleware) AfterRequest(req api.HTTPRequest, str parentContext = z.tracer.Extract(ExtractHTTPHeaders(req)) } - spanName := req.URL().Scheme + "/" + req.Method() + spanName := req.URL().String() remoteEndpoint, _ := ExtractRemoteEndpoint(req) span := z.tracer.StartSpan( @@ -53,6 +57,7 @@ func (z zipkinHTTPClientTracingMiddleware) AfterRequest(req api.HTTPRequest, str zipkin.TagHTTPMethod.Set(span, req.Method()) zipkin.TagHTTPPath.Set(span, req.URL().Path) zipkin.TagHTTPUrl.Set(span, req.URL().String()) + AddCommonZipkinTags(req, span, z.environment) _ = InjectHTTPHeaders(req)(span.Context()) diff --git a/pkg/istio/tracing/zipkin_http_middleware.go b/pkg/istio/tracing/zipkin_http_middleware.go index 3b2ac1a5..824a094f 100644 --- a/pkg/istio/tracing/zipkin_http_middleware.go +++ b/pkg/istio/tracing/zipkin_http_middleware.go @@ -4,6 +4,10 @@ import ( "context" "strconv" + "google.golang.org/grpc/status" + + "github.com/cisco-open/nasp/pkg/environment" + "github.com/openzipkin/zipkin-go" "github.com/openzipkin/zipkin-go/model" @@ -12,14 +16,16 @@ import ( ) type zipkinHTTPTracingMiddleware struct { - tracer *zipkin.Tracer + tracer *zipkin.Tracer + environment *environment.IstioEnvironment } var _ lhttp.HandleMiddleware = &zipkinHTTPTracingMiddleware{} -func NewZipkinHTTPTracingMiddleware(tracer *zipkin.Tracer) lhttp.HandleMiddleware { +func NewZipkinHTTPTracingMiddleware(tracer *zipkin.Tracer, meshConfig *environment.IstioEnvironment) lhttp.HandleMiddleware { h := &zipkinHTTPTracingMiddleware{ - tracer: tracer, + tracer: tracer, + environment: meshConfig, } return h } @@ -29,10 +35,15 @@ func (z *zipkinHTTPTracingMiddleware) BeforeRequest(req api.HTTPRequest, stream return req, stream } + // handle GRPC request + if value, ok := req.Header().Get("Content-Type"); ok && value == "application/grpc" { + return z.GRPCBeforeRequest(req, stream) + } + // extract B3 Headers from upstream spanContext := z.tracer.Extract(ExtractHTTPHeaders(req)) - spanName := req.URL().Scheme + "/" + req.Method() + spanName := req.URL().String() span := z.tracer.StartSpan( spanName, @@ -47,10 +58,7 @@ func (z *zipkinHTTPTracingMiddleware) BeforeRequest(req api.HTTPRequest, stream zipkin.TagHTTPMethod.Set(span, req.Method()) zipkin.TagHTTPPath.Set(span, req.URL().Path) zipkin.TagHTTPUrl.Set(span, req.URL().String()) - - if req.ContentLength() > 0 { - zipkin.TagHTTPRequestSize.Set(span, strconv.FormatInt(req.ContentLength(), 10)) - } + AddCommonZipkinTags(req, span, z.environment) _ = InjectHTTPHeaders(req)(span.Context()) @@ -70,10 +78,15 @@ func (z *zipkinHTTPTracingMiddleware) AfterResponse(ctx context.Context, resp ap return resp, stream } + // handle GRPC case + if value, ok := resp.Header().Get("Content-Type"); ok && value == "application/grpc" { + return z.GRPCAfterResponse(ctx, resp, stream) + } + if span := zipkin.SpanFromContext(ctx); span != nil { code := resp.StatusCode() sCode := strconv.Itoa(code) - if code < 200 || code > 299 { + if code <= 200 || code > 299 { zipkin.TagHTTPStatusCode.Set(span, sCode) if code > 399 { zipkin.TagError.Set(span, sCode) @@ -88,3 +101,79 @@ func (z *zipkinHTTPTracingMiddleware) AfterResponse(ctx context.Context, resp ap return resp, stream } + +func (z *zipkinHTTPTracingMiddleware) GRPCBeforeRequest(req api.HTTPRequest, stream api.Stream) (api.HTTPRequest, api.Stream) { + tags := make(map[string]string) + + tags["grpc.method"] = req.Method() + + spanName := req.URL().String() + remoteEndpoint, _ := ExtractRemoteEndpoint(req) + + spanContext := z.tracer.Extract(ExtractGRPCHeaders(req)) + + span := z.tracer.StartSpan( + spanName, + zipkin.Kind(model.Server), + zipkin.Tags(tags), + zipkin.Parent(spanContext), + zipkin.RemoteEndpoint(remoteEndpoint), + ) + span.SetRemoteEndpoint(remoteEndpoint) + + if req.ContentLength() > 0 { + zipkin.TagHTTPRequestSize.Set(span, strconv.FormatInt(req.ContentLength(), 10)) + } + + _ = InjectGRPCHeaders(req)(span.Context()) + return req.WithContext(zipkin.NewContext(req.Context(), span)), stream +} + +func (z *zipkinHTTPTracingMiddleware) GRPCAfterResponse(ctx context.Context, resp api.HTTPResponse, stream api.Stream) (api.HTTPResponse, api.Stream) { + if span := zipkin.SpanFromContext(ctx); span != nil { + if resp.Error() != nil { + if status, ok := status.FromError(resp.Error()); ok { + zipkin.TagGRPCStatusCode.Set(span, strconv.Itoa(resp.StatusCode())) + zipkin.TagError.Set(span, status.Message()) + } else { + zipkin.TagError.Set(span, resp.Error().Error()) + } + } + + span.Finish() + } + + return resp, stream +} + +// AddCommonZipkinTags adds common tracing tags, like HTTP protocol, user agent, request ID, downstream cluster, +// and Istio environment specifics +func AddCommonZipkinTags(req api.HTTPRequest, span zipkin.Span, istioEnvironment *environment.IstioEnvironment) { + zipkin.Tag("http.protocol").Set(span, req.HTTPProtocol()) + zipkin.Tag("component").Set(span, "nasp") + if value, ok := req.Header().Get("User-Agent"); ok { + zipkin.Tag("user_agent").Set(span, value) + } + if value, ok := req.Header().Get("x-request-id"); ok { + zipkin.Tag("guid:x-request-id").Set(span, value) + } + + if value, ok := req.Header().Get("x-envoy-downstream-service-cluster"); ok { + zipkin.Tag("downstream_cluster").Set(span, value) + } + + zipkin.Tag("istio.mesh_id").Set(span, istioEnvironment.MeshID) + zipkin.Tag("istio.namespace").Set(span, istioEnvironment.PodNamespace) + + if value, ok := istioEnvironment.Labels["service.istio.io/canonical-name"]; ok { + zipkin.Tag("istio.canonical_service").Set(span, value) + } + + if value, ok := istioEnvironment.Labels["service.istio.io/canonical-revision"]; ok { + zipkin.Tag("istio.canonical_revision").Set(span, value) + } + + if req.ContentLength() > 0 { + zipkin.TagHTTPRequestSize.Set(span, strconv.FormatInt(req.ContentLength(), 10)) + } +}