Skip to content

Commit c847309

Browse files
authored
Merge pull request #744 from jetstack/add_debug_log_message
Log debug message before uploading
2 parents 14ee0dc + 14a87d9 commit c847309

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

pkg/client/client_api_token.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"k8s.io/client-go/transport"
14+
"k8s.io/klog/v2"
1415

1516
"github.com/jetstack/preflight/api"
1617
"github.com/jetstack/preflight/pkg/version"
@@ -64,6 +65,14 @@ func (c *APITokenClient) postDataReadings(ctx context.Context, orgID, clusterID
6465
return err
6566
}
6667

68+
klog.FromContext(ctx).V(2).Info(
69+
"uploading data readings",
70+
"url", filepath.Join("/api/v1/org", orgID, "datareadings", clusterID),
71+
"cluster_id", clusterID,
72+
"data_readings_count", len(readings),
73+
"data_size_bytes", len(data),
74+
)
75+
6776
res, err := c.post(ctx, filepath.Join("/api/v1/org", orgID, "datareadings", clusterID), bytes.NewBuffer(data))
6877
if err != nil {
6978
return err

pkg/client/client_oauth.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/hashicorp/go-multierror"
1616
"k8s.io/client-go/transport"
17+
"k8s.io/klog/v2"
1718

1819
"github.com/jetstack/preflight/api"
1920
"github.com/jetstack/preflight/pkg/version"
@@ -119,6 +120,14 @@ func (c *OAuthClient) postDataReadings(ctx context.Context, orgID, clusterID str
119120
return err
120121
}
121122

123+
klog.FromContext(ctx).V(2).Info(
124+
"uploading data readings",
125+
"url", filepath.Join("/api/v1/org", orgID, "datareadings", clusterID),
126+
"cluster_id", clusterID,
127+
"data_readings_count", len(readings),
128+
"data_size_bytes", len(data),
129+
)
130+
122131
res, err := c.post(ctx, filepath.Join("/api/v1/org", orgID, "datareadings", clusterID), bytes.NewBuffer(data))
123132
if err != nil {
124133
return err

pkg/client/client_venafi_cloud.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/hashicorp/go-multierror"
2929
"github.com/microcosm-cc/bluemonday"
3030
"k8s.io/client-go/transport"
31+
"k8s.io/klog/v2"
3132

3233
"github.com/jetstack/preflight/api"
3334
"github.com/jetstack/preflight/pkg/version"
@@ -205,6 +206,14 @@ func (c *VenafiCloudClient) PostDataReadingsWithOptions(ctx context.Context, rea
205206
}
206207
venafiCloudUploadURL.RawQuery = query.Encode()
207208

209+
klog.FromContext(ctx).V(2).Info(
210+
"uploading data readings",
211+
"url", venafiCloudUploadURL.String(),
212+
"cluster_name", opts.ClusterName,
213+
"data_readings_count", len(readings),
214+
"data_size_bytes", len(data),
215+
)
216+
208217
res, err := c.post(ctx, venafiCloudUploadURL.String(), bytes.NewBuffer(data))
209218
if err != nil {
210219
return err

pkg/client/client_venconn.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"k8s.io/apimachinery/pkg/types"
2121
"k8s.io/client-go/rest"
2222
"k8s.io/client-go/transport"
23+
"k8s.io/klog/v2"
2324
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
2425

2526
"github.com/jetstack/preflight/api"
@@ -154,18 +155,23 @@ func (c *VenConnClient) PostDataReadingsWithOptions(ctx context.Context, reading
154155
DataGatherTime: time.Now().UTC(),
155156
DataReadings: readings,
156157
}
157-
158-
encodedBody := &bytes.Buffer{}
159-
160-
err = json.NewEncoder(encodedBody).Encode(payload)
158+
data, err := json.Marshal(payload)
161159
if err != nil {
162160
return err
163161
}
164162

163+
klog.FromContext(ctx).V(2).Info(
164+
"uploading data readings",
165+
"url", fullURL(details.VCP.URL, "/v1/tlspk/upload/clusterdata/no"),
166+
"cluster_name", opts.ClusterName,
167+
"data_readings_count", len(readings),
168+
"data_size_bytes", len(data),
169+
)
170+
165171
// The path parameter "no" is a dummy parameter to make the Venafi Cloud
166172
// backend happy. This parameter, named `uploaderID` in the backend, is not
167173
// actually used by the backend.
168-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fullURL(details.VCP.URL, "/v1/tlspk/upload/clusterdata/no"), encodedBody)
174+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, fullURL(details.VCP.URL, "/v1/tlspk/upload/clusterdata/no"), bytes.NewReader(data))
169175
if err != nil {
170176
return err
171177
}

0 commit comments

Comments
 (0)