-
Notifications
You must be signed in to change notification settings - Fork 25
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
[VC-36032] Pass the context to Venafi clients and enable debug roundtripper #627
Conversation
12618ad
to
f46d396
Compare
Add the client-go debug round tripper to the venafi clients Signed-off-by: Richard Wall <richard.wall@venafi.com>
f46d396
to
68bbb8f
Compare
Signed-off-by: Richard Wall <richard.wall@venafi.com>
Signed-off-by: Richard Wall <richard.wall@venafi.com>
Signed-off-by: Richard Wall <richard.wall@venafi.com>
3b3b68a
to
ec8af5f
Compare
extraArgs: | ||
- --logging-format=json | ||
- --log-level=6 # To enable HTTP request logging | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Example: | ||
# extraArgs: | ||
# - --logging-format=json | ||
# - --log-level=6 # To enable HTTP request logging | ||
extraArgs: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Matches what is now used in the E2E test:
jetstack-secure/hack/e2e/values.venafi-kubernetes-agent.yaml
Lines 11 to 13 in fcca2f1
extraArgs: | |
- --logging-format=json | |
- --log-level=6 |
@@ -10,4 +10,4 @@ authentication: | |||
|
|||
extraArgs: | |||
- --logging-format=json | |||
- --log-level=2 | |||
- --log-level=6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -648,7 +655,7 @@ func Test_ValidateAndCombineConfig_VenafiCloudKeyPair(t *testing.T) { | |||
testutil.TrustCA(t, cl, cert) | |||
assert.Equal(t, VenafiCloudKeypair, got.AuthMode) | |||
|
|||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: "test cluster name"}) | |||
err = cl.PostDataReadingsWithOptions(ctx, nil, client.Options{ClusterName: "test cluster name"}) | |||
require.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing gets logged by the client in this test
$ go test ./pkg/agent/... -v -run "Test_ValidateAndCombineConfig_VenafiCloudKeyPair"
=== RUN Test_ValidateAndCombineConfig_VenafiCloudKeyPair
=== RUN Test_ValidateAndCombineConfig_VenafiCloudKeyPair/server,_uploader_id,_and_cluster_name_are_correctly_passed
envtest.go:188: fake api.venafi.cloud received request: POST /v1/oauth/token/serviceaccount
envtest.go:188: fake api.venafi.cloud received request: POST /v1/tlspk/upload/clusterdata/no
--- PASS: Test_ValidateAndCombineConfig_VenafiCloudKeyPair (0.01s)
--- PASS: Test_ValidateAndCombineConfig_VenafiCloudKeyPair/server,_uploader_id,_and_cluster_name_are_correctly_passed (0.01s)
PASS
ok github.com/jetstack/preflight/pkg/agent 0.044s
testutil.TrustCA(t, cl, cert) | ||
|
||
// TODO(mael): the client should keep track of the cluster ID, we | ||
// shouldn't need to pass it as an option to | ||
// PostDataReadingsWithOptions. | ||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: cfg.ClusterID}) | ||
err = cl.PostDataReadingsWithOptions(ctx, nil, client.Options{ClusterName: cfg.ClusterID}) | ||
require.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ go test ./pkg/agent/... -v -run "Test_ValidateAndCombineConfig_VenafiConnection"
=== RUN Test_ValidateAndCombineConfig_VenafiConnection
=== RUN Test_ValidateAndCombineConfig_VenafiConnection/err_when_cluster_id_field_is_empty
=== RUN Test_ValidateAndCombineConfig_VenafiConnection/the_server_field_is_ignored_when_VenafiConnection_is_used
=== NAME Test_ValidateAndCombineConfig_VenafiConnection
envtest.go:188: fake api.venafi.cloud received request: POST /v1/tlspk/upload/clusterdata/no
envtest.go:51: Waiting for envtest to exit
--- PASS: Test_ValidateAndCombineConfig_VenafiConnection (7.01s)
--- PASS: Test_ValidateAndCombineConfig_VenafiConnection/err_when_cluster_id_field_is_empty (0.00s)
--- PASS: Test_ValidateAndCombineConfig_VenafiConnection/the_server_field_is_ignored_when_VenafiConnection_is_used (0.17s)
PASS
ok github.com/jetstack/preflight/pkg/agent 7.041s
pkg/client/client_venconn_test.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ go test ./pkg/client/... -v -run "TestVenConnClient_PostDataReadin
gsWithOptions"
=== RUN TestVenConnClient_PostDataReadingsWithOptions
=== PAUSE TestVenConnClient_PostDataReadingsWithOptions
=== CONT TestVenConnClient_PostDataReadingsWithOptions
=== RUN TestVenConnClient_PostDataReadingsWithOptions/valid_accessToken
envtest.go:188: fake api.venafi.cloud received request: POST /v1/tlspk/upload/clusterdata/no
=== RUN TestVenConnClient_PostDataReadingsWithOptions/error_when_the_apiKey_field_is_used
W1127 14:44:47.223096 366750 reflector.go:484] pkg/mod/k8s.io/client-go@v0.31.1/tools/cache/reflector.go:243: watch of *v1.PartialObjectMetadata ended with: an error on the server ("unable to decode an event from the watch stream: context canceled") has prevented the request from succeeding
envtest.go:188: fake api.venafi.cloud received request: GET /v1/useraccounts
envtest.go:188: fake api.venafi.cloud received request: GET /v1/useraccounts
metrics_transport.go:113: I1127 14:44:47.488976] outgoing http request succeeded method="GET" uri="https://127.0.0.1:36713/v1/useraccounts" status="200 OK" duration="340.47µs"
W1127 14:44:47.491474 366750 reflector.go:484] pkg/mod/k8s.io/client-go@v0.31.1/tools/cache/reflector.go:243: watch of *v1alpha1.VenafiConnection ended with: an error on the server ("unable to decode an event from the watch stream: context canceled") has prevented the request from succeeding
=== RUN TestVenConnClient_PostDataReadingsWithOptions/error_when_the_tpp_field_is_used
W1127 14:44:47.491530 366750 reflector.go:484] pkg/mod/k8s.io/client-go@v0.31.1/tools/cache/reflector.go:243: watch of *v1.PartialObjectMetadata ended with: an error on the server ("unable to decode an event from the watch stream: context canceled") has prevented the request from succeeding
envtest.go:235: fake tpp.example.com received request: GET /vedsdk/Identity/Self
envtest.go:235: fake tpp.example.com received request: GET /vedsdk/Identity/Self
metrics_transport.go:113: I1127 14:44:47.756336] outgoing http request succeeded method="GET" uri="https://127.0.0.1:46053/vedsdk/Identity/Self" status="200 OK" duration="453.761µs"
=== NAME TestVenConnClient_PostDataReadingsWithOptions
envtest.go:51: Waiting for envtest to exit
--- PASS: TestVenConnClient_PostDataReadingsWithOptions (7.93s)
--- PASS: TestVenConnClient_PostDataReadingsWithOptions/valid_accessToken (2.35s)
--- PASS: TestVenConnClient_PostDataReadingsWithOptions/error_when_the_apiKey_field_is_used (0.27s)
--- PASS: TestVenConnClient_PostDataReadingsWithOptions/error_when_the_tpp_field_is_used (0.27s)
PASS
ok github.com/jetstack/preflight/pkg/client 7.958s
Signed-off-by: Richard Wall <richard.wall@venafi.com>
…rt values documentation. Signed-off-by: Richard Wall <richard.wall@venafi.com>
ec8af5f
to
fcca2f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client-go uses the global klog
functions rather than the logger from the context. I didn't realise that when I started this PR and in hindsight the introduction of DebugWrappers could be split into a separate PR.
I'm OK with these having these two seemingly unrelated changes (debug roundtripper + pass context down to Venafi clients) since it aims to the same thing: logging HTTP requests for the Venafi client and the Kubernetes client.
Excellent! We will have a much easier way to debug customer issues with I have looked at the changes and they look OK to me. I have not tried the feature locally since you showed everything I needed in the PR description. |
Maybe one note: client-go seems to be forcing
|
--log-level=6
.go run . agent --install-namespace venafi --one-shot --input-path out.json --venafi-connection venafi-components -v6