fix(service ping): log body size of reports (#10686)

# Which Problems Are Solved

The current service ping reports can run into body size limit errors and
there's no way of knowing how big the current size is.

# How the Problems Are Solved

Log the current size to have at least some insights and possibly change
bulk size.

# Additional Changes

None

# Additional Context

- noticed internally
- backport to v4.x

(cherry picked from commit bc471b4f78)
This commit is contained in:
Livio Spring
2025-09-16 09:04:17 +02:00
parent bb6accc60d
commit 07887487b5
3 changed files with 30 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import (
"io"
"net/http"
"github.com/zitadel/logging"
"google.golang.org/grpc"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
@@ -22,6 +23,7 @@ import (
const (
pathBaseInformation = "/instances"
pathResourceCounts = "/resource_counts"
maxSize = 1024 * 1024 // 1MB
)
type Client struct {
@@ -52,6 +54,7 @@ func (c Client) callTelemetryService(ctx context.Context, path string, in proto.
if err != nil {
return err
}
logBodySize(len(requestBody), path)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.endpoint+path, bytes.NewReader(requestBody))
if err != nil {
return err
@@ -80,6 +83,21 @@ func (c Client) callTelemetryService(ctx context.Context, path string, in proto.
}.Unmarshal(body, out)
}
func logBodySize(requestBodySize int, path string) {
percentage := requestBodySize * 100 / maxSize
requestLog := logging.WithFields("body size", requestBodySize, "path", path, "max size", maxSize, "percentage", percentage)
if percentage >= 100 {
requestLog.Error("telemetry request body too large, please reduce the bulk size")
return
}
if percentage >= 80 {
requestLog.Warning("telemetry request body size approaching limit, please consider reducing the bulk size")
return
}
requestLog.Info("telemetry request body size")
}
func NewClient(config *Config) Client {
return Client{
httpClient: http.DefaultClient,