Commit Graph

478 Commits

Author SHA1 Message Date
Bryan Boreham
d9e5748a27
[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>
2025-07-28 14:54:32 +01:00
socialsister
869c946370 chore: fix some minor issues in comments
Signed-off-by: socialsister <seekseat@qq.com>
2025-07-16 11:24:42 +01:00
vanshika
0fc5e75504
scraping: Create a span and send the traceparent header during scrape requests (#16425)
* Traceparent header

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>
(cherry picked from commit 44a620dd73)
Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

* changes

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>
(cherry picked from commit 6e98a77b2d)
Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

* adding test

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>
(cherry picked from commit 97f288ad87)
Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

* more changes

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>
(cherry picked from commit d5dd861544)
Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

* extract http client creation to newScrapeClient

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>
(cherry picked from commit 3cd8092b155df069d02d9409b6327fe60c788bec)
Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

* rebase

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

* rebase

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

* reverting

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

* ctx

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>

---------

Signed-off-by: Vanshikav123 <vanshikav928@gmail.com>
2025-07-15 09:37:24 +02:00
Yandi Lee
8eb445b8a4
Discovery.Manager: close sync ch after sender() is stopped (#14465)
* close sync ch after sender() is stopped
* break if chan is closed

Signed-off-by: liyandi <littlepangdi@163.com>
Co-authored-by: liyandi <liyandi@xiaomi.com>
2025-07-11 17:15:01 +01:00
George Krajcsovits
dae80e66a5
test(scrape): make nhcb scrape test more tolerant (#16862)
Fixes #16689
well, maybe not 100%, but should improve it.

Increase the scrape timeout to be more tolerant of slow test and
also use eventually when checking for targets.

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
2025-07-11 12:09:53 +02:00
Arve Knudsen
5a5424cbc1
Consolidate around prometheus/common/model.ValidationScheme (#16806)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2025-07-03 15:37:46 +02:00
Łukasz Mierzwa
748fe6d825
Limit concurrency of scrape pool reloads (#16783)
To avoid possible overload.

As per https://github.com/prometheus/prometheus/pull/16595#issuecomment-3005027067 this changes scrape pool manager to limit the number of scrape pools that can reload at the same time.

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>
2025-06-27 12:34:07 +01:00
Owen Williams
aa1d46a9da
scrape: set validation and escaping defaults in default config vars (#16751)
Fixes https://github.com/prometheus/prometheus/issues/16750

Signed-off-by: Owen Williams <owen.williams@grafana.com>
2025-06-25 11:14:13 -04:00
Carrie Edwards
7289d41940
Add tests for relabeling of type and unit labels (#16743)
Signed-off-by: Carrie Edwards <edwrdscarrie@gmail.com>
2025-06-23 16:42:38 +01:00
Łukasz Mierzwa
c528293376
Enhancement: Reload all scrape pools concurrently (#16595)
* Reload all scrape pools concurrently

At the moment all scrape pools that need to be reloaded are reloaded one by one. While reloads are ongoing mtxScrape is locked.
For each pool that's being reloaded we need to wait until all targets are updated.
This whole process can take a while and the more scrape pools to reload the longer.
At the same time all pools are independent and there's no real reason to do them one-by-one.
Reload each pool in a seperate goroutine so we finish config reload as ASAP as possible and unlock the mtxScrape.

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>

* Address PR review feedback

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>

---------

Signed-off-by: Lukasz Mierzwa <l.mierzwa@gmail.com>
2025-06-09 16:01:35 +02:00
Bartlomiej Plotka
8e6b008608
feature: type-and-unit-labels (PROM-39 implementation) (#16228)
* feature: type-and-unit-labels (extended MetricIdentity)

Experimental implementation of https://github.com/prometheus/proposals/pull/39

Previous (unmerged) experiments:
* https://github.com/prometheus/prometheus/compare/main...dashpole:prometheus:type_and_unit_labels
* https://github.com/prometheus/prometheus/pull/16025

Signed-off-by: bwplotka <bwplotka@gmail.com>

feature: type-and-unit-labels (extended MetricIdentity)

Experimental implementation of https://github.com/prometheus/proposals/pull/39

Previous (unmerged) experiments:
* https://github.com/prometheus/prometheus/compare/main...dashpole:prometheus:type_and_unit_labels
* https://github.com/prometheus/prometheus/pull/16025

Signed-off-by: bwplotka <bwplotka@gmail.com>

* Fix compilation errors

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>

Lint

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>

Revert change made to protobuf 'Accept' header

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>

Fix compilation errors for 'dedupelabels' tag

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>

* Rectored into schema.Metadata

Signed-off-by: bwplotka <bwplotka@gmail.com>

* texparse: Added tests for PromParse

Signed-off-by: bwplotka <bwplotka@gmail.com>

* add OM tests.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* add proto tests

Signed-off-by: bwplotka <bwplotka@gmail.com>

* Addressed comments.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* add schema label tests.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* addressed comments.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* fix tests.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* add promql tests.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* lint

Signed-off-by: bwplotka <bwplotka@gmail.com>

* Addressed comments.

Signed-off-by: bwplotka <bwplotka@gmail.com>

---------

Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
Co-authored-by: Arthur Silva Sens <arthursens2005@gmail.com>
2025-05-17 09:37:25 +00:00
George Krajcsovits
2726a18ae3
Merge pull request #16452 from chardch/global-always-scrape-classic-hist
Add global config option for always_scrape_classic_histograms
2025-05-06 09:29:30 +02:00
chardch
a1c157aaef Add global config option for always_scrape_classic_histograms
Addresses https://github.com/prometheus/prometheus/issues/16371
This will help with migrating to native histograms with `convert_classic_histograms_to_nhcb` since users may still need to keep the classic histograms during a migration

Signed-off-by: chardch <otwordsne@gmail.com>
2025-05-05 10:14:04 -07:00
Arve Knudsen
e7e3ab2824
Fix linting issues found by golangci-lint v2.0.2 (#16368)
* Fix linting issues found by golangci-lint v2.0.2

---------

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2025-05-03 19:05:13 +02:00
chardch
357b5ed640 Fix small issues and clarify documentation
Signed-off-by: chardch <otwordsne@gmail.com>
2025-03-29 08:35:11 -07:00
chardch
2f59d38054 Add global config option for convert_classic_histograms_to_nhcb
Addresses the global part of https://github.com/prometheus/prometheus/issues/13532

Signed-off-by: chardch <otwordsne@gmail.com>
2025-03-27 10:55:27 -07:00
Owen Williams
6566c5a2b3
scrape: Add config option for escaping scheme request. (#16066)
The new metric_name_escaping_scheme config option works in parallel with metric_name_validation_scheme and controls which escaping scheme is requested when scraping. When not specified, the scheme will request underscores if the validation scheme is set to legacy, and will request allow-utf-8 when the validation scheme is set to utf8. This setting allows users to allow utf8 names if they like, but explicitly request an escaping scheme rather than UTF-8.

Fixes https://github.com/prometheus/prometheus/issues/16034

Built on https://github.com/prometheus/prometheus/pull/16080

Signed-off-by: Owen Williams <owen.williams@grafana.com>
2025-03-26 18:27:28 -04:00
Matthieu MOREL
5fa1146e21
chore: enable gci linter (#16245)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-03-22 15:46:13 +00:00
György Krajcsovits
fec2f2603a fix(scrape): skip native histogram series if ingestion is disabled
No need to validate, track, add sample, add exemplar if series isn't
going to be ingested. Basically this is the same as if this series was
dropped by relabelling.

Fixes #16217

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
2025-03-17 14:48:09 +01:00
Owen Williams
94b43c5d4c utf8: Remove support for legacy global validation setting
Global and Data Source configurations can specify legacy mode, but Prometheus now requires that the overall validation mode be set to UTF-8

Signed-off-by: Owen Williams <owen.williams@grafana.com>
2025-03-13 10:47:24 -04:00
MarkDaveny
53be282396 refactor: use slices.Equal to simplify code
Signed-off-by: MarkDaveny <peicuiping@aliyun.com>
2025-03-10 15:25:22 +01:00
Bryan Boreham
e32d89af7f
[BUGFIX] Scraping: bump cache iteration after error (#16174)
We use the cache iteration number to detect when the same metric has
occurred twice in a scrape. We need to bump this number at the end of
every scrape, not just successful scrapes.

The `iter` number is also used:
* After a successful scrape, to delete older metrics and metadata.
* To detect when metadata changed in this scrape.

None of those additional cases is broken by incrementing the number
on error.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2025-03-08 18:45:37 +00:00
Bartlomiej Plotka
dc85d677d8
textparse: Optimize CreatedTimestamp; It returns int64 value now. (#16072)
..instead of *int64. This is as an optimization and ease of use. We already
accepted in many places (proto histograms, PRW) that CT (or any timestamp really) 0
means not set.

Signed-off-by: bwplotka <bwplotka@gmail.com>
2025-03-07 12:43:13 +00:00
boforetech
6ec89f14c7
refactor: use a more straightforward return value (#16070)
Signed-off-by: beforetech <mail@before.tech>
2025-02-24 12:25:57 +00:00
Björn Rabenstein
7bbbb5cb97
Merge pull request #16006 from mmorel-35/revive/unused-parameter
chore: enable unused-parameter from revive
2025-02-21 13:56:04 +01:00
Matt Hughes
5868e36d91 scraper: fix UTF-8 scraping header always sent with PrometheusText1.0.0
The `Accept` header should not include `escape=allow-utf-8` unless
explicitly requested.

Conveniently, there was already a test covering this header's value, it
just required updating so it also asserts that this value in the header
is not set in the cases we don't expect it to be set. I also converted
those tests into table tests to help make failures clearer.

Issue: https://github.com/prometheus/prometheus/issues/15857
Signed-off-by: Matt Hughes <mhughes@uw.co.uk>
2025-02-20 11:33:16 +00:00
Matthieu MOREL
c7d4b53ec1 chore: enable unused-parameter from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-02-19 19:50:28 +01:00
Laimis Juzeliūnas
a5ffa83be8
scrape: reorder the switch case of errors (#15991)
Change case order for switch scrapeLoop

This commit changes the ordering in error identification switch cases for better production performance and adds reasonings behind error switch case order as comments.

---------

Signed-off-by: Laimis Juzeliūnas <asnelaimis@gmail.com>
2025-02-13 14:25:50 +01:00
Bartlomiej Plotka
733a5e9eb4
textparse: Optimized protobuf parser with custom streaming unmarshal. (#15731)
* textparse: Optimized protobuf parser with custom streaming decoder.

Signed-off-by: bwplotka <bwplotka@gmail.com>

Update model/textparse/protobufparse.go

Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>

Addressing comments.

Signed-off-by: bwplotka <bwplotka@gmail.com>

decoder: reuse histograms and summaries.

Signed-off-by: bwplotka <bwplotka@gmail.com>

optimize help returning (5% of mem utilization).

Signed-off-by: bwplotka <bwplotka@gmail.com>

Apply suggestions from code review

Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>

Update prompb/io/prometheus/client/decoder.go

Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>

Fix build.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* Update model/textparse/protobufparse.go

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>

---------

Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
2025-02-13 10:38:35 +00:00
Bartlomiej Plotka
00b69efabb
model/textparse: Change parser interface Metric(...) string to Labels(...) (#16012)
* model/textparse: Change parser interface Metric(...) string to Labels(...)

Simplified the interface given no one is using the return argument.
Renamed for clarity too.

Found and discussed https://github.com/prometheus/prometheus/pull/15731#discussion_r1950916842

Signed-off-by: bwplotka <bwplotka@gmail.com>

* Fixed comments; optimized not needed copy for om and text.

Signed-off-by: bwplotka <bwplotka@gmail.com>

---------

Signed-off-by: bwplotka <bwplotka@gmail.com>
2025-02-12 15:47:56 +00:00
Bartlomiej Plotka
8cd9069cf1
textparse: Refactor benchmark testdata for all types. (#15998)
Also:
* split benchmark functions to make sure no one compares across parsers.
* testdata file have meaningful names reflecting the type representation
* promtestdata.txt now has all types, taken directly from long running Prometheus (https://demo.do.prometheus.io/)

Needed for https://github.com/prometheus/prometheus/pull/15731

Signed-off-by: bwplotka <bwplotka@gmail.com>
2025-02-10 12:26:18 +00:00
Bartlomiej Plotka
7427753922
scrape: Add realistic data case for scrape loop append bench. (#15966)
* scrape: Add realistic data case for scrape loop append bench.

Signed-off-by: bwplotka <bwplotka@gmail.com>

* Update scrape/scrape_test.go

Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>

---------

Signed-off-by: bwplotka <bwplotka@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
Co-authored-by: George Krajcsovits <krajorama@users.noreply.github.com>
2025-02-03 14:46:39 +00:00
Jan Fajerski
7f37a008c4
Merge pull request #15540 from mmorel-35/prometheus/common@v0.61.0
chore(deps): use `version.PrometheusUserAgent`
2025-01-28 13:10:48 +01:00
Jan Fajerski
54cf0d6879
Merge pull request #15472 from tjhop/ref/jsonfilelogger-slog-handler
ref: JSONFileLogger slog handler, add scrape.FailureLogger interface
2025-01-27 20:17:46 +01:00
Matthieu MOREL
dd5ab743ea chore(deps): use version.PrometheusUserAgent
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-01-22 07:31:02 +01:00
Bartlomiej Plotka
6f1ad64e27
Update scrape/scrape.go
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
2025-01-17 09:09:28 +00:00
bwplotka
3119567d5b scrape: Add metadata for automatic metrics.
Signed-off-by: bwplotka <bwplotka@gmail.com>
2025-01-16 19:49:12 +00:00
bwplotka
af928a1ba4 Addressed Krajo's comment.
Signed-off-by: bwplotka <bwplotka@gmail.com>
2025-01-16 13:15:56 +00:00
bwplotka
9385f31147 scrape: Fix metadata in WAL not working for histograms and summaries.
The was a bug (due to confusion?) on the local metadata cache that is cached
by metric family not the series metric name. The fix is to NOT use that local cache
at all (it's still needed for current metadata API implementation, added TODO
on how we can get rid of it).

I went ahead and also rename Metric field in metadata structs to MetricFamily to make
clear it's not always __name__.

Signed-off-by: bwplotka <bwplotka@gmail.com>
2025-01-15 20:12:38 +00:00
Bartlomiej Plotka
e5e8f90119
Merge pull request #15720 from prometheus/scrapebench
scrape: Improved scrape loop benchmark
2025-01-14 15:15:37 +01:00
Arve Knudsen
f030894c2c
Fix issues raised by staticcheck (#15722)
Fix issues raised by staticcheck

We are not enabling staticcheck explicitly, though, because it has too many false positives.

---------

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
2025-01-09 17:51:26 +01:00
bwplotka
281306765e scrape: Unified scrape loop benchmark.
Signed-off-by: bwplotka <bwplotka@gmail.com>
2024-12-29 15:19:06 +00:00
Bryan Boreham
bc9210e393 [TESTS] Scrape: make caching work in benchmark
Returning 0 from Append means 'unknown', so the series is never cached.

Return arbitrary numbers instead.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-12-29 15:13:47 +00:00
Bryan Boreham
b4ef38cfc8 Scraping: Add benchmark for protobuf format
Extract helper function textToProto().

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-12-29 15:13:38 +00:00
Bryan Boreham
8f4557b0b1 Scraping benchmark: more realistic test
Don't repeat type and help text.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-12-29 15:11:39 +00:00
Bryan Boreham
7b03796d0f
Scraping: stop storing discovered labels (#15261)
Instead of storing discovered labels on every target, recompute them if
required. The `Target` struct now needs to hold some more data required
to recompute them, such as ScrapeConfig.

This moves the load from every Prometheus all of the time, to just when
someone views Service Discovery in the UI.

The way `PopulateLabels` is used changes; you are no longer expected to
call it with a part-populated `labels.Builder`.

The signature of `Target.Labels` changes to take a `labels.Builder`
instead of a `ScratchBuilder`, for consistency with `DiscoveredLabels`.

This will save a lot of work when many targets are filtered out in
relabeling. Combine with `keep_dropped_targets` to avoid ever computing
most labels for dropped targets.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2024-12-21 13:33:08 +00:00
Joel Beckmeyer
39f5a07236 fix TestOOOHeadChunkReader_Chunk on 32-bit
Signed-off-by: Joel Beckmeyer <joel@beckmeyer.us>
2024-12-16 10:45:07 -05:00
David Ashpole
953a873342
update links to openmetrics to reference the v1.0.0 release
Signed-off-by: David Ashpole <dashpole@google.com>
2024-12-13 21:32:27 +00:00
bwplotka
f44bba31b3 config: Remove validation GetScrapeConfigs; require using config.Load.
We should never modify (or even shallow copy) Config after config.Load;
added comments and modified GetScrapeConfigs to do so. For GetScrapeConfigs
the validation (even repeated) was likely doing writes (because global fields was 0). We GetScrapeConfigs concurrently
in tests and ApplyConfig causing test races. In prod there were
races but likelyt only to replace 0 with 0, so not too severe.

I removed validation since I don't see anyone using our config.Config without Load.
I had to refactor one test that was doing it, all others use yaml config.

Fixes #15538
Previous attempt: https://github.com/prometheus/prometheus/pull/15634

Signed-off-by: bwplotka <bwplotka@gmail.com>
2024-12-11 13:31:01 +00:00
Bryan Boreham
c69aeabf1d
Merge pull request #15563 from GiedriusS/fix_setting_field
scrape: fix nil panic after scrape loop reload
2024-12-10 15:33:56 +00:00