Skip to content

Commit

Permalink
Issue prometheus#13268: fix quality value in accept header
Browse files Browse the repository at this point in the history
Signed-off-by: Kumar Kalpadiptya Roy <kalpadiptya.roy@outlook.com>
  • Loading branch information
kalpadiptyaroy committed Dec 20, 2023
1 parent 99c17b4 commit 1a1ae5b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,26 @@ var errBodySizeLimit = errors.New("body size limit exceeded")
func acceptHeader(sps []config.ScrapeProtocol) string {
var vals []string
weight := len(config.ScrapeProtocolsHeaders) + 1
normalisedWeight := normaliseWeightBetweenZeroAndOne(weight)
for _, sp := range sps {
vals = append(vals, fmt.Sprintf("%s;q=0.%d", config.ScrapeProtocolsHeaders[sp], weight))
vals = append(vals, fmt.Sprintf("%s;q=%f", config.ScrapeProtocolsHeaders[sp], normalisedWeight))
weight--
}
// Default match anything.
vals = append(vals, fmt.Sprintf("*/*;q=%d", weight))
vals = append(vals, fmt.Sprintf("*/*;q=%f", normalisedWeight))
return strings.Join(vals, ",")
}

func normaliseWeightBetweenZeroAndOne(weight int) float64 {
countDigits := 0
copy := weight
for copy > 0 {
countDigits++
copy /= 10
}
return float64(weight) / math.Pow(float64(10), float64(countDigits))
}

func acceptEncodingHeader(enableCompression bool) string {
if enableCompression {
return "gzip"
Expand Down

0 comments on commit 1a1ae5b

Please sign in to comment.