Commit graph

11157 commits

Author SHA1 Message Date
Yuri Nikolic 88d9726b20 Fixing conflicts with commit 666f61a4d5 2023-03-08 16:54:40 +01:00
Yuri Nikolic d1cce20369 Fixing conflicts with commit 66da1d51fd 2023-03-08 16:52:14 +01:00
Yuri Nikolic 13c2945af0 Fixing conflicts with commit 86d3d5fec6 2023-03-08 16:48:58 +01:00
ying-jeanne cfdf2a0594
Merge pull request #447 from grafana/changeValidUntil
Rules: Increase tolerance for missed iterations on alerts
2023-03-08 10:00:07 +01:00
Ying WANG f6b8a939f9 Rules: Increase tolerance for missed iterations on alerts 2023-03-07 17:34:48 +01:00
Marco Pracucci 1e7ad0ec11
Optimized very long case insensitive alternations (#444)
* Optimized very long case insensitive alternations

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Run common regexps in BenchmarkFastRegexMatcher

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Modify BenchmarkNewFastRegexMatcher to benchmark the NewFastRegexMatcher() function

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Reduced allocations by optimizeEqualStringMatchers()

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Fixed typo in comments

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Fixed typo in test case name

Signed-off-by: Marco Pracucci <marco@pracucci.com>

---------

Signed-off-by: Marco Pracucci <marco@pracucci.com>
2023-03-02 17:20:52 +01:00
Marco Pracucci 383ea59ce1
Add TestAnalyzeRealQueries (#443)
* Add TestAnalyzeRealQueries

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Add nolint directive

Signed-off-by: Marco Pracucci <marco@pracucci.com>

---------

Signed-off-by: Marco Pracucci <marco@pracucci.com>
2023-03-01 15:50:04 +01:00
Marco Pracucci eeecfee885
Do not optimize regexps with begin/end text anchors inside (#433)
* Do not optimize regexps with being/end text anchors inside

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Explicit case for begin/end text in stringMatcherFromRegexpInternal()

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Added more test cases

Signed-off-by: Marco Pracucci <marco@pracucci.com>

---------

Signed-off-by: Marco Pracucci <marco@pracucci.com>
2023-03-01 14:50:26 +01:00
Marco Pracucci 2e0ecc013f
Fix containsStringMatcher() when the text contains multiple occurrences of a substring (#431)
Signed-off-by: Marco Pracucci <marco@pracucci.com>
2023-03-01 11:18:30 +00:00
Marco Pracucci c77900d58e
Optimized FastRegexMatcher when the regex contains a case insensitive alternation made with concats too (#430)
* Optimized FastRegexMatcher when the regex contains a case insensitive alternation made with concats too

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Do not use a pointer to hold whether the matches are case sensitive

Signed-off-by: Marco Pracucci <marco@pracucci.com>

* Improved unit tests based on review feedback

Signed-off-by: Marco Pracucci <marco@pracucci.com>

---------

Signed-off-by: Marco Pracucci <marco@pracucci.com>
2023-03-01 10:49:25 +01:00
Charles Korn d26f584bfd
Merge pull request #429 from grafana/charleskorn/fix-license-header
Correct license header in `web/api/v1/codec_test.go`.
2023-02-27 23:47:18 +11:00
Charles Korn 94d858d2f4
Correct license header in web/api/v1/codec_test.go.
This was incorrectly added as part of #428.

Signed-off-by: Charles Korn <charles.korn@grafana.com>
2023-02-27 13:34:52 +11:00
Charles Korn 819f9ae856
Merge pull request #428 from grafana/charleskorn/content-negotation-improvements
Implement fully-featured content negotiation for API requests, and allow overriding the default API codec.
2023-02-27 09:43:15 +11:00
Charles Korn 5d62640e9b
Handle case where default codec cannot encode the response.
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2023-02-24 14:47:24 +11:00
Charles Korn 374c3f4dec
Implement fully-featured content negotiation for API requests, and allow overriding the default API codec.
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2023-02-24 14:04:43 +11:00
Julien Pivotto 666f61a4d5
Merge pull request #10991 from bboreham/labels-as-string
labels.Labels: reduce memory by storing as a single string
2023-02-22 21:01:20 +01:00
Bryan Boreham 4a49ec3a25 CI: additionally run tests with 'stringlabel' tag
This checks that no code is assuming things about `labels.Labels` which
don't work with the alternate implementation.

Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2023-02-22 15:34:23 +00:00
Bryan Boreham 6136ae67e0 labels: shrink by making internals a single string
This commit adds an alternate implementation for `labels.Labels`, behind
a build tag `stringlabels`.

Instead of storing label names and values as individual strings, they
are all concatenated into one string in this format:

    [len][name0][len][value0][len][name1][len][value1]...

The lengths are varint encoded so usually a single byte.

The previous `[]string` had 24 bytes of overhead for the slice and 16
for each label name and value; this one has 16 bytes overhead plus 1
for each name and value.

In `ScratchBuilder.Overwrite` and `Labels.Hash` we use an unsafe
conversion from string to byte slice. `Overwrite` is explicitly unsafe,
but for `Hash` this is a pure performance hack.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2023-02-22 15:34:23 +00:00
Bryan Boreham 3f7ba22bde rules: two places need to call EmptyLabels
Can't assume nil is a valid value.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2023-02-22 15:14:07 +00:00
Ganesh Vernekar 66da1d51fd
Merge pull request #12003 from codesome/redundant-chunk-access
Remove unnecessary chunk fetch in Head queries
2023-02-22 12:57:38 +05:30
Ganesh Vernekar d504c950a2
Remove unnecessary chunk fetch in Head queries
`safeChunk` is only obtained from the `headChunkReader.Chunk` call where
the chunk is already fetched and stored with the `safeChunk`. So, when
getting the iterator for the `safeChunk`, we don't need to get the chunk again.

Also removed a couple of unnecessary fields from `safeChunk` as a part of this.

Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
2023-02-22 12:21:12 +05:30
Ganesh Vernekar bfcf69b4a4
Merge pull request #12004 from vishalnad/main
Observe delta in seconds prometheus_tsdb_sample_ooo_delta
2023-02-21 19:32:53 +05:30
Vishal N 96ba6831ae Observe delta in seconds prometheus_tsdb_sample_ooo_delta
Signed-off-by: Vishal Nadagouda <vishalmn1996@gmail.com>
2023-02-21 18:55:09 +05:30
Ben Kochie 86d3d5fec6
Merge pull request #11993 from prometheus/superq/bump_golangci-lint
Update golangci-lint
2023-02-20 14:29:38 +01:00
SuperQ 65e743719c
Update golangci-lint
Update to the latest release, supports Go 1.20.

Signed-off-by: SuperQ <superq@gmail.com>
2023-02-20 11:17:22 +01:00
Shan Aminzadeh 3f6f5d3357
Scope GroupBy labels to metric (#11914)
Signed-off-by: Shan Aminzadeh <shan.aminzadeh@chronosphere.io>
2023-02-17 10:23:16 +01:00
dependabot[bot] 2d588725c1
build(deps): bump bufbuild/buf-setup-action from 1.12.0 to 1.13.1 (#11922)
Bumps [bufbuild/buf-setup-action](https://github.com/bufbuild/buf-setup-action) from 1.12.0 to 1.13.1.
- [Release notes](https://github.com/bufbuild/buf-setup-action/releases)
- [Commits](https://github.com/bufbuild/buf-setup-action/compare/v1.12.0...v1.13.1)

---
updated-dependencies:
- dependency-name: bufbuild/buf-setup-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-15 10:28:04 +01:00
dependabot[bot] 94e0801f9f
build(deps): bump actions/cache from 3.2.3 to 3.2.4 (#11920)
Bumps [actions/cache](https://github.com/actions/cache) from 3.2.3 to 3.2.4.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v3.2.3...v3.2.4)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-15 10:27:44 +01:00
dependabot[bot] bb18bb3d1f
build(deps): bump golangci/golangci-lint-action from 3.3.1 to 3.4.0 (#11921)
Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.3.1 to 3.4.0.
- [Release notes](https://github.com/golangci/golangci-lint-action/releases)
- [Commits](https://github.com/golangci/golangci-lint-action/compare/v3.3.1...v3.4.0)

---
updated-dependencies:
- dependency-name: golangci/golangci-lint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-15 10:27:18 +01:00
Julien Pivotto 259bb5c692
Merge pull request #11826 from dannykopping/dannykopping/rule-eval
Pass rule details in evaluation context
2023-02-14 21:38:19 +01:00
Julien Pivotto e1679a80f3
Merge pull request #11936 from kelnage/sanitize-labels-edge-cases
Fix SanitizeLabelName for certain edge case invalid labels
2023-02-14 21:36:11 +01:00
Julien Pivotto 8a8f594b16
Merge pull request #11487 from FUSAKLA/fus-promtool-http-config
Promtool: add http config support to query commands
2023-02-14 11:18:24 +01:00
Martin Chodur f1de2cec3d fix: set the http round tripper fro promtool import command
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
2023-02-10 23:23:38 +01:00
Julien Pivotto dfd2b5340e
Merge pull request #11951 from Fish-pro/chore/httpvar
Use http constants instead of string
2023-02-10 22:44:50 +01:00
Martin Chodur 3ebe4b48db feat: add promtool http config support
Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
2023-02-10 14:53:20 +01:00
Justin Lei af1d9e01c7
Refactor tsdbutil for tests/native histograms (#11948)
* Add float histograms to ChunkFromSamplesGeneric

Signed-off-by: Justin Lei <justin.lei@grafana.com>

* Add Generate*Samples functions to tsdbutil

Signed-off-by: Justin Lei <justin.lei@grafana.com>

* PR responses

Signed-off-by: Justin Lei <justin.lei@grafana.com>

---------

Signed-off-by: Justin Lei <justin.lei@grafana.com>
2023-02-10 17:09:33 +05:30
Fish-pro 43d77f7c41 Use http constants instead of string
Signed-off-by: Fish-pro <zechun.chen@daocloud.io>
2023-02-10 10:21:05 +08:00
Ganesh Vernekar 36b04efc7b
Merge pull request #11947 from prometheus/beorn7/protobuf
protobuf: Mark repeated fields as non-nullable
2023-02-09 12:43:32 +05:30
Ganesh Vernekar ebc2b419ca
Merge pull request #11935 from charleskorn/non-nullable-bucketspans
Mark `Histogram.positive_spans` and `negative_spans` as non-nullable.
2023-02-09 12:43:05 +05:30
beorn7 1dd53843b6 protobuf: Mark repeated fields as non-nullable
Inspired by #11935, we can do it here, too.

Also, clean up indentation.

Signed-off-by: beorn7 <beorn@grafana.com>
2023-02-07 15:02:03 +01:00
Nick Moore c05ebef306
Implement SanitizeLabelName and Full variant
Rather than removing the previous implementation of SanitizeLabelName,
offer another version named SanitizeFullLabelName that achieved the
desired requirements, without breaking existing Prometheus code.

Update testing to validate correctness of new variant.

Signed-off-by: Nick Moore <nicholas.moore@grafana.com>
2023-02-03 15:28:33 +00:00
Nick Moore 758914e1fb
Fix SanitizeLabelName for certain invalid labels
SanitizeLabelName was not correctly sanitizing label names that:

1. Started with a digit (0-9)
2. Were empty

This commit changes the santization code to catch both of these edge
cases and adds new tests to validate it works correctly in them both. In
the first case, a leading digit will be replaced with an underscore, and
in the latter, the function will return a single underscore.

Signed-off-by: Nick Moore <nicholas.moore@grafana.com>
2023-02-03 08:53:10 +00:00
Charles Korn d2d23d9849
Expose QueryData so that implementations of Codec.CanEncode() can perform a type assertion against Response.Data. (#427)
Signed-off-by: Charles Korn <charles.korn@grafana.com>
2023-02-03 05:38:40 +01:00
Charles Korn 0a1de58f7e
Mark Histogram.(Positive|Negative)Spans as non-nullable.
As far as I understand it, we'd never expect to receive a nil span,
and remote.spansProtoToSpans would panic if we received a nil span.

Marking the fields as non-nullable also means the generated Golang
code doesn't use pointers for these fields, reducing allocations.

Signed-off-by: Charles Korn <charles.korn@grafana.com>
2023-02-03 13:49:22 +11:00
Julien Pivotto c70d85baed
Merge pull request #11916 from prometheus/release-2.42
Merge 2.42 to main
2023-02-02 10:17:27 +01:00
George Krajcsovits 47a690022c
Merge pull request #426 from grafana/krajo/merge-upstream-main
merge upstream main
2023-02-01 13:55:42 +01:00
György Krajcsovits 26936c4e91 Merge remote-tracking branch 'upstream/main' into krajo/merge-upstream-main
At 1f0cc09579
2023-02-01 13:35:06 +01:00
George Krajcsovits 1f0cc09579
Export single ith test histogram generation functions (#11911)
* Export single ith test histogram generation functions

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>

* Do not set counter reset hint for non-gauge histograms individually

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>

* Apply suggestions from code review

Co-authored-by: Ganesh Vernekar <ganeshvern@gmail.com>
Signed-off-by: George Krajcsovits <krajorama@users.noreply.github.com>

---------

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Signed-off-by: George Krajcsovits <krajorama@users.noreply.github.com>
Co-authored-by: Ganesh Vernekar <ganeshvern@gmail.com>
2023-02-01 16:23:38 +05:30
Charles Korn d9063441c1
Add extension point for returning different content types from API endpoints (#412)
* Add initial sketch of Codec interface.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Introduce JSON codec.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Expose Response type so that consuming applications (eg. Mimir) can implement their own Codecs.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Add sketch of what supporting different codecs could look like.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Rename fallbackCodec to defaultCodec.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Remove defaultCodec as a field on API.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Rename AddCodec() and clarify expected behaviour.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Modify TestRespond to test JsonCodec directly.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Refactor existing respond() test in preparation for content negotiation test cases.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Add tests for content negotiation.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Add missing documentation comments.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Add another test case.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Rename JsonCodec to JSONCodec.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Fix linting issue.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Fallback to JSON codec if no acceptable codec can be found for the Accept header.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

* Move custom jsoniter code into json_codec.go.

Signed-off-by: Charles Korn <charles.korn@grafana.com>

---------

Signed-off-by: Charles Korn <charles.korn@grafana.com>
2023-02-01 09:33:50 +01:00
Kemal Akkoyun 225c61122d
Cut v2.42.0 (#11912)
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2023-01-31 18:04:46 +01:00