mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 10:26:29 +02:00
metrics: make sure to flush buffered writer (#5398)
The writeMetricsMux() method instantiates a buffered writer but does not call Flush() after it is done writing. As a result the metrics output may be incomplete.
This commit is contained in:
parent
3d53f26d18
commit
69cb6f53de
1 changed files with 4 additions and 3 deletions
|
@ -124,7 +124,7 @@ type promProducerFn func(context.Context) promProducerResult
|
||||||
// writeMetricsMux runs producers concurrently and pipes output to destination yet avoiding data interleaving
|
// writeMetricsMux runs producers concurrently and pipes output to destination yet avoiding data interleaving
|
||||||
func writeMetricsMux(ctx context.Context, w io.Writer, producers []promProducerFn) error {
|
func writeMetricsMux(ctx context.Context, w io.Writer, producers []promProducerFn) error {
|
||||||
results := make(chan promProducerResult)
|
results := make(chan promProducerResult)
|
||||||
w = bufio.NewWriter(w)
|
bw := bufio.NewWriter(w)
|
||||||
|
|
||||||
for _, p := range producers {
|
for _, p := range producers {
|
||||||
go func(fn promProducerFn) {
|
go func(fn promProducerFn) {
|
||||||
|
@ -138,14 +138,15 @@ loop_producers:
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
err := fmt.Errorf("processed %d metric producers out of %d: %w", i, len(producers), ctx.Err())
|
err := fmt.Errorf("processed %d metric producers out of %d: %w", i, len(producers), ctx.Err())
|
||||||
errs = multierror.Append(errs, err, writePrometheusComment(w, err.Error()))
|
errs = multierror.Append(errs, err, writePrometheusComment(bw, err.Error()))
|
||||||
break loop_producers
|
break loop_producers
|
||||||
case res := <-results:
|
case res := <-results:
|
||||||
if err := writeMetricsResult(w, res); err != nil {
|
if err := writeMetricsResult(bw, res); err != nil {
|
||||||
errs = multierror.Append(errs, fmt.Errorf("%s: %w", res.name, err))
|
errs = multierror.Append(errs, fmt.Errorf("%s: %w", res.name, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
errs = multierror.Append(errs, bw.Flush())
|
||||||
|
|
||||||
return errs.ErrorOrNil()
|
return errs.ErrorOrNil()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue