core/metrics: improve memory usage (#5364)

This commit is contained in:
Denis Mishin 2024-12-03 11:17:34 -05:00 committed by GitHub
parent 1a448708fa
commit 699679bc57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 3978 additions and 101 deletions

View file

@ -0,0 +1,30 @@
package prometheus
import (
"io"
"iter"
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
)
// Export writes the metric families to the writer in text format
func Export(
w io.Writer,
src iter.Seq2[*dto.MetricFamily, error],
) error {
for mf, err := range src {
if err != nil {
return err
}
if err := exportMetricFamily(w, mf); err != nil {
return err
}
}
return nil
}
func exportMetricFamily(w io.Writer, mf *dto.MetricFamily) error {
_, err := expfmt.MetricFamilyToText(w, mf)
return err
}