Skip to content

Commit efc83ad

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 913b8f0 commit efc83ad

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
@@ -115,7 +115,13 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
115115
// for FmtOpenMetrics, but a future (breaking) release will add the Close method
116116
// to the Encoder interface directly. The current version of the Encoder
117117
// interface is kept for backwards compatibility.
118-
func NewEncoder(w io.Writer, format Format) Encoder {
118+
//
119+
// NewEncoder can be called with additional options to customize the OpenMetrics text output.
120+
// For example:
121+
// NewEncoder(w, FmtOpenMetrics_1_0_0, WithCreatedLines())
122+
//
123+
// Extra options are ignored for all other formats.
124+
func NewEncoder(w io.Writer, format Format, options ...ToOpenMetricsOption) Encoder {
119125
switch format {
120126
case FmtProtoDelim:
121127
return encoderCloser{
@@ -152,7 +158,7 @@ func NewEncoder(w io.Writer, format Format) Encoder {
152158
case FmtOpenMetrics_0_0_1, FmtOpenMetrics_1_0_0:
153159
return encoderCloser{
154160
encode: func(v *dto.MetricFamily) error {
155-
_, err := MetricFamilyToOpenMetrics(w, v)
161+
_, err := MetricFamilyToOpenMetrics(w, v, options...)
156162
return err
157163
},
158164
close: func() error {

0 commit comments

Comments
 (0)