Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
066d5cf4
Unverified
Commit
066d5cf4
authored
Feb 28, 2020
by
Vikky Omkar
Committed by
GitHub
Feb 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alerting: Fixed the issue/bug of diff and percent_diff functions *Breaking change* (#21338)
fixes #16270 #10129
parent
0606555b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
233 additions
and
22 deletions
+233
-22
pkg/services/alerting/conditions/reducer.go
+14
-3
pkg/services/alerting/conditions/reducer_test.go
+217
-19
public/app/features/alerting/state/alertDef.ts
+2
-0
No files found.
pkg/services/alerting/conditions/reducer.go
View file @
066d5cf4
...
...
@@ -96,8 +96,12 @@ func (s *queryReducer) Reduce(series *tsdb.TimeSeries) null.Float {
}
case
"diff"
:
allNull
,
value
=
calculateDiff
(
series
,
allNull
,
value
,
diff
)
case
"diff_abs"
:
allNull
,
value
=
calculateDiff
(
series
,
allNull
,
value
,
diffAbs
)
case
"percent_diff"
:
allNull
,
value
=
calculateDiff
(
series
,
allNull
,
value
,
percentDiff
)
case
"percent_diff_abs"
:
allNull
,
value
=
calculateDiff
(
series
,
allNull
,
value
,
percentDiffAbs
)
case
"count_non_null"
:
for
_
,
v
:=
range
series
.
Points
{
if
isValid
(
v
[
0
])
{
...
...
@@ -141,8 +145,7 @@ func calculateDiff(series *tsdb.TimeSeries, allNull bool, value float64, fn func
for
i
:=
0
;
i
<
len
(
points
);
i
++
{
if
isValid
(
points
[
i
][
0
])
{
allNull
=
false
val
:=
fn
(
first
,
points
[
i
][
0
]
.
Float64
)
value
=
math
.
Abs
(
val
)
value
=
fn
(
first
,
points
[
i
][
0
]
.
Float64
)
break
}
}
...
...
@@ -158,6 +161,14 @@ var diff = func(newest, oldest float64) float64 {
return
newest
-
oldest
}
var
diffAbs
=
func
(
newest
,
oldest
float64
)
float64
{
return
math
.
Abs
(
newest
-
oldest
)
}
var
percentDiff
=
func
(
newest
,
oldest
float64
)
float64
{
return
(
newest
-
oldest
)
/
oldest
*
100
return
(
newest
-
oldest
)
/
math
.
Abs
(
oldest
)
*
100
}
var
percentDiffAbs
=
func
(
newest
,
oldest
float64
)
float64
{
return
math
.
Abs
((
newest
-
oldest
)
/
oldest
*
100
)
}
pkg/services/alerting/conditions/reducer_test.go
View file @
066d5cf4
This diff is collapsed.
Click to expand it.
public/app/features/alerting/state/alertDef.ts
View file @
066d5cf4
...
...
@@ -47,7 +47,9 @@ const reducerTypes = [
{
text
:
'last()'
,
value
:
'last'
},
{
text
:
'median()'
,
value
:
'median'
},
{
text
:
'diff()'
,
value
:
'diff'
},
{
text
:
'diff_abs()'
,
value
:
'diff_abs'
},
{
text
:
'percent_diff()'
,
value
:
'percent_diff'
},
{
text
:
'percent_diff_abs()'
,
value
:
'percent_diff_abs'
},
{
text
:
'count_non_null()'
,
value
:
'count_non_null'
},
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment