mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-21 18:50:52 -08:00
Merge pull request #398 from grafana/krajo/merge-upstream-main
Update to prometheus/prometheus@e6f84d5 To get prometheus/prometheus#11856
This commit is contained in:
commit
fa6d2a8ede
|
@ -311,10 +311,10 @@ func (m *Manager) registerProviders(cfgs discovery.Configs, setName string) int
|
|||
}
|
||||
typ := cfg.Name()
|
||||
d, err := cfg.NewDiscoverer(discovery.DiscovererOptions{
|
||||
Logger: log.With(m.logger, "discovery", typ),
|
||||
Logger: log.With(m.logger, "discovery", typ, "config", setName),
|
||||
})
|
||||
if err != nil {
|
||||
level.Error(m.logger).Log("msg", "Cannot create service discovery", "err", err, "type", typ)
|
||||
level.Error(m.logger).Log("msg", "Cannot create service discovery", "err", err, "type", typ, "config", setName)
|
||||
failed++
|
||||
return
|
||||
}
|
||||
|
|
|
@ -428,11 +428,11 @@ func (m *Manager) registerProviders(cfgs Configs, setName string) int {
|
|||
}
|
||||
typ := cfg.Name()
|
||||
d, err := cfg.NewDiscoverer(DiscovererOptions{
|
||||
Logger: log.With(m.logger, "discovery", typ),
|
||||
Logger: log.With(m.logger, "discovery", typ, "config", setName),
|
||||
HTTPClientOptions: m.httpOpts,
|
||||
})
|
||||
if err != nil {
|
||||
level.Error(m.logger).Log("msg", "Cannot create service discovery", "err", err, "type", typ)
|
||||
level.Error(m.logger).Log("msg", "Cannot create service discovery", "err", err, "type", typ, "config", setName)
|
||||
failed++
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2418,7 +2418,6 @@ The following meta labels are available on targets during [relabeling](#relabel_
|
|||
# The information to access the Nomad API. It is to be defined
|
||||
# as the Nomad documentation requires.
|
||||
[ allow_stale: <boolean> | default = true ]
|
||||
[ datacenter: <string> ]
|
||||
[ namespace: <string> | default = default ]
|
||||
[ refresh_interval: <duration> | default = 60s ]
|
||||
[ region: <string> | default = global ]
|
||||
|
|
|
@ -27,7 +27,6 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
|
@ -917,8 +916,7 @@ type scrapeCache struct {
|
|||
series map[string]*cacheEntry
|
||||
|
||||
// Cache of dropped metric strings and their iteration. The iteration must
|
||||
// be a pointer so we can update it without setting a new entry with an unsafe
|
||||
// string in addDropped().
|
||||
// be a pointer so we can update it.
|
||||
droppedSeries map[string]*uint64
|
||||
|
||||
// seriesCur and seriesPrev store the labels of series that were seen
|
||||
|
@ -1006,8 +1004,8 @@ func (c *scrapeCache) iterDone(flushCache bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *scrapeCache) get(met string) (*cacheEntry, bool) {
|
||||
e, ok := c.series[met]
|
||||
func (c *scrapeCache) get(met []byte) (*cacheEntry, bool) {
|
||||
e, ok := c.series[string(met)]
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
@ -1015,20 +1013,20 @@ func (c *scrapeCache) get(met string) (*cacheEntry, bool) {
|
|||
return e, true
|
||||
}
|
||||
|
||||
func (c *scrapeCache) addRef(met string, ref storage.SeriesRef, lset labels.Labels, hash uint64) {
|
||||
func (c *scrapeCache) addRef(met []byte, ref storage.SeriesRef, lset labels.Labels, hash uint64) {
|
||||
if ref == 0 {
|
||||
return
|
||||
}
|
||||
c.series[met] = &cacheEntry{ref: ref, lastIter: c.iter, lset: lset, hash: hash}
|
||||
c.series[string(met)] = &cacheEntry{ref: ref, lastIter: c.iter, lset: lset, hash: hash}
|
||||
}
|
||||
|
||||
func (c *scrapeCache) addDropped(met string) {
|
||||
func (c *scrapeCache) addDropped(met []byte) {
|
||||
iter := c.iter
|
||||
c.droppedSeries[met] = &iter
|
||||
c.droppedSeries[string(met)] = &iter
|
||||
}
|
||||
|
||||
func (c *scrapeCache) getDropped(met string) bool {
|
||||
iterp, ok := c.droppedSeries[met]
|
||||
func (c *scrapeCache) getDropped(met []byte) bool {
|
||||
iterp, ok := c.droppedSeries[string(met)]
|
||||
if ok {
|
||||
*iterp = c.iter
|
||||
}
|
||||
|
@ -1052,7 +1050,7 @@ func (c *scrapeCache) forEachStale(f func(labels.Labels) bool) {
|
|||
func (c *scrapeCache) setType(metric []byte, t textparse.MetricType) {
|
||||
c.metaMtx.Lock()
|
||||
|
||||
e, ok := c.metadata[yoloString(metric)]
|
||||
e, ok := c.metadata[string(metric)]
|
||||
if !ok {
|
||||
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
||||
c.metadata[string(metric)] = e
|
||||
|
@ -1069,12 +1067,12 @@ func (c *scrapeCache) setType(metric []byte, t textparse.MetricType) {
|
|||
func (c *scrapeCache) setHelp(metric, help []byte) {
|
||||
c.metaMtx.Lock()
|
||||
|
||||
e, ok := c.metadata[yoloString(metric)]
|
||||
e, ok := c.metadata[string(metric)]
|
||||
if !ok {
|
||||
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
||||
c.metadata[string(metric)] = e
|
||||
}
|
||||
if e.Help != yoloString(help) {
|
||||
if e.Help != string(help) {
|
||||
e.Help = string(help)
|
||||
e.lastIterChange = c.iter
|
||||
}
|
||||
|
@ -1086,12 +1084,12 @@ func (c *scrapeCache) setHelp(metric, help []byte) {
|
|||
func (c *scrapeCache) setUnit(metric, unit []byte) {
|
||||
c.metaMtx.Lock()
|
||||
|
||||
e, ok := c.metadata[yoloString(metric)]
|
||||
e, ok := c.metadata[string(metric)]
|
||||
if !ok {
|
||||
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
||||
c.metadata[string(metric)] = e
|
||||
}
|
||||
if e.Unit != yoloString(unit) {
|
||||
if e.Unit != string(unit) {
|
||||
e.Unit = string(unit)
|
||||
e.lastIterChange = c.iter
|
||||
}
|
||||
|
@ -1509,7 +1507,7 @@ func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string,
|
|||
|
||||
sl.cache.metaMtx.Lock()
|
||||
defer sl.cache.metaMtx.Unlock()
|
||||
metaEntry, metaOk := sl.cache.metadata[yoloString([]byte(lset.Get(labels.MetricName)))]
|
||||
metaEntry, metaOk := sl.cache.metadata[lset.Get(labels.MetricName)]
|
||||
if metaOk && (isNewSeries || metaEntry.lastIterChange == sl.cache.iter) {
|
||||
metadataChanged = true
|
||||
meta.Type = metaEntry.Type
|
||||
|
@ -1584,14 +1582,13 @@ loop:
|
|||
meta = metadata.Metadata{}
|
||||
metadataChanged = false
|
||||
|
||||
if sl.cache.getDropped(yoloString(met)) {
|
||||
if sl.cache.getDropped(met) {
|
||||
continue
|
||||
}
|
||||
ce, ok := sl.cache.get(yoloString(met))
|
||||
ce, ok := sl.cache.get(met)
|
||||
var (
|
||||
ref storage.SeriesRef
|
||||
lset labels.Labels
|
||||
mets string
|
||||
hash uint64
|
||||
)
|
||||
|
||||
|
@ -1602,7 +1599,7 @@ loop:
|
|||
// Update metadata only if it changed in the current iteration.
|
||||
updateMetadata(lset, false)
|
||||
} else {
|
||||
mets = p.Metric(&lset)
|
||||
p.Metric(&lset)
|
||||
hash = lset.Hash()
|
||||
|
||||
// Hash label set as it is seen local to the target. Then add target labels
|
||||
|
@ -1611,7 +1608,7 @@ loop:
|
|||
|
||||
// The label set may be set to empty to indicate dropping.
|
||||
if lset.IsEmpty() {
|
||||
sl.cache.addDropped(mets)
|
||||
sl.cache.addDropped(met)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -1656,7 +1653,7 @@ loop:
|
|||
// Bypass staleness logic if there is an explicit timestamp.
|
||||
sl.cache.trackStaleness(hash, lset)
|
||||
}
|
||||
sl.cache.addRef(mets, ref, lset, hash)
|
||||
sl.cache.addRef(met, ref, lset, hash)
|
||||
if sampleAdded && sampleLimitErr == nil {
|
||||
seriesAdded++
|
||||
}
|
||||
|
@ -1721,10 +1718,6 @@ loop:
|
|||
return
|
||||
}
|
||||
|
||||
func yoloString(b []byte) string {
|
||||
return *((*string)(unsafe.Pointer(&b)))
|
||||
}
|
||||
|
||||
// Adds samples to the appender, checking the error, and then returns the # of samples added,
|
||||
// whether the caller should continue to process more samples, and any sample limit errors.
|
||||
func (sl *scrapeLoop) checkAddError(ce *cacheEntry, met []byte, tp *int64, err error, sampleLimitErr *error, appErrs *appendErrors) (bool, error) {
|
||||
|
@ -1777,15 +1770,15 @@ func (sl *scrapeLoop) checkAddExemplarError(err error, e exemplar.Exemplar, appE
|
|||
|
||||
// The constants are suffixed with the invalid \xff unicode rune to avoid collisions
|
||||
// with scraped metrics in the cache.
|
||||
const (
|
||||
scrapeHealthMetricName = "up" + "\xff"
|
||||
scrapeDurationMetricName = "scrape_duration_seconds" + "\xff"
|
||||
scrapeSamplesMetricName = "scrape_samples_scraped" + "\xff"
|
||||
samplesPostRelabelMetricName = "scrape_samples_post_metric_relabeling" + "\xff"
|
||||
scrapeSeriesAddedMetricName = "scrape_series_added" + "\xff"
|
||||
scrapeTimeoutMetricName = "scrape_timeout_seconds" + "\xff"
|
||||
scrapeSampleLimitMetricName = "scrape_sample_limit" + "\xff"
|
||||
scrapeBodySizeBytesMetricName = "scrape_body_size_bytes" + "\xff"
|
||||
var (
|
||||
scrapeHealthMetricName = []byte("up" + "\xff")
|
||||
scrapeDurationMetricName = []byte("scrape_duration_seconds" + "\xff")
|
||||
scrapeSamplesMetricName = []byte("scrape_samples_scraped" + "\xff")
|
||||
samplesPostRelabelMetricName = []byte("scrape_samples_post_metric_relabeling" + "\xff")
|
||||
scrapeSeriesAddedMetricName = []byte("scrape_series_added" + "\xff")
|
||||
scrapeTimeoutMetricName = []byte("scrape_timeout_seconds" + "\xff")
|
||||
scrapeSampleLimitMetricName = []byte("scrape_sample_limit" + "\xff")
|
||||
scrapeBodySizeBytesMetricName = []byte("scrape_body_size_bytes" + "\xff")
|
||||
)
|
||||
|
||||
func (sl *scrapeLoop) report(app storage.Appender, start time.Time, duration time.Duration, scraped, added, seriesAdded, bytes int, scrapeErr error) (err error) {
|
||||
|
@ -1861,7 +1854,7 @@ func (sl *scrapeLoop) reportStale(app storage.Appender, start time.Time) (err er
|
|||
return
|
||||
}
|
||||
|
||||
func (sl *scrapeLoop) addReportSample(app storage.Appender, s string, t int64, v float64) error {
|
||||
func (sl *scrapeLoop) addReportSample(app storage.Appender, s []byte, t int64, v float64) error {
|
||||
ce, ok := sl.cache.get(s)
|
||||
var ref storage.SeriesRef
|
||||
var lset labels.Labels
|
||||
|
@ -1872,7 +1865,7 @@ func (sl *scrapeLoop) addReportSample(app storage.Appender, s string, t int64, v
|
|||
// The constants are suffixed with the invalid \xff unicode rune to avoid collisions
|
||||
// with scraped metrics in the cache.
|
||||
// We have to drop it when building the actual metric.
|
||||
lset = labels.FromStrings(labels.MetricName, s[:len(s)-1])
|
||||
lset = labels.FromStrings(labels.MetricName, string(s[:len(s)-1]))
|
||||
lset = sl.reportSampleMutator(lset)
|
||||
}
|
||||
|
||||
|
|
|
@ -1586,21 +1586,21 @@ func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) {
|
|||
|
||||
fakeRef := storage.SeriesRef(1)
|
||||
expValue := float64(1)
|
||||
metric := `metric{n="1"} 1`
|
||||
p, warning := textparse.New([]byte(metric), "")
|
||||
metric := []byte(`metric{n="1"} 1`)
|
||||
p, warning := textparse.New(metric, "")
|
||||
require.NoError(t, warning)
|
||||
|
||||
var lset labels.Labels
|
||||
p.Next()
|
||||
mets := p.Metric(&lset)
|
||||
p.Metric(&lset)
|
||||
hash := lset.Hash()
|
||||
|
||||
// Create a fake entry in the cache
|
||||
sl.cache.addRef(mets, fakeRef, lset, hash)
|
||||
sl.cache.addRef(metric, fakeRef, lset, hash)
|
||||
now := time.Now()
|
||||
|
||||
slApp := sl.appender(context.Background())
|
||||
_, _, _, err := sl.append(slApp, []byte(metric), "", now)
|
||||
_, _, _, err := sl.append(slApp, metric, "", now)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, slApp.Commit())
|
||||
|
||||
|
|
|
@ -76,10 +76,7 @@ func TestChunkSeriesSetToSeriesSet(t *testing.T) {
|
|||
samples []tsdbutil.Sample
|
||||
}{
|
||||
{
|
||||
lbs: labels.Labels{
|
||||
{Name: "__name__", Value: "up"},
|
||||
{Name: "instance", Value: "localhost:8080"},
|
||||
},
|
||||
lbs: labels.FromStrings("__name__", "up", "instance", "localhost:8080"),
|
||||
samples: []tsdbutil.Sample{
|
||||
sample{t: 1, v: 1},
|
||||
sample{t: 2, v: 2},
|
||||
|
@ -87,10 +84,7 @@ func TestChunkSeriesSetToSeriesSet(t *testing.T) {
|
|||
sample{t: 4, v: 4},
|
||||
},
|
||||
}, {
|
||||
lbs: labels.Labels{
|
||||
{Name: "__name__", Value: "up"},
|
||||
{Name: "instance", Value: "localhost:8081"},
|
||||
},
|
||||
lbs: labels.FromStrings("__name__", "up", "instance", "localhost:8081"),
|
||||
samples: []tsdbutil.Sample{
|
||||
sample{t: 1, v: 2},
|
||||
sample{t: 2, v: 3},
|
||||
|
|
|
@ -590,9 +590,9 @@ func (a *HistogramAppender) Recode(
|
|||
return hc, app
|
||||
}
|
||||
|
||||
// RecodeHistogramm converts the current histogram (in-place) to accommodate an expansion of the set of
|
||||
// RecodeHistogram converts the current histogram (in-place) to accommodate an expansion of the set of
|
||||
// (positive and/or negative) buckets used.
|
||||
func (a *HistogramAppender) RecodeHistogramm(
|
||||
func (a *HistogramAppender) RecodeHistogram(
|
||||
h *histogram.Histogram,
|
||||
pBackwardInter, nBackwardInter []Interjection,
|
||||
) {
|
||||
|
|
|
@ -1179,7 +1179,7 @@ func (s *memSeries) appendHistogram(t int64, h *histogram.Histogram, appendID ui
|
|||
if len(pBackwardInter)+len(nBackwardInter) > 0 {
|
||||
h.PositiveSpans = pMergedSpans
|
||||
h.NegativeSpans = nMergedSpans
|
||||
app.RecodeHistogramm(h, pBackwardInter, nBackwardInter)
|
||||
app.RecodeHistogram(h, pBackwardInter, nBackwardInter)
|
||||
}
|
||||
// We have 3 cases here
|
||||
// - !okToAppend -> We need to cut a new chunk.
|
||||
|
|
|
@ -499,7 +499,6 @@ func (h *Head) resetSeriesWithMMappedChunks(mSeries *memSeries, mmc, oooMmc []*m
|
|||
h.metrics.chunksRemoved.Add(float64(len(mSeries.mmappedChunks)))
|
||||
h.metrics.chunks.Add(float64(len(mmc) + len(oooMmc) - len(mSeries.mmappedChunks)))
|
||||
mSeries.mmappedChunks = mmc
|
||||
mSeries.ooo = nil
|
||||
if len(oooMmc) == 0 {
|
||||
mSeries.ooo = nil
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue