mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-28 18:06:34 +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
|
||||
func writeMetricsMux(ctx context.Context, w io.Writer, producers []promProducerFn) error {
|
||||
results := make(chan promProducerResult)
|
||||
w = bufio.NewWriter(w)
|
||||
bw := bufio.NewWriter(w)
|
||||
|
||||
for _, p := range producers {
|
||||
go func(fn promProducerFn) {
|
||||
|
@ -138,14 +138,15 @@ loop_producers:
|
|||
select {
|
||||
case <-ctx.Done():
|
||||
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
|
||||
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, bw.Flush())
|
||||
|
||||
return errs.ErrorOrNil()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue