Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send custom headers in tracing backend requests #7353

Merged
merged 2 commits into from
May 22, 2024

Conversation

jmazzitelli
Copy link
Collaborator

fixes: #7266

@jmazzitelli jmazzitelli self-assigned this May 13, 2024
@jmazzitelli
Copy link
Collaborator Author

jmazzitelli commented May 14, 2024

I think the only thing left to do is figure out how to get custom headers sent via the gRPC client that is created here:

https://github.com/kiali/kiali/blob/v1.84.0/tracing/client.go#L150-L158

conn, err := grpc.Dial(address, opts...)
if err == nil {
	cc := model.NewQueryServiceClient(conn)
	client, err = jaeger.NewGRPCJaegerClient(cc)
	if err != nil {
		return nil, err
	}
	log.Infof("Create %s GRPC client %s", cfgTracing.Provider, address)
	return &Client{httpTracingClient: httpTracingClient, grpcClient: client, ctx: ctx}, nil
...

Need to investigate the APIs used here because it isn't clear to me if you can set client-side headers to be sent over the underlying HTTP/2 transport. (UPDATE: latest commits do this. So this is done).

@jmazzitelli jmazzitelli marked this pull request as ready for review May 14, 2024 19:13
@jmazzitelli jmazzitelli added the requires operator PR It requires update in operator code label May 15, 2024
@jmazzitelli
Copy link
Collaborator Author

jmazzitelli commented May 17, 2024

  1. With this PR checked out, build the server: make build build-ui test
  2. Start a cluster with Kiali (using what you built in step 1) w/Tracing enabled: hack/run-integration-tests.sh -so true
  3. Add a custom header to the Tracing config: kubectl edit cm kiali -n istio-system
external_services:
  tracing:
    url: http://tracing.istio-system:16685/jaeger
    custom_headers:
      X-MazzWasHere_Foo: mazz_WasHere
  1. Restart the Kiali pod to pick up the change: kubectl delete pod -n istio-system -l app.kubernetes.io/name=kiali
  2. Confirm the header was added to the client:
$ kubectl logs -n istio-system -l app.kubernetes.io/name=kiali --tail=-1 | grep "custom headers"
2024-05-17T14:27:30Z TRC Adding [1] custom headers to Tracing client
  1. At this point it would be nice to actually see the header in the HTTP request, but you need to use kubeshark to do it. If you are so inclined, install kubeshark and look at the traffic going from kiali to the tracing pod and you'll see the header.

@jmazzitelli
Copy link
Collaborator Author

jmazzitelli commented May 17, 2024

Using Tempo without gRPC (hack/setup-kind-in-ci.sh -t), I can see the headers using kubeshark:

image

@jmazzitelli
Copy link
Collaborator Author

latest commit has it working with grpc:
grpc-kubeshark

@jmazzitelli
Copy link
Collaborator Author

This is all ready. I was able to confirm the header is passed with using gRPC and non-gRPC.

@jmazzitelli jmazzitelli requested a review from josunect May 17, 2024 21:06
@jmazzitelli
Copy link
Collaborator Author

@josunect I added you as a reviewer to take a look at the code since you are most familiar with it. The person who asked for this feature tested it in his cluster and it works for him, and I tested it (as you see above) and it works for me, too. I just want to make sure the code doesn't break something else that I cannot see.

jshaughn
jshaughn previously approved these changes May 18, 2024
Copy link
Collaborator

@jshaughn jshaughn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't run it because the community originator of the RFE already tested it successfully. Code looks good for me.

@jshaughn jshaughn added the test: back-end/integration PR adds/updates back-end tests (unit and/or integration) label May 22, 2024
Copy link
Contributor

@josunect josunect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it yet, I've just added one comment after looking at the code. Except for that, it looks good!

@@ -165,7 +171,7 @@ func newClient(ctx context.Context, cfg *config.Config, token string) (*Client,
// Legacy HTTP client
log.Tracef("Using legacy HTTP client for Tracing: url=%v, auth.type=%s", u, auth.Type)
timeout := time.Duration(config.Get().ExternalServices.Tracing.QueryTimeout) * time.Second
transport, err := httputil.CreateTransport(&auth, &http.Transport{}, timeout, nil)
transport, err := httputil.CreateTransport(&auth, &http.Transport{}, timeout, cfgTracing.CustomHeaders)
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't add the comment in the specific line, but I think the ctx should also need to be added in the Tempo grpc client? This would be in line 195:
clientConn, _ := grpc.Dial(grpcAddress, dialOps...)

I think that could be replaced with something like:

clientConn, _ := grpc.DialContext(ctx, grpcAddress, dialOps...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change - see commit abb5e7a

@jmazzitelli
Copy link
Collaborator Author

The failure is the known flake unrelated to this PR

@jmazzitelli jmazzitelli requested a review from jshaughn May 22, 2024 17:38
Copy link
Collaborator

@jshaughn jshaughn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving, +1 to Josune's suggested change.

@jmazzitelli jmazzitelli merged commit 976461b into kiali:master May 22, 2024
8 of 9 checks passed
@jmazzitelli jmazzitelli deleted the 7266-custom-headers-tracing branch May 22, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires operator PR It requires update in operator code test: back-end/integration PR adds/updates back-end tests (unit and/or integration)
Projects
Development

Successfully merging this pull request may close these issues.

Custom http headers for tracing
3 participants