Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/metrics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"go.uber.org/zap"
)

const timeout = 5 * time.Second
const timeout = 10 * time.Second
const maxIdleConnsPerHost = 32
const maxConnsPerHost = 32
const maxRetries = 5
Expand Down Expand Up @@ -103,15 +103,15 @@ func (c *Client) RecordEvent(ctx context.Context, params EventParams) {
idempotency := xid.New().String()
logger = logger.With(zap.String("idempotency", idempotency))

// Use a new context, we want to record events of users that are already disconnected.
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

for i := range maxRetries {
if i > 0 {
time.Sleep(time.Duration(rand.Int63n(backoffRange)*int64(i)) * time.Millisecond)
}

// Use a new context, we want to record events of users that are already disconnected.
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.url, bytes.NewReader(payload))
if err != nil {
logger.Error("failed to create metrics request", zap.Error(err))
Expand Down