@@ -27,7 +27,15 @@ import (
2727 "github.com/prometheus/prom2json/histogram"
2828)
2929
30- const acceptHeader = `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3`
30+ const (
31+ acceptHeader = `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=1.0.0;q=0.2,text/plain;version=0.0.4;q=0.1`
32+ // acceptHeaderTemplate takes the escaping scheme as its single
33+ // parameter. Note that we even add the parameter to
34+ // text/plain;version=0.0.4. This version officially does not support
35+ // escaping scheme selection, but some targets implement it anyway, so
36+ // no harm in trying.
37+ acceptHeaderTemplate = `application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;escaping=%[1]s;q=0.7,text/plain;version=1.0.0;escaping=%[1]s;q=0.2,text/plain;version=0.0.4;escaping=%[1]s;q=0.1`
38+ )
3139
3240// Family mirrors the MetricFamily proto message.
3341type Family struct {
@@ -177,12 +185,23 @@ func makeBuckets(m *dto.Metric) map[string]string {
177185// returns after all MetricFamilies have been sent. The provided transport
178186// may be nil (in which case the default Transport is used).
179187func FetchMetricFamilies (url string , ch chan <- * dto.MetricFamily , transport http.RoundTripper ) error {
188+ return FetchMetricFamiliesWithEscapingScheme (url , ch , transport , "" )
189+ }
190+
191+ // FetchMetricFamiliesWithEscapingScheme works like FetchMetricFamilies but adds
192+ // the provided string as the value of the additional 'escaping' parameter in
193+ // the accept header.
194+ func FetchMetricFamiliesWithEscapingScheme (url string , ch chan <- * dto.MetricFamily , transport http.RoundTripper , escapingScheme string ) error {
180195 req , err := http .NewRequest ("GET" , url , nil )
181196 if err != nil {
182197 close (ch )
183198 return fmt .Errorf ("creating GET request for URL %q failed: %w" , url , err )
184199 }
185- req .Header .Add ("Accept" , acceptHeader )
200+ if escapingScheme != "" {
201+ req .Header .Add ("Accept" , fmt .Sprintf (acceptHeaderTemplate , escapingScheme ))
202+ } else {
203+ req .Header .Add ("Accept" , acceptHeader )
204+ }
186205 client := http.Client {Transport : transport }
187206 resp , err := client .Do (req )
188207 if err != nil {
0 commit comments