Skip to content

Commit f34371c

Browse files
author
Arthur Silva Sens
committed
expfmt/encoder: Allow opt-in for OM created lines
Signed-off-by: Arthur Silva Sens <[email protected]>
1 parent 3f2b35b commit f34371c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

expfmt/encode.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
116116
// for FmtOpenMetrics, but a future (breaking) release will add the Close method
117117
// to the Encoder interface directly. The current version of the Encoder
118118
// interface is kept for backwards compatibility.
119-
func NewEncoder(w io.Writer, format Format) Encoder {
119+
//
120+
// NewEncoder can be called with additional options to customize the OpenMetrics text output.
121+
// For example:
122+
// NewEncoder(w, FmtOpenMetrics_1_0_0, WithCreatedLines())
123+
//
124+
// Extra options are ignored for all other formats.
125+
func NewEncoder(w io.Writer, format Format, options ...ToOpenMetricsOption) Encoder {
120126
switch format {
121127
case FmtProtoDelim:
122128
return encoderCloser{
@@ -153,7 +159,7 @@ func NewEncoder(w io.Writer, format Format) Encoder {
153159
case FmtOpenMetrics_0_0_1, FmtOpenMetrics_1_0_0:
154160
return encoderCloser{
155161
encode: func(v *dto.MetricFamily) error {
156-
_, err := MetricFamilyToOpenMetrics(w, v)
162+
_, err := MetricFamilyToOpenMetrics(w, v, options...)
157163
return err
158164
},
159165
close: func() error {

0 commit comments

Comments
 (0)