Conversation
- Undeprecate Fmt... constants and ProtoFmt, clarifying documentation that these represent baseline Content-Types. - Export FmtOpenMetrics_2_0_0 constant. - Add Format.Version() to extract format version parameter. - Add Format.Matches() to safely compare formats while ignoring dynamic parameters (e.g. escaping scheme) and whitespace differences. - Provide DefaultAcceptedFormats, DefaultOpenMetricsAcceptedFormats, and DefaultOpenMetrics2AcceptedFormats slices for use with NegotiateAccept. - Update Negotiate and NegotiateIncludingOpenMetrics to use the new slices. Signed-off-by: bwplotka <bwplotka@gmail.com>
| // DefaultAcceptedFormats contains the standard accepted formats for Negotiate, | ||
| // ordered by preference (delimited protobuf, protobuf text, compact protobuf text, | ||
| // and Prometheus text format). | ||
| DefaultAcceptedFormats = []Format{ |
There was a problem hiding this comment.
Making these package vars makes them mutable as a side-effect ... are we worried about someone messing with these and changing the defaults? One possibility is to make them private and make public function accessors that return copies of the slice. It's kind of annoying that there's not a safe way to hand out immutable zero-cost copies of the default slice.
| // Prometheus text format). | ||
| // | ||
| // Deprecated: Use NegotiateAccept(h, FmtProtoDelim, FmtProtoText, FmtProtoCompact, FmtText) | ||
| // Deprecated: Use NegotiateAccept(h, DefaultAcceptedFormats...) |
There was a problem hiding this comment.
remind me why this function is deprecated again? Having a negotiate function that uses default accepted formats seems preferable to making people get their own copy of the default formats
Would it make sense to have a private package var for the formats for Negotiate / NegotiateIncludingOpenMetrics, a getter that returns a slice for those, and to undeprecate the Negotiate / NegotiateIncludingOpenMetrics methods and just document the equivalent calls?
var defaultAcceptedFormats = ...
func DefaultAcceptedFormats() []Format {
return slices.Clone(defaultAcceptedFormats)
}
func Negotiate(h http.Header) Format {
return NegotiateAccept(h, defaultAcceptedFormats...)
}
This PR attempts to improve the ergonomics of the
expfmtpackage without breaking backwards compatibility.Fixes: #993