From 14a87d969a5e186215e5e8cbe88d87347b07a3de Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Wed, 12 Nov 2025 19:31:23 +0100 Subject: [PATCH] log debug message before uploading Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- pkg/client/client_api_token.go | 9 +++++++++ pkg/client/client_oauth.go | 9 +++++++++ pkg/client/client_venafi_cloud.go | 9 +++++++++ pkg/client/client_venconn.go | 16 +++++++++++----- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/pkg/client/client_api_token.go b/pkg/client/client_api_token.go index bc7f333d..e1ec9af5 100644 --- a/pkg/client/client_api_token.go +++ b/pkg/client/client_api_token.go @@ -11,6 +11,7 @@ import ( "time" "k8s.io/client-go/transport" + "k8s.io/klog/v2" "github.com/jetstack/preflight/api" "github.com/jetstack/preflight/pkg/version" @@ -64,6 +65,14 @@ func (c *APITokenClient) postDataReadings(ctx context.Context, orgID, clusterID return err } + klog.FromContext(ctx).V(2).Info( + "uploading data readings", + "url", filepath.Join("/api/v1/org", orgID, "datareadings", clusterID), + "cluster_id", clusterID, + "data_readings_count", len(readings), + "data_size_bytes", len(data), + ) + res, err := c.post(ctx, filepath.Join("/api/v1/org", orgID, "datareadings", clusterID), bytes.NewBuffer(data)) if err != nil { return err diff --git a/pkg/client/client_oauth.go b/pkg/client/client_oauth.go index 4ea65aff..5cc1e64f 100644 --- a/pkg/client/client_oauth.go +++ b/pkg/client/client_oauth.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/go-multierror" "k8s.io/client-go/transport" + "k8s.io/klog/v2" "github.com/jetstack/preflight/api" "github.com/jetstack/preflight/pkg/version" @@ -119,6 +120,14 @@ func (c *OAuthClient) postDataReadings(ctx context.Context, orgID, clusterID str return err } + klog.FromContext(ctx).V(2).Info( + "uploading data readings", + "url", filepath.Join("/api/v1/org", orgID, "datareadings", clusterID), + "cluster_id", clusterID, + "data_readings_count", len(readings), + "data_size_bytes", len(data), + ) + res, err := c.post(ctx, filepath.Join("/api/v1/org", orgID, "datareadings", clusterID), bytes.NewBuffer(data)) if err != nil { return err diff --git a/pkg/client/client_venafi_cloud.go b/pkg/client/client_venafi_cloud.go index 7e4a30d8..405c65a9 100644 --- a/pkg/client/client_venafi_cloud.go +++ b/pkg/client/client_venafi_cloud.go @@ -28,6 +28,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/microcosm-cc/bluemonday" "k8s.io/client-go/transport" + "k8s.io/klog/v2" "github.com/jetstack/preflight/api" "github.com/jetstack/preflight/pkg/version" @@ -205,6 +206,14 @@ func (c *VenafiCloudClient) PostDataReadingsWithOptions(ctx context.Context, rea } venafiCloudUploadURL.RawQuery = query.Encode() + klog.FromContext(ctx).V(2).Info( + "uploading data readings", + "url", venafiCloudUploadURL.String(), + "cluster_name", opts.ClusterName, + "data_readings_count", len(readings), + "data_size_bytes", len(data), + ) + res, err := c.post(ctx, venafiCloudUploadURL.String(), bytes.NewBuffer(data)) if err != nil { return err diff --git a/pkg/client/client_venconn.go b/pkg/client/client_venconn.go index e4fbad70..9ce0c86b 100644 --- a/pkg/client/client_venconn.go +++ b/pkg/client/client_venconn.go @@ -20,6 +20,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/rest" "k8s.io/client-go/transport" + "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client/apiutil" "github.com/jetstack/preflight/api" @@ -154,18 +155,23 @@ func (c *VenConnClient) PostDataReadingsWithOptions(ctx context.Context, reading DataGatherTime: time.Now().UTC(), DataReadings: readings, } - - encodedBody := &bytes.Buffer{} - - err = json.NewEncoder(encodedBody).Encode(payload) + data, err := json.Marshal(payload) if err != nil { return err } + klog.FromContext(ctx).V(2).Info( + "uploading data readings", + "url", fullURL(details.VCP.URL, "/v1/tlspk/upload/clusterdata/no"), + "cluster_name", opts.ClusterName, + "data_readings_count", len(readings), + "data_size_bytes", len(data), + ) + // The path parameter "no" is a dummy parameter to make the Venafi Cloud // backend happy. This parameter, named `uploaderID` in the backend, is not // actually used by the backend. - req, err := http.NewRequestWithContext(ctx, http.MethodPost, fullURL(details.VCP.URL, "/v1/tlspk/upload/clusterdata/no"), encodedBody) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, fullURL(details.VCP.URL, "/v1/tlspk/upload/clusterdata/no"), bytes.NewReader(data)) if err != nil { return err }