Commit graph

122 commits

Author SHA1 Message Date
Julien Pivotto 96d5a32659
Update go to 1.19, set min version to 1.18 (#11279)
* Update go to 1.19, set min version to 1.18

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>

* Update golangci-lint

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
2022-09-07 11:30:48 +02:00
Bryan Boreham 8b863c42dd
Optimise relabeling by re-using memory (#11147)
* model/relabel: Add benchmark

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* model/relabel: re-use Builder across relabels

Saves memory allocations.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* labels.Builder: allow re-use of result slice

This reduces memory allocations where the caller has a suitable slice available.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* model/relabel: re-use source values slice

To reduce memory allocations.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Unwind one change causing test failures

Restore original behaviour in PopulateLabels, where we must not overwrite the input set.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* relabel: simplify values optimisation

Use a stack-based array for up to 16 source labels, which will be the
vast majority of cases.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* lint

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2022-08-19 15:27:52 +05:30
Matthieu MOREL 0906f2eafa
refactor (promql): move from github.com/pkg/errors to 'errors' and 'fmt' (#10817)
Signed-off-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>

Co-authored-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
2022-06-08 10:47:52 +02:00
Bryan Boreham 2e2c014d52
Labels: optimise creation of signature with/without labels (#10667)
* Labels: create signature with/without labels

Instead of creating a new Labels slice then converting to signature,
go directly to the signature and save time.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Labels: refactor Builder tests

Have one test with a range of cases, and have them check the final
output rather than checking the internal structure of the Builder.

Also add a couple of cases where the value is "", which should be
interpreted as 'delete'.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Labels: add 'Keep' function to Builder

This lets us replace `Labels.WithLabels` with the more general `Builder`.

In `engine.resultMetric()` we can call `Keep()` instead of checking
and calling `Del()`.

Avoid calling `Sort()` in `Builder.Labels()` if we didn't add anything,
so that `Keep()` has the same performance as `WithLabels()`.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2022-06-07 10:08:27 +05:30
Ivo Gosemann e22b54e253 Adds day_of_year function to PromQL
Signed-off-by: Ivo Gosemann <ivo.gosemann@sap.com>
2022-05-20 14:08:34 +02:00
Julien Pivotto 9a2e93228e
Switch to grafana/regexp everywhere (#10268)
Let's have a consistent library for regexp.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2022-02-13 00:58:27 +01:00
David N Perkins 472456efde Added issue link to the comment
Signed-off-by: David N Perkins <David.N.Perkins@ibm.com>
2022-01-07 15:38:15 -05:00
David N Perkins 52662e8105 Added metric name to histogram quartile binning and associated unit test
Signed-off-by: David N Perkins <David.N.Perkins@ibm.com>
2022-01-07 15:31:37 -05:00
Matthew 7ee52bfb86
feat: linreg => slope 0 for const values (#9728)
* feat: linreg => slope 0 for const values

Signed-off-by: mtfoley <mtfoley.mae@gmail.com>
2021-11-16 00:03:22 +01:00
Thomas Jackson f0003bc0ba
Don't drop ParenExpr when creating StepInvariantExpr (#9591)
* Add test case to showcase the problem in #9590

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>

* Don't unwrap ParenExpr in newStepInvariantExpr

Fixes #9590

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>
2021-11-10 20:16:24 +05:30
beorn7 c954cd9d1d Move packages out of deprecated pkg directory
This creates a new `model` directory and moves all data-model related
packages over there:
  exemplar labels relabel rulefmt textparse timestamp value

All the others are more or less utilities and have been moved to `util`:
  gate logging modetimevfs pool runtime

Signed-off-by: beorn7 <beorn@grafana.com>
2021-11-09 08:03:10 +01:00
Mateusz Gozdek 1a6c2283a3 Format Go source files using 'gofumpt -w -s -extra'
Part of #9557

Signed-off-by: Mateusz Gozdek <mgozdekof@gmail.com>
2021-11-02 19:52:34 +01:00
darshanime 42d786f1ac use kahan summation for aggregation functions
Signed-off-by: darshanime <deathbullet@gmail.com>
2021-10-30 19:41:36 +05:30
darshanime 694b872dee address stylistic nits
Signed-off-by: darshanime <deathbullet@gmail.com>
2021-10-30 19:08:23 +05:30
darshanime a905354da3 use kahan for avg_over_time
Signed-off-by: darshanime <deathbullet@gmail.com>
2021-10-30 19:04:18 +05:30
darshanime 0a9deb9597 use kahan summation for numerical stability
Signed-off-by: darshanime <deathbullet@gmail.com>
2021-10-30 19:04:18 +05:30
Levi Harrison 4ac4e2ca4b Remove parenthesis
Signed-off-by: Levi Harrison <git@leviharrison.dev>
2021-09-15 22:47:10 -04:00
Levi Harrison 6faca22eec Add inverse hyperbolic functions
Signed-off-by: Levi Harrison <git@leviharrison.dev>
2021-09-15 22:47:10 -04:00
Levi Harrison 9c54ee0a6e Changed function comment
Signed-off-by: Levi Harrison <git@leviharrison.dev>
2021-09-15 22:47:10 -04:00
Levi Harrison 53d88fd147 Added hyperbolic trig functions
Signed-off-by: Levi Harrison <git@leviharrison.dev>
2021-09-15 22:47:10 -04:00
Levi Harrison 9fc7ba33aa Remove atan2()
Signed-off-by: Levi Harrison <git@leviharrison.dev>
2021-09-15 22:47:10 -04:00
Levi Harrison 309e020c0a Added functions
Signed-off-by: Levi Harrison <git@leviharrison.dev>
2021-09-15 22:47:09 -04:00
Darshan Chaudhary c4f2e9eec5
Add present_over_time (#9097)
* Add present_over_time

Signed-off-by: darshanime <deathbullet@gmail.com>

* Add tests for present_over_time

Signed-off-by: darshanime <deathbullet@gmail.com>

* Address PR comments

Signed-off-by: darshanime <deathbullet@gmail.com>

* Add documentation for present_over_time

Signed-off-by: darshanime <deathbullet@gmail.com>

* Update documentation

Signed-off-by: darshanime <deathbullet@gmail.com>

* Update documentation comment

Signed-off-by: darshanime <deathbullet@gmail.com>
2021-07-29 12:38:11 +02:00
songjiayang 776c2b8f42 Speed delta value without loop to calculate resultValue
Signed-off-by: songjiayang <songjiayang1@gmail.com>
2021-02-23 22:28:04 +08:00
pschou aff3c702ab
promql: Add sgn, clamp and last_over_time functions (#8457)
* Add sgn, clamp and last_over_time functions

Signed-off-by: schou <pschou@users.noreply.github.com>
2021-02-20 16:34:52 +01:00
Ganesh Vernekar 9199fcb8d1
'@ <timestamp>' modifier (#8121)
This commit adds `@ <timestamp>` modifier as per this design doc: https://docs.google.com/document/d/1uSbD3T2beM-iX4-Hp7V074bzBRiRNlqUdcWP6JTDQSs/edit.

An example query:

```
rate(process_cpu_seconds_total[1m]) 
  and
topk(7, rate(process_cpu_seconds_total[1h] @ 1234))
```

which ranks based on last 1h rate and w.r.t. unix timestamp 1234 but actually plots the 1m rate.

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
2021-01-20 16:27:39 +05:30
Vijay Samuel 00ee73ef91
Export members of EvalNodeHelper to facilitate usage in external functions (#7860)
Signed-off-by: Vijay Samuel <vjsamuel@ebay.com>
2020-08-27 19:30:10 +01:00
Julien Pivotto d77b56e88e
Fix avg_over_time for nan and float64 overflows (#7346)
* Fix avg_over_time with Inf and NaN values

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-07-13 17:30:50 +02:00
Callum Styan 5bb7f00d00
change labelset comparison in promql engine to avoid false positive during detection of duplicates (#7058)
* Use go1.14 new hash/maphash to hash both RHS and LHS instead of XOR'ing
which has been resulting in hash collisions.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Refactor engine labelset signature generation, just use labels.Labels
instead of hashes.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Address review comments; function comments + store result of
lhs.String+rhs.String as key.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Replace all signatureFunc usage with signatureFuncString.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Make optimizations to labels String function and generation of rhs+lhs
as string in resultMetric.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Use separate string functions that don't use strconv just for engine
maps.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Use a byte invalid separator instead of quoting and have a buffer
attached to EvalNodeHelper instead of using a global pool in the labels
package.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Address review comments.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Address more review comments, labels has a function that now builds a
byte slice without turning it into a string.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* Use two different non-ascii hex codes as byte separators between labels
and between sets of labels when building bytes of a Labels struct.

Signed-off-by: Callum Styan <callumstyan@gmail.com>

* We only need the 2nd byte invalid sep. at the beginning of a
labels.Bytes

Signed-off-by: Callum Styan <callumstyan@gmail.com>
2020-05-12 14:03:15 -07:00
Ben Kochie 269e7c8091
Fix golint issues.
Signed-off-by: Ben Kochie <superq@gmail.com>
2020-03-23 20:38:43 +01:00
李国忠 2bf4952049
remove Unused parameter 'sf' in calcTrendValue function (#6900)
Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>
2020-03-03 08:23:27 +00:00
Tobias Guggenmos b93845d6bf Remove unused function
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-02-17 16:09:23 +01:00
Tobias Guggenmos 1360f9ff12 Fix all build errors in promql package
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-02-17 16:09:23 +01:00
Tobias Guggenmos 9a1366775e Store function implementations independently of their signatures
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-02-17 16:07:53 +01:00
Tobias Guggenmos ff0ea1c1ac Fix more identifiers
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-02-17 16:07:53 +01:00
Tobias Guggenmos 6b1b323558 Export sequenceValue
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-02-17 16:07:53 +01:00
Tobias Guggenmos 228967a507 Fix usages of more things that have moved the package
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-02-17 16:07:27 +01:00
Tobias Guggenmos 2f1113479f Fix usages of ValueType
Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-02-17 16:05:21 +01:00
Tobias Guggenmos 2aacd807b3 PromQL: Various small improvements in the parser (#6652)
* Move check for empty VectorSelector to typeChecking
* Move check for twice set metric name to typeChecking
* Make child of MatrixSelector a general Node
* rename checkType to checkAST
* Rename fail to addParseErr
* Remove trailing whitespace

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-01-17 15:16:58 +00:00
Tobias Guggenmos 64194f7d45 PromQL: AST: Make VectorSelector Children of MatrixSelector (#6590)
Make Vector selectors children of Matrix Selectors

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2020-01-10 14:25:41 +00:00
Julien Pivotto 577e738986 Cleanup PromQL functions (#6551)
* Cleanup PromQL functions

The engine ensures, for Matrix functions, that functions are called with exactly one series at the time.
Therefore a lot of code can be inlined and we can directly assume the first element of the arguments exists and contains all the samples needed.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-01-06 10:33:36 +00:00
Julien Pivotto e0afec906f add absent_over_time (#6490)
* Implement absent_over_time

Fixes #2882

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-01-03 15:26:12 +00:00
Julien Pivotto f363a71ef7 promql: function: fix typo (#6501)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2019-12-20 22:30:55 +00:00
Julien Pivotto 4b3bab890d Fix absent output where two label matchers are identical (#6493)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2019-12-20 14:33:33 +00:00
Tobias Guggenmos cd39ebe7c6 PromQL: export function list (#6434)
This PR exports the list of supported PromQL functions and their signatures.

The reason for that is that the PromQL language server likes to use that list.

Signed-off-by: Tobias Guggenmos <tguggenm@redhat.com>
2019-12-09 15:33:43 +00:00
Tariq Ibrahim 8fdfa8abea refine error handling in prometheus (#5388)
i) Uses the more idiomatic Wrap and Wrapf methods for creating nested errors.
ii) Fixes some incorrect usages of fmt.Errorf where the error messages don't have any formatting directives.
iii) Does away with the use of fmt package for errors in favour of pkg/errors

Signed-off-by: tariqibrahim <tariq181290@gmail.com>
2019-03-26 00:01:12 +01:00
Ben Kochie c6399296dc
Fix spelling/typos (#4921)
* Fix spelling/typos

Fix spelling/typos reported by codespell/misspell.
* UK -> US spelling changes.

Signed-off-by: Ben Kochie <superq@gmail.com>
2018-11-27 17:44:29 +01:00
Thomas Jackson abf6fe0a98 Change max/min over_time to handle NaNs properly (#4386)
We only want to return a NaN if the NaN is the only value

Signed-off-by: Thomas Jackson <jacksontj.89@gmail.com>

Fixes #4385
2018-09-26 08:58:16 +01:00
Harsh Agarwal 18a9a390b5 Add duplicate-labelset check for range/instant vectors (#4589)
Signed-off-by: Harsh Agarwal <cs15btech11019@iith.ac.in>
2018-09-18 10:46:13 +01:00
Dan Cech 9f4cb06a37 use Welford/Knuth method to compute standard deviation and variance (#4533)
* use Welford/Knuth method to compute standard deviation and variance, avoids float precision issues
* use better method for calculating avg and avg_over_time

Signed-off-by: Dan Cech <dcech@grafana.com>
2018-08-26 10:28:47 +01:00