How to ignore empty dataseries in prometheus - max

Calculating the maximum quantile over all dataseries is a problem for me:
query
http_response_time{job=~"^(x|y)$", quantile="0.95",...}
result
http_response_time{job="x",...} 0.26
http_response_time{job="y",...} NaN
This is how I would try to calculate the maximum:
avg(http_response_time{job=~"^(x|y)$",...})
Now the result will be "NaN". How can I ignore the "NaN" result (from the result section)?
UPDATE 0
The metric is a self made summary-metric.
UPDATE 1
Using prometheus version 1.8.

I didn't try this one with NaN, but you can simply filter by values with binary operators. Since NaN mathematically doesn't equal NaN you could try this trick (since a response time should be always positive):
avg(http_response_time{job=~"^(x|y)$",...} >= 0)

Related

Sum expression in report Buildr

I got this expression
=iIF(Isnothing(Fields!Saldo_contable.Value) or (Fields!Saldo_contable.Value)<0,0,Fields!Saldo_contable.Value)
That works fine, I need to sum the result of the whole expression
=sum(iif(Isnothing(Fields!Saldo_contable.Value) or (Fields!Saldo_contable.Value)<0,0,Fields!Saldo_contable.Value)),
i dont get an actual error but the field just show the result: #Error,
What im doing wrong?
If Saldo_contable is not an integer, you need to use CDEC(0) for the zero value (2nd argument) of the IIF.
=SUM(IIF(Isnothing(Fields!Saldo_contable.Value) or (Fields!Saldo_contable.Value) < 0, CDEC(0), Fields!Saldo_contable.Value))
SUMming values like 0 and 2.25 results in a Can't sum different data type error.
Your detail line works because it isn't using SUM - just displaying the values.

SQL Server Reporting: How calculate value based on the previous calculated value int the same column?

I'm trying to calculate a row value based on the previous row value in the same column within a report expression. I can't precalculate this from database since starting point of calculation is dependent from input parameters and values in a table should be recalculated dynamically within report itself.
In Excel analogical data and formula look like as it is shown below (starting point is always 100):
B C D E
Price PreviousPrice CalcValue Formula
1 NULL NULL 100
2 2.6 2.5 104 B2/C2*D1
3 2.55 2.6 102 B3/C3*D2
4 2.6 2.55 104 B4/C4*D3
5 2.625 2.6 105 B5/C5*D4
6 2.65 2.625 106 B6/C6*D5
7 2.675 2.65 107 B7/C7*D6
I tried to calculate expected values ("CalcValue" is the name of column where expression is set) like this:
=Fields!Price.Value/ PreviousPrice.Value * Previous(reportitems("CalcValue").Value))
but got an error "Aggregate functions can be used only on report items contained in page headers and footers"
Can you please advice whether expected result is achievable in my case and suggest a solution?
Thank you in advance!
Sadly I'm still facing with issue: calculated column does not consider previous calculated value. E.g., I added CalcVal field with 100 as default and tried to calculate using above approach, like: =previous(runningValue(Fields!CalcVal.Value, sum, "DataSet1") ) * Fields!Price.Value/Fields!PreviousPrice.Value.
But in this case it always multiples Fields!Price.Value/Fields!PreviousPrice.Value by 100..
For example CalcVal on Fly always show 200
=previous(runningValue(Fields!CalcVal.Value, sum, "DataSet1")) * 2
https://imgur.com/Wtg3Wsg
I tried with your sample data, here is how I achieved the results
Formula to use, You might have to take care of null values
=Fields!Price.Value/(Fields!PreviousPrice.Value*Previous(Fields!CalcValue.Value))
Edit: Update to answer after Op's comment
CalcValue is caluated with below formula i.e on the fly
=RunningValue(CountDistinct("Tablix6"),Count,"Tablix6"*100
and then Final value as below
=Fields!Price.Value/(Fields!PreviousPrice.Value*
Previous(RunningValue(CountDistinct("Tablix6"),Count,"Tablix6"))*100)

Check if number is NaN

I'm trying to check if a variable I have is equals to NaN in my Ruby on Rails application.
I saw this answer, but it's not really useful because in my code I want to return 0 if the variable is NaN and the value otherwise:
return (average.nan ? 0 : average.round(1))
The problem is that if the number is not a NaN I get this error:
NoMethodError: undefined method `nan?' for 10:Fixnum
I can't check if the number is a Float instance because it is in both cases (probably, I'm calculating an average).
What can I do?
It is strange only to me that a function to check if a variable is equals to NaN is avaible only to NaN objects?
Quickest way is to use this:
under_the_test.to_f.nan? # gives you true/false e.g.:
123.to_f.nan? # => false
(123/0.0).to_f.nan? #=> true
Also note that only Floats have #nan? method defined on them, that's the reason why I'm using #to_f in order to convert result to float first.
Tip: if you have integer calculation that potentially can divide by zero this will not work:
(123/0).to_f.nan?
Because both 123 and 0 are integers and that will throw ZeroDivisionError, in order to overcome that issue Float::NAN constant can be useful - for example like this:
return Float::NAN if divisor == 0
return x / divisor
I found this answer while duckducking for something that is neither NaN nor Infinity (e.g., a finite number). Hence I'll add my discovery here for next googlers.
And as always in ruby, the answer was just to type my expectation while searching in the Float documentation, and find finite?
n = 1/0.0 #=> Infinity
n.nan? #=> false
n.finite? #=> false
The best way to avoid this kind of problem is to rely on the fact that a NaN isn't even equal to itself:
a = 0.0/0.0
a != a
# -> True !
This is likely not going to be an issue with any other type.

Symfony Range in validation.yml

I would like to know about this particular validation behaviour, although is more out of curiosity than to solve a real life problem, I'm interested to know the answer.
Entity property price is defined as:
/**
* #ORM\Column(name="price", type="float", nullable=false)
*/
In the Symfony manual targeting 2.7, range min and max options are 'integer' types. But actually using a float, it does work as expected:
#validation.yml
Project\MyBundle\Entity\Product:
properties:
price:
- Range:
min: 0.01
max: 12.90
minMessage: Price can't be lower than 0,01€
maxMessage: Price can't be lower than 12,90€
max validation works without any problem making any value higher than 12,90 fail as seen in the picture.
min validation does not:
Entering 0,009 will pass validation although is minor than 0,01.
Is there any reason that min and max values are documented as type: integer but work to validate float values ?
Has anyone a valid answer for this one ?
Price type has a precision point 2, so your number is rounded
0.009 which is equivalent 0.01

re sizing column data with tcl

I have a set of data that has a X number of points and I want to re size this to x+n number of points.
I need to do this with tcl and am struggling in the last part.
I know the Max, Min and the delta that is needed to refit the data to desired number of points.
Original data:
-0.3925
-0.262
-0.1965
-0.026
-0.013
-0.0065
-0.0026
0
0.0026
0.0065
0.013
0.026
0.1965
0.262
0.3925
I'm struggling to construct a for loop that will, take the first value and subtract it from delta to create the second value. Subsequently take the second and subtract it from delta to create third and so on and so forth.
Given:
Points 19
Min : -0.3925
Max :0.3925
Delta : 0.04361
Results column data would look like:
-0.3925
-0.348888889
-0.305277778
-0.261666667
-0.218055556
-0.174444444
-0.130833333
-0.087222222
-0.043611111
-6.93889E-17
0.043611111
0.087222222
0.130833333
0.174444444
0.218055556
0.261666667
0.305277778
0.348888889
0.3925
Could someone kindly give me some advice.
There are a few key points when doing this sort of thing (and these apply to languages other than Tcl too). Firstly, you should compute the delta from the span you want and the number of steps you want. Secondly, you should keep your incrementing and loop control using integers if you can, so as to avoid fencepost errors caused by rounding; instead compute the value for the loop iteration by multiplying the delta by the loop counter and adding to the originating value. Thirdly, you should consider what the right precision is when printing your results; in Tcl, this tends to mean using format with the %f conversion and appropriate width specifier.
set from -0.3925
set to 0.3925
set points 19
set delta [expr {($to-$from) / double($points-1)}]
for {set i 0} {$i<$points} {incr i} {
set x [expr {$from + $i*$delta}]
puts [format "%.5f" $x]
}
This produces this output:
-0.39250
-0.34889
-0.30528
-0.26167
-0.21806
-0.17444
-0.13083
-0.08722
-0.04361
0.00000
0.04361
0.08722
0.13083
0.17444
0.21806
0.26167
0.30528
0.34889
0.39250

Resources