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
98406d6c
Unverified
Commit
98406d6c
authored
Jan 21, 2021
by
Hugo Häggmark
Committed by
GitHub
Jan 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alerting: Hides threshold handle for percentual thresholds (#30431)
parent
e1243e07
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
12 deletions
+80
-12
public/app/features/alerting/AlertTabCtrl.ts
+1
-0
public/app/features/alerting/state/ThresholdMapper.test.ts
+63
-2
public/app/features/alerting/state/ThresholdMapper.ts
+12
-10
public/app/plugins/panel/graph/threshold_manager.ts
+4
-0
No files found.
public/app/features/alerting/AlertTabCtrl.ts
View file @
98406d6c
...
@@ -390,6 +390,7 @@ export class AlertTabCtrl {
...
@@ -390,6 +390,7 @@ export class AlertTabCtrl {
case
'action'
:
{
case
'action'
:
{
conditionModel
.
source
.
reducer
.
type
=
evt
.
action
.
value
;
conditionModel
.
source
.
reducer
.
type
=
evt
.
action
.
value
;
conditionModel
.
reducerPart
=
alertDef
.
createReducerPart
(
conditionModel
.
source
.
reducer
);
conditionModel
.
reducerPart
=
alertDef
.
createReducerPart
(
conditionModel
.
source
.
reducer
);
this
.
evaluatorParamsChanged
();
break
;
break
;
}
}
case
'get-part-actions'
:
{
case
'get-part-actions'
:
{
...
...
public/app/features/alerting/state/ThresholdMapper.test.ts
View file @
98406d6c
import
{
describe
,
it
,
expect
}
from
'test/lib/common'
;
import
{
hiddenReducerTypes
,
ThresholdMapper
}
from
'./ThresholdMapper'
;
import
alertDef
from
'./alertDef'
;
import
{
ThresholdMapper
}
from
'./ThresholdMapper'
;
const
visibleReducerTypes
=
alertDef
.
reducerTypes
.
filter
(({
value
})
=>
hiddenReducerTypes
.
indexOf
(
value
)
===
-
1
)
.
map
(({
value
})
=>
value
);
describe
(
'ThresholdMapper'
,
()
=>
{
describe
(
'ThresholdMapper'
,
()
=>
{
describe
(
'with greater than evaluator'
,
()
=>
{
describe
(
'with greater than evaluator'
,
()
=>
{
...
@@ -74,4 +77,62 @@ describe('ThresholdMapper', () => {
...
@@ -74,4 +77,62 @@ describe('ThresholdMapper', () => {
expect
(
panel
.
thresholds
[
1
].
value
).
toBe
(
200
);
expect
(
panel
.
thresholds
[
1
].
value
).
toBe
(
200
);
});
});
});
});
visibleReducerTypes
.
forEach
((
type
)
=>
{
describe
(
`with {
${
type
}
} reducer`
,
()
=>
{
it
(
'visible should be true'
,
()
=>
{
const
panel
=
getPanel
({
reducerType
:
type
});
const
updated
=
ThresholdMapper
.
alertToGraphThresholds
(
panel
);
expect
(
updated
).
toBe
(
true
);
expect
(
panel
.
thresholds
[
0
]).
toEqual
({
value
:
100
,
op
:
'gt'
,
fill
:
true
,
line
:
true
,
colorMode
:
'critical'
,
visible
:
true
,
});
});
});
});
hiddenReducerTypes
.
forEach
((
type
)
=>
{
describe
(
`with {
${
type
}
} reducer`
,
()
=>
{
it
(
'visible should be false'
,
()
=>
{
const
panel
=
getPanel
({
reducerType
:
type
});
const
updated
=
ThresholdMapper
.
alertToGraphThresholds
(
panel
);
expect
(
updated
).
toBe
(
true
);
expect
(
panel
.
thresholds
[
0
]).
toEqual
({
value
:
100
,
op
:
'gt'
,
fill
:
true
,
line
:
true
,
colorMode
:
'critical'
,
visible
:
false
,
});
});
});
});
});
});
function
getPanel
({
reducerType
}:
{
reducerType
?:
string
}
=
{})
{
const
panel
:
any
=
{
type
:
'graph'
,
options
:
{
alertThreshold
:
true
},
alert
:
{
conditions
:
[
{
type
:
'query'
,
evaluator
:
{
type
:
'gt'
,
params
:
[
100
]
},
reducer
:
{
type
:
reducerType
},
},
],
},
};
return
panel
;
}
public/app/features/alerting/state/ThresholdMapper.ts
View file @
98406d6c
import
{
PanelModel
}
from
'app/features/dashboard/state'
;
import
{
PanelModel
}
from
'app/features/dashboard/state'
;
export
const
hiddenReducerTypes
=
[
'percent_diff'
,
'percent_diff_abs'
];
export
class
ThresholdMapper
{
export
class
ThresholdMapper
{
static
alertToGraphThresholds
(
panel
:
PanelModel
)
{
static
alertToGraphThresholds
(
panel
:
PanelModel
)
{
if
(
!
panel
.
alert
)
{
if
(
!
panel
.
alert
)
{
...
@@ -14,16 +15,17 @@ export class ThresholdMapper {
...
@@ -14,16 +15,17 @@ export class ThresholdMapper {
const
evaluator
=
condition
.
evaluator
;
const
evaluator
=
condition
.
evaluator
;
const
thresholds
:
any
[]
=
(
panel
.
thresholds
=
[]);
const
thresholds
:
any
[]
=
(
panel
.
thresholds
=
[]);
const
visible
=
hiddenReducerTypes
.
indexOf
(
condition
.
reducer
?.
type
)
===
-
1
;
switch
(
evaluator
.
type
)
{
switch
(
evaluator
.
type
)
{
case
'gt'
:
{
case
'gt'
:
{
const
value
=
evaluator
.
params
[
0
];
const
value
=
evaluator
.
params
[
0
];
thresholds
.
push
({
value
:
value
,
op
:
'gt'
});
thresholds
.
push
({
value
:
value
,
op
:
'gt'
,
visible
});
break
;
break
;
}
}
case
'lt'
:
{
case
'lt'
:
{
const
value
=
evaluator
.
params
[
0
];
const
value
=
evaluator
.
params
[
0
];
thresholds
.
push
({
value
:
value
,
op
:
'lt'
});
thresholds
.
push
({
value
:
value
,
op
:
'lt'
,
visible
});
break
;
break
;
}
}
case
'outside_range'
:
{
case
'outside_range'
:
{
...
@@ -31,11 +33,11 @@ export class ThresholdMapper {
...
@@ -31,11 +33,11 @@ export class ThresholdMapper {
const
value2
=
evaluator
.
params
[
1
];
const
value2
=
evaluator
.
params
[
1
];
if
(
value1
>
value2
)
{
if
(
value1
>
value2
)
{
thresholds
.
push
({
value
:
value1
,
op
:
'gt'
});
thresholds
.
push
({
value
:
value1
,
op
:
'gt'
,
visible
});
thresholds
.
push
({
value
:
value2
,
op
:
'lt'
});
thresholds
.
push
({
value
:
value2
,
op
:
'lt'
,
visible
});
}
else
{
}
else
{
thresholds
.
push
({
value
:
value1
,
op
:
'lt'
});
thresholds
.
push
({
value
:
value1
,
op
:
'lt'
,
visible
});
thresholds
.
push
({
value
:
value2
,
op
:
'gt'
});
thresholds
.
push
({
value
:
value2
,
op
:
'gt'
,
visible
});
}
}
break
;
break
;
...
@@ -45,11 +47,11 @@ export class ThresholdMapper {
...
@@ -45,11 +47,11 @@ export class ThresholdMapper {
const
value2
=
evaluator
.
params
[
1
];
const
value2
=
evaluator
.
params
[
1
];
if
(
value1
>
value2
)
{
if
(
value1
>
value2
)
{
thresholds
.
push
({
value
:
value1
,
op
:
'lt'
});
thresholds
.
push
({
value
:
value1
,
op
:
'lt'
,
visible
});
thresholds
.
push
({
value
:
value2
,
op
:
'gt'
});
thresholds
.
push
({
value
:
value2
,
op
:
'gt'
,
visible
});
}
else
{
}
else
{
thresholds
.
push
({
value
:
value1
,
op
:
'gt'
});
thresholds
.
push
({
value
:
value1
,
op
:
'gt'
,
visible
});
thresholds
.
push
({
value
:
value2
,
op
:
'lt'
});
thresholds
.
push
({
value
:
value2
,
op
:
'lt'
,
visible
});
}
}
break
;
break
;
}
}
...
...
public/app/plugins/panel/graph/threshold_manager.ts
View file @
98406d6c
...
@@ -87,6 +87,10 @@ export class ThresholdManager {
...
@@ -87,6 +87,10 @@ export class ThresholdManager {
renderHandle
(
handleIndex
:
number
,
defaultHandleTopPos
:
number
)
{
renderHandle
(
handleIndex
:
number
,
defaultHandleTopPos
:
number
)
{
const
model
=
this
.
thresholds
[
handleIndex
];
const
model
=
this
.
thresholds
[
handleIndex
];
if
(
!
model
.
visible
)
{
return
;
}
const
value
=
model
.
value
;
const
value
=
model
.
value
;
let
valueStr
=
value
;
let
valueStr
=
value
;
let
handleTopPos
=
0
;
let
handleTopPos
=
0
;
...
...
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