mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-05 21:57:09 +02:00
[REFACTOR] Scraping: Remove unnecessary yolostring calls (#16927)
Go will not allocate when reading from a map with a key cast from []byte to string. Also remove some yoloString calls in package `textparse` - call a more suitable library function. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
2c04f2d7b1
commit
d9e5748a27
@ -183,7 +183,7 @@ func (p *OpenMetricsParser) Help() ([]byte, []byte) {
|
||||
m := p.l.b[p.offsets[0]:p.offsets[1]]
|
||||
|
||||
// Replacer causes allocations. Replace only when necessary.
|
||||
if strings.IndexByte(yoloString(p.text), byte('\\')) >= 0 {
|
||||
if bytes.IndexByte(p.text, byte('\\')) >= 0 {
|
||||
// OpenMetrics always uses the Prometheus format label value escaping.
|
||||
return m, []byte(lvalReplacer.Replace(string(p.text)))
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package textparse
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -199,7 +200,7 @@ func (p *PromParser) Help() ([]byte, []byte) {
|
||||
m := p.l.b[p.offsets[0]:p.offsets[1]]
|
||||
|
||||
// Replacer causes allocations. Replace only when necessary.
|
||||
if strings.IndexByte(yoloString(p.text), byte('\\')) >= 0 {
|
||||
if bytes.IndexByte(p.text, byte('\\')) >= 0 {
|
||||
return m, []byte(helpReplacer.Replace(string(p.text)))
|
||||
}
|
||||
return m, p.text
|
||||
|
@ -1116,7 +1116,7 @@ func (c *scrapeCache) setType(mfName []byte, t model.MetricType) ([]byte, *metaE
|
||||
c.metaMtx.Lock()
|
||||
defer c.metaMtx.Unlock()
|
||||
|
||||
e, ok := c.metadata[yoloString(mfName)]
|
||||
e, ok := c.metadata[string(mfName)]
|
||||
if !ok {
|
||||
e = &metaEntry{Metadata: metadata.Metadata{Type: model.MetricTypeUnknown}}
|
||||
c.metadata[string(mfName)] = e
|
||||
@ -1133,7 +1133,7 @@ func (c *scrapeCache) setHelp(mfName, help []byte) ([]byte, *metaEntry) {
|
||||
c.metaMtx.Lock()
|
||||
defer c.metaMtx.Unlock()
|
||||
|
||||
e, ok := c.metadata[yoloString(mfName)]
|
||||
e, ok := c.metadata[string(mfName)]
|
||||
if !ok {
|
||||
e = &metaEntry{Metadata: metadata.Metadata{Type: model.MetricTypeUnknown}}
|
||||
c.metadata[string(mfName)] = e
|
||||
@ -1150,7 +1150,7 @@ func (c *scrapeCache) setUnit(mfName, unit []byte) ([]byte, *metaEntry) {
|
||||
c.metaMtx.Lock()
|
||||
defer c.metaMtx.Unlock()
|
||||
|
||||
e, ok := c.metadata[yoloString(mfName)]
|
||||
e, ok := c.metadata[string(mfName)]
|
||||
if !ok {
|
||||
e = &metaEntry{Metadata: metadata.Metadata{Type: model.MetricTypeUnknown}}
|
||||
c.metadata[string(mfName)] = e
|
||||
|
Loading…
Reference in New Issue
Block a user