mirror of
https://github.com/zitadel/zitadel.git
synced 2025-11-02 07:58:46 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user