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()
|
typ := cfg.Name()
|
||||||
d, err := cfg.NewDiscoverer(discovery.DiscovererOptions{
|
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 {
|
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++
|
failed++
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,11 +428,11 @@ func (m *Manager) registerProviders(cfgs Configs, setName string) int {
|
||||||
}
|
}
|
||||||
typ := cfg.Name()
|
typ := cfg.Name()
|
||||||
d, err := cfg.NewDiscoverer(DiscovererOptions{
|
d, err := cfg.NewDiscoverer(DiscovererOptions{
|
||||||
Logger: log.With(m.logger, "discovery", typ),
|
Logger: log.With(m.logger, "discovery", typ, "config", setName),
|
||||||
HTTPClientOptions: m.httpOpts,
|
HTTPClientOptions: m.httpOpts,
|
||||||
})
|
})
|
||||||
if err != nil {
|
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++
|
failed++
|
||||||
return
|
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
|
# The information to access the Nomad API. It is to be defined
|
||||||
# as the Nomad documentation requires.
|
# as the Nomad documentation requires.
|
||||||
[ allow_stale: <boolean> | default = true ]
|
[ allow_stale: <boolean> | default = true ]
|
||||||
[ datacenter: <string> ]
|
|
||||||
[ namespace: <string> | default = default ]
|
[ namespace: <string> | default = default ]
|
||||||
[ refresh_interval: <duration> | default = 60s ]
|
[ refresh_interval: <duration> | default = 60s ]
|
||||||
[ region: <string> | default = global ]
|
[ region: <string> | default = global ]
|
||||||
|
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
|
@ -917,8 +916,7 @@ type scrapeCache struct {
|
||||||
series map[string]*cacheEntry
|
series map[string]*cacheEntry
|
||||||
|
|
||||||
// Cache of dropped metric strings and their iteration. The iteration must
|
// 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
|
// be a pointer so we can update it.
|
||||||
// string in addDropped().
|
|
||||||
droppedSeries map[string]*uint64
|
droppedSeries map[string]*uint64
|
||||||
|
|
||||||
// seriesCur and seriesPrev store the labels of series that were seen
|
// 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) {
|
func (c *scrapeCache) get(met []byte) (*cacheEntry, bool) {
|
||||||
e, ok := c.series[met]
|
e, ok := c.series[string(met)]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
@ -1015,20 +1013,20 @@ func (c *scrapeCache) get(met string) (*cacheEntry, bool) {
|
||||||
return e, true
|
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 {
|
if ref == 0 {
|
||||||
return
|
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
|
iter := c.iter
|
||||||
c.droppedSeries[met] = &iter
|
c.droppedSeries[string(met)] = &iter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *scrapeCache) getDropped(met string) bool {
|
func (c *scrapeCache) getDropped(met []byte) bool {
|
||||||
iterp, ok := c.droppedSeries[met]
|
iterp, ok := c.droppedSeries[string(met)]
|
||||||
if ok {
|
if ok {
|
||||||
*iterp = c.iter
|
*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) {
|
func (c *scrapeCache) setType(metric []byte, t textparse.MetricType) {
|
||||||
c.metaMtx.Lock()
|
c.metaMtx.Lock()
|
||||||
|
|
||||||
e, ok := c.metadata[yoloString(metric)]
|
e, ok := c.metadata[string(metric)]
|
||||||
if !ok {
|
if !ok {
|
||||||
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
||||||
c.metadata[string(metric)] = e
|
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) {
|
func (c *scrapeCache) setHelp(metric, help []byte) {
|
||||||
c.metaMtx.Lock()
|
c.metaMtx.Lock()
|
||||||
|
|
||||||
e, ok := c.metadata[yoloString(metric)]
|
e, ok := c.metadata[string(metric)]
|
||||||
if !ok {
|
if !ok {
|
||||||
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
||||||
c.metadata[string(metric)] = e
|
c.metadata[string(metric)] = e
|
||||||
}
|
}
|
||||||
if e.Help != yoloString(help) {
|
if e.Help != string(help) {
|
||||||
e.Help = string(help)
|
e.Help = string(help)
|
||||||
e.lastIterChange = c.iter
|
e.lastIterChange = c.iter
|
||||||
}
|
}
|
||||||
|
@ -1086,12 +1084,12 @@ func (c *scrapeCache) setHelp(metric, help []byte) {
|
||||||
func (c *scrapeCache) setUnit(metric, unit []byte) {
|
func (c *scrapeCache) setUnit(metric, unit []byte) {
|
||||||
c.metaMtx.Lock()
|
c.metaMtx.Lock()
|
||||||
|
|
||||||
e, ok := c.metadata[yoloString(metric)]
|
e, ok := c.metadata[string(metric)]
|
||||||
if !ok {
|
if !ok {
|
||||||
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
e = &metaEntry{Metadata: metadata.Metadata{Type: textparse.MetricTypeUnknown}}
|
||||||
c.metadata[string(metric)] = e
|
c.metadata[string(metric)] = e
|
||||||
}
|
}
|
||||||
if e.Unit != yoloString(unit) {
|
if e.Unit != string(unit) {
|
||||||
e.Unit = string(unit)
|
e.Unit = string(unit)
|
||||||
e.lastIterChange = c.iter
|
e.lastIterChange = c.iter
|
||||||
}
|
}
|
||||||
|
@ -1509,7 +1507,7 @@ func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string,
|
||||||
|
|
||||||
sl.cache.metaMtx.Lock()
|
sl.cache.metaMtx.Lock()
|
||||||
defer sl.cache.metaMtx.Unlock()
|
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) {
|
if metaOk && (isNewSeries || metaEntry.lastIterChange == sl.cache.iter) {
|
||||||
metadataChanged = true
|
metadataChanged = true
|
||||||
meta.Type = metaEntry.Type
|
meta.Type = metaEntry.Type
|
||||||
|
@ -1584,14 +1582,13 @@ loop:
|
||||||
meta = metadata.Metadata{}
|
meta = metadata.Metadata{}
|
||||||
metadataChanged = false
|
metadataChanged = false
|
||||||
|
|
||||||
if sl.cache.getDropped(yoloString(met)) {
|
if sl.cache.getDropped(met) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ce, ok := sl.cache.get(yoloString(met))
|
ce, ok := sl.cache.get(met)
|
||||||
var (
|
var (
|
||||||
ref storage.SeriesRef
|
ref storage.SeriesRef
|
||||||
lset labels.Labels
|
lset labels.Labels
|
||||||
mets string
|
|
||||||
hash uint64
|
hash uint64
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1602,7 +1599,7 @@ loop:
|
||||||
// Update metadata only if it changed in the current iteration.
|
// Update metadata only if it changed in the current iteration.
|
||||||
updateMetadata(lset, false)
|
updateMetadata(lset, false)
|
||||||
} else {
|
} else {
|
||||||
mets = p.Metric(&lset)
|
p.Metric(&lset)
|
||||||
hash = lset.Hash()
|
hash = lset.Hash()
|
||||||
|
|
||||||
// Hash label set as it is seen local to the target. Then add target labels
|
// 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.
|
// The label set may be set to empty to indicate dropping.
|
||||||
if lset.IsEmpty() {
|
if lset.IsEmpty() {
|
||||||
sl.cache.addDropped(mets)
|
sl.cache.addDropped(met)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1656,7 +1653,7 @@ loop:
|
||||||
// Bypass staleness logic if there is an explicit timestamp.
|
// Bypass staleness logic if there is an explicit timestamp.
|
||||||
sl.cache.trackStaleness(hash, lset)
|
sl.cache.trackStaleness(hash, lset)
|
||||||
}
|
}
|
||||||
sl.cache.addRef(mets, ref, lset, hash)
|
sl.cache.addRef(met, ref, lset, hash)
|
||||||
if sampleAdded && sampleLimitErr == nil {
|
if sampleAdded && sampleLimitErr == nil {
|
||||||
seriesAdded++
|
seriesAdded++
|
||||||
}
|
}
|
||||||
|
@ -1721,10 +1718,6 @@ loop:
|
||||||
return
|
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,
|
// 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.
|
// 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) {
|
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
|
// The constants are suffixed with the invalid \xff unicode rune to avoid collisions
|
||||||
// with scraped metrics in the cache.
|
// with scraped metrics in the cache.
|
||||||
const (
|
var (
|
||||||
scrapeHealthMetricName = "up" + "\xff"
|
scrapeHealthMetricName = []byte("up" + "\xff")
|
||||||
scrapeDurationMetricName = "scrape_duration_seconds" + "\xff"
|
scrapeDurationMetricName = []byte("scrape_duration_seconds" + "\xff")
|
||||||
scrapeSamplesMetricName = "scrape_samples_scraped" + "\xff"
|
scrapeSamplesMetricName = []byte("scrape_samples_scraped" + "\xff")
|
||||||
samplesPostRelabelMetricName = "scrape_samples_post_metric_relabeling" + "\xff"
|
samplesPostRelabelMetricName = []byte("scrape_samples_post_metric_relabeling" + "\xff")
|
||||||
scrapeSeriesAddedMetricName = "scrape_series_added" + "\xff"
|
scrapeSeriesAddedMetricName = []byte("scrape_series_added" + "\xff")
|
||||||
scrapeTimeoutMetricName = "scrape_timeout_seconds" + "\xff"
|
scrapeTimeoutMetricName = []byte("scrape_timeout_seconds" + "\xff")
|
||||||
scrapeSampleLimitMetricName = "scrape_sample_limit" + "\xff"
|
scrapeSampleLimitMetricName = []byte("scrape_sample_limit" + "\xff")
|
||||||
scrapeBodySizeBytesMetricName = "scrape_body_size_bytes" + "\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) {
|
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
|
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)
|
ce, ok := sl.cache.get(s)
|
||||||
var ref storage.SeriesRef
|
var ref storage.SeriesRef
|
||||||
var lset labels.Labels
|
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
|
// The constants are suffixed with the invalid \xff unicode rune to avoid collisions
|
||||||
// with scraped metrics in the cache.
|
// with scraped metrics in the cache.
|
||||||
// We have to drop it when building the actual metric.
|
// 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)
|
lset = sl.reportSampleMutator(lset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1586,21 +1586,21 @@ func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) {
|
||||||
|
|
||||||
fakeRef := storage.SeriesRef(1)
|
fakeRef := storage.SeriesRef(1)
|
||||||
expValue := float64(1)
|
expValue := float64(1)
|
||||||
metric := `metric{n="1"} 1`
|
metric := []byte(`metric{n="1"} 1`)
|
||||||
p, warning := textparse.New([]byte(metric), "")
|
p, warning := textparse.New(metric, "")
|
||||||
require.NoError(t, warning)
|
require.NoError(t, warning)
|
||||||
|
|
||||||
var lset labels.Labels
|
var lset labels.Labels
|
||||||
p.Next()
|
p.Next()
|
||||||
mets := p.Metric(&lset)
|
p.Metric(&lset)
|
||||||
hash := lset.Hash()
|
hash := lset.Hash()
|
||||||
|
|
||||||
// Create a fake entry in the cache
|
// Create a fake entry in the cache
|
||||||
sl.cache.addRef(mets, fakeRef, lset, hash)
|
sl.cache.addRef(metric, fakeRef, lset, hash)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
slApp := sl.appender(context.Background())
|
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, err)
|
||||||
require.NoError(t, slApp.Commit())
|
require.NoError(t, slApp.Commit())
|
||||||
|
|
||||||
|
|
|
@ -76,10 +76,7 @@ func TestChunkSeriesSetToSeriesSet(t *testing.T) {
|
||||||
samples []tsdbutil.Sample
|
samples []tsdbutil.Sample
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
lbs: labels.Labels{
|
lbs: labels.FromStrings("__name__", "up", "instance", "localhost:8080"),
|
||||||
{Name: "__name__", Value: "up"},
|
|
||||||
{Name: "instance", Value: "localhost:8080"},
|
|
||||||
},
|
|
||||||
samples: []tsdbutil.Sample{
|
samples: []tsdbutil.Sample{
|
||||||
sample{t: 1, v: 1},
|
sample{t: 1, v: 1},
|
||||||
sample{t: 2, v: 2},
|
sample{t: 2, v: 2},
|
||||||
|
@ -87,10 +84,7 @@ func TestChunkSeriesSetToSeriesSet(t *testing.T) {
|
||||||
sample{t: 4, v: 4},
|
sample{t: 4, v: 4},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
lbs: labels.Labels{
|
lbs: labels.FromStrings("__name__", "up", "instance", "localhost:8081"),
|
||||||
{Name: "__name__", Value: "up"},
|
|
||||||
{Name: "instance", Value: "localhost:8081"},
|
|
||||||
},
|
|
||||||
samples: []tsdbutil.Sample{
|
samples: []tsdbutil.Sample{
|
||||||
sample{t: 1, v: 2},
|
sample{t: 1, v: 2},
|
||||||
sample{t: 2, v: 3},
|
sample{t: 2, v: 3},
|
||||||
|
|
|
@ -590,9 +590,9 @@ func (a *HistogramAppender) Recode(
|
||||||
return hc, app
|
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.
|
// (positive and/or negative) buckets used.
|
||||||
func (a *HistogramAppender) RecodeHistogramm(
|
func (a *HistogramAppender) RecodeHistogram(
|
||||||
h *histogram.Histogram,
|
h *histogram.Histogram,
|
||||||
pBackwardInter, nBackwardInter []Interjection,
|
pBackwardInter, nBackwardInter []Interjection,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -1179,7 +1179,7 @@ func (s *memSeries) appendHistogram(t int64, h *histogram.Histogram, appendID ui
|
||||||
if len(pBackwardInter)+len(nBackwardInter) > 0 {
|
if len(pBackwardInter)+len(nBackwardInter) > 0 {
|
||||||
h.PositiveSpans = pMergedSpans
|
h.PositiveSpans = pMergedSpans
|
||||||
h.NegativeSpans = nMergedSpans
|
h.NegativeSpans = nMergedSpans
|
||||||
app.RecodeHistogramm(h, pBackwardInter, nBackwardInter)
|
app.RecodeHistogram(h, pBackwardInter, nBackwardInter)
|
||||||
}
|
}
|
||||||
// We have 3 cases here
|
// We have 3 cases here
|
||||||
// - !okToAppend -> We need to cut a new chunk.
|
// - !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.chunksRemoved.Add(float64(len(mSeries.mmappedChunks)))
|
||||||
h.metrics.chunks.Add(float64(len(mmc) + len(oooMmc) - len(mSeries.mmappedChunks)))
|
h.metrics.chunks.Add(float64(len(mmc) + len(oooMmc) - len(mSeries.mmappedChunks)))
|
||||||
mSeries.mmappedChunks = mmc
|
mSeries.mmappedChunks = mmc
|
||||||
mSeries.ooo = nil
|
|
||||||
if len(oooMmc) == 0 {
|
if len(oooMmc) == 0 {
|
||||||
mSeries.ooo = nil
|
mSeries.ooo = nil
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue