promql: Fix stddev/stdvar when aggregating histograms, NaNs, and Infs
Native histograms are ignored when calculating stddev or stdvar.
However, for the first series of each group, a `groupedAggregation` is
always created. If the first series that was encountered is a histogram
then it acts as the equivalent of a 0 point.
This change creates the first `groupedAggregation` with the `seen` field set to `false` if the point is a
histogram, thus ignoring it like the rest of the aggregation function does. A new `groupedAggregation`
will then be created once an actual float value is encountered.
This commit also sets the `floatValue` field of the `groupedAggregation` to `NaN`, if the first
float value of a group is `NaN` or `±Inf`, so that the outcome is consistently `NaN` once those
values are in the mix.
(The added tests fail without this change).
Signed-off-by: Joshua Hesketh <josh@nitrotech.org>
Signed-off-by: beorn7 <beorn@grafana.com>
---------
Signed-off-by: Joshua Hesketh <josh@nitrotech.org>
Signed-off-by: beorn7 <beorn@grafana.com>
Co-authored-by: beorn7 <beorn@grafana.com>
* discovery: add aws/ec2 unit tests
* discovery: initial skeleton for aws/ec2 unit tests
This is a - very likely - not too useful unit test for the AWS SD. It is
commited so other people can check the basic logic and the
implementation.
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: fix linter complains about ec2_test.go
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: add basic unit test for aws
This tests only the basic labelling, not including the VPC related
information.
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: fix linter complains about ec2_test.go
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: other linter fixes in aws/ec2_test.go
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: implement remaining tests for aws/ec2
The coverage is not 100% but I think it is a good starting point if
someone wants to improve that.
Currently it covers all the AWS API calls.
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: make linter happy in aws/ec2_test.go
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: make utility funtcions private
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discover: no global variable in the aws/ec2 test
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: common body for some tests in ec2
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: try to make golangci-lint happy
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: make every non-test function private
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: test for errors first in TestRefresh
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: move refresh tests into the function
This way people can find both the test cases and the execution of the
test at the same place.
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: fix copyright date
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: remove misleading comment
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: rename test for easier identification
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: use static values for the test cases
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discover: try to make the linter happy
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: drop redundant data from ec2 and use common ptr functions
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: use Error instead of Equal
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
* discovery: merge refreshAZIDs tests into one
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
---------
Signed-off-by: Arpad Kunszt <akunszt@hiya.com>
promql: corrects binary operators functioning for mixed sample with histogram and float
For invalid pairings of sample types, an annotation is added now.
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
---------
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
* model: move classic to NHCB conversion into its own file
In preparation for #14978.
Author: Jeanette Tan <jeanette.tan@grafana.com> 2024-07-03 11:56:48
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Co-authored-by: Jeanette Tan <jeanette.tan@grafana.com>
Co-authored-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
* Better naming from review comment
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
* Add doc strings.
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
---------
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Co-authored-by: Jeanette Tan <jeanette.tan@grafana.com>
* azure sd: separate refresh and refreshAzure
* azure sd: create a client with mocked servers for tests
* add test for refresh function
---------
Signed-off-by: mviswanathsai <mviswanath.sai.met21@itbhu.ac.in>
* Tests for Mempostings.{Add,Get} data race
* Fix MemPostings.{Add,Get} data race
We can't modify the postings list that are held in MemPostings as they
might already be in use by some readers.
* Modify BenchmarkHeadStripeSeriesCreate to have common labels
If there are no common labels on the series, we don't excercise the
ordering part of MemSeries, as we're just creating slices of one element
for each label value.
---------
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
Move writing memSeries lastHistogramValue and lastFloatHistogramValue
after series creation under lock.
The resulting code isn't totally correct in the sense that we're setting
these values before Commit() , so they might be overwritten/rolled back
later.
Also Append of stale sample checks the values without lock, so there's
still a potential race.
The correct solution would be to set these only in Commit() which we
actually do, but then Commit() would also need to process samples in
order and not floats first, then histograms, then float histograms - which
leads to not knowing what stale marker to write for histograms.
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Two Appenders race when creating a series with a native histogram
as the memSeries will be common and the lastHistogram field is written
without lock.
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
- `float histogram` → `floathistogram`, as it is used in the code.
- Actual link encodings to the code (to find the actual numerical values).
- `<bytes>` → `<data>` for consistency.
Signed-off-by: beorn7 <beorn@grafana.com>
Put a scalar to query, it can be graphed.
So the doc says "an expression that returns an instant vector is the only type which can be graphed." is not correct?
And also, a query_range, which used for graph, always return a range vector <https://promlabs.com/blog/2020/06/18/the-anatomy-of-a-promql-query/#range-queries> , so it's confusing to read the above statement.
Signed-off-by: Viet Hung Nguyen <hvn@familug.org>
For: #14355
This commit updates Prometheus to adopt stdlib's log/slog package in
favor of go-kit/log. As part of converting to use slog, several other
related changes are required to get prometheus working, including:
- removed unused logging util func `RateLimit()`
- forward ported the util/logging/Deduper logging by implementing a small custom slog.Handler that does the deduping before chaining log calls to the underlying real slog.Logger
- move some of the json file logging functionality to use prom/common package functionality
- refactored some of the new json file logging for scraping
- changes to promql.QueryLogger interface to swap out logging methods for relevant slog sugar wrappers
- updated lots of tests that used/replicated custom logging functionality, attempting to keep the logical goal of the tests consistent after the transition
- added a healthy amount of `if logger == nil { $makeLogger }` type conditional checks amongst various functions where none were provided -- old code that used the go-kit/log.Logger interface had several places where there were nil references when trying to use functions like `With()` to add keyvals on the new *slog.Logger type
Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>