Skip to content

Commit

Permalink
expfmt/encoder: Allow opt-in for OM created lines
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Silva Sens <[email protected]>
  • Loading branch information
Arthur Silva Sens committed Feb 2, 2024
1 parent b3430de commit 4e141fb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions expfmt/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ func NegotiateIncludingOpenMetrics(h http.Header) Format {
// for FmtOpenMetrics, but a future (breaking) release will add the Close method
// to the Encoder interface directly. The current version of the Encoder
// interface is kept for backwards compatibility.
func NewEncoder(w io.Writer, format Format) Encoder {
//
// NewEncoder can be called with additional options to customize the OpenMetrics text output.
// For example:
// NewEncoder(w, FmtOpenMetrics_1_0_0, WithCreatedLines())
//
// Extra options are ignored for all other formats.
func NewEncoder(w io.Writer, format Format, options ...ToOpenMetricsOption) Encoder {
switch format {
case FmtProtoDelim:
return encoderCloser{
Expand Down Expand Up @@ -153,7 +159,7 @@ func NewEncoder(w io.Writer, format Format) Encoder {
case FmtOpenMetrics_0_0_1, FmtOpenMetrics_1_0_0:
return encoderCloser{
encode: func(v *dto.MetricFamily) error {
_, err := MetricFamilyToOpenMetrics(w, v)
_, err := MetricFamilyToOpenMetrics(w, v, options...)
return err
},
close: func() error {
Expand Down

0 comments on commit 4e141fb

Please sign in to comment.