Skip to content

Commit

Permalink
Merge pull request #686 from atlassian/limit-concurrent-req-n-batch
Browse files Browse the repository at this point in the history
Limit the amount of concurrent request to `maxRequests`
  • Loading branch information
hstan authored May 24, 2024
2 parents 33ee86f + 4b017b4 commit 7ee3ac5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/backends/otlp/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Backend struct {

logger logrus.FieldLogger
client *http.Client
sem chan struct{}
}

var _ gostatsd.Backend = (*Backend)(nil)
Expand Down Expand Up @@ -65,6 +66,7 @@ func NewClientFromViper(v *viper.Viper, logger logrus.FieldLogger, pool *transpo
discarded: cfg.TimerSubtypes,
client: tc.Client,
logger: logger,
sem: make(chan struct{}, cfg.MaxRequests),
}, nil
}

Expand Down Expand Up @@ -228,7 +230,10 @@ func (c *Backend) postMetrics(ctx context.Context, resourceMetrics []data.Resour
atomic.AddUint64(&c.droppedMetrics, uint64(len(resourceMetrics)))
return err
}

c.sem <- struct{}{}
resp, err := c.client.Do(req)
<-c.sem
if err != nil {
atomic.AddUint64(&c.droppedMetrics, uint64(len(resourceMetrics)))
return err
Expand Down

0 comments on commit 7ee3ac5

Please sign in to comment.