MCPcopy
hub / github.com/prometheus/prometheus / append

Method append

scrape/scrape.go:1595–1903  ·  view source on GitHub ↗
(b []byte, contentType string, ts time.Time)

Source from the content-addressed store, hash-verified

1593var _ scrapeLoopAppendAdapter = &scrapeLoopAppender{}
1594
1595func (sl *scrapeLoopAppender) append(b []byte, contentType string, ts time.Time) (total, added, seriesAdded int, err error) {
1596 defTime := timestamp.FromTime(ts)
1597
1598 if len(b) == 0 {
1599 // Empty scrape. Just update the stale makers and swap the cache (but don't flush it).
1600 err = sl.updateStaleMarkers(sl.Appender, defTime)
1601 sl.cache.iterDone(false)
1602 return total, added, seriesAdded, err
1603 }
1604
1605 p, err := textparse.New(b, contentType, sl.symbolTable, textparse.ParserOptions{
1606 EnableTypeAndUnitLabels: sl.enableTypeAndUnitLabels,
1607 IgnoreNativeHistograms: !sl.enableNativeHistogramScraping,
1608 ConvertClassicHistogramsToNHCB: sl.convertClassicHistToNHCB,
1609 KeepClassicOnClassicAndNativeHistograms: sl.alwaysScrapeClassicHist,
1610 OpenMetricsSkipSTSeries: sl.enableSTZeroIngestion,
1611 FallbackContentType: sl.fallbackScrapeProtocol,
1612 })
1613 if p == nil {
1614 sl.l.Error(
1615 "Failed to determine correct type of scrape target.",
1616 "content_type", contentType,
1617 "fallback_media_type", sl.fallbackScrapeProtocol,
1618 "err", err,
1619 )
1620 return total, added, seriesAdded, err
1621 }
1622 if err != nil {
1623 sl.l.Debug(
1624 "Invalid content type on scrape, using fallback setting.",
1625 "content_type", contentType,
1626 "fallback_media_type", sl.fallbackScrapeProtocol,
1627 "err", err,
1628 )
1629 }
1630 var (
1631 appErrs = appendErrors{}
1632 sampleLimitErr error
1633 bucketLimitErr error
1634 lset labels.Labels // Escapes to heap so hoisted out of loop.
1635 e exemplar.Exemplar // Escapes to heap so hoisted out of loop.
1636 lastMeta *metaEntry
1637 lastMFName []byte
1638 )
1639
1640 exemplars := make([]exemplar.Exemplar, 0, 1)
1641
1642 // Take an appender with limits.
1643 app := appenderWithLimits(sl.Appender, sl.sampleLimit, sl.bucketLimit, sl.maxSchema)
1644
1645 defer func() {
1646 if err != nil {
1647 return
1648 }
1649 // Flush and swap the cache as the scrape was non-empty.
1650 sl.cache.iterDone(true)
1651 }()
1652

Callers

nothing calls this directly

Calls 15

FromTimeFunction · 0.92
NewFunction · 0.92
appenderWithLimitsFunction · 0.85
verifyLabelLimitsFunction · 0.85
isSeriesPartOfFamilyFunction · 0.85
updateStaleMarkersMethod · 0.80
iterDoneMethod · 0.80
setTypeMethod · 0.80
setHelpMethod · 0.80
setUnitMethod · 0.80
getDroppedMethod · 0.80
addDroppedMethod · 0.80

Tested by

no test coverage detected