Skip to content

Commit

Permalink
support alert define threshold expression display ui (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Jun 16, 2023
1 parent 0820cff commit 942b5c8
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class MonitorsController {

private static final byte ALL_MONITOR_STATUS = 9;

private static final int TAG_LENGTH = 2;

@Autowired
private MonitorService monitorService;

Expand Down Expand Up @@ -101,7 +103,7 @@ public ResponseEntity<Message<Page<Monitor>>> getMonitors(
ListJoin<Monitor, org.dromara.hertzbeat.common.entity.manager.Tag> tagJoin = root
.join(root.getModel()
.getList("tags", org.dromara.hertzbeat.common.entity.manager.Tag.class), JoinType.LEFT);
if (tagArr.length == 2) {
if (tagArr.length == TAG_LENGTH) {
andList.add(criteriaBuilder.equal(tagJoin.get("name"), tagName));
andList.add(criteriaBuilder.equal(tagJoin.get("value"), tagValue));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ public class Hierarchy {
*/
@Schema(description = "是否是叶子节点", example = "true", accessMode = READ_WRITE)
Boolean isLeaf = false;

/**
* For leaf metric
* metric type 0-number: number 1-string: string
* 指标类型 0-number:数字 1-string:字符串
*/
@Schema(description = "metric type 0-number: number 1-string: string")
private Byte type;

/**
* metric unit
* 指标单位
*/
@Schema(description = "metric unit")
private String unit;

/**
* Next level of association
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public List<Hierarchy> getAllAppHierarchy(String lang) {
hierarchyField.setValue(field.getField());
hierarchyField.setLabel(field.getField());
hierarchyField.setIsLeaf(true);
// for metric
hierarchyField.setType(field.getType());
hierarchyField.setUnit(field.getUnit());
hierarchyFieldList.add(hierarchyField);
}
hierarchyMetric.setChildren(hierarchyFieldList);
Expand Down
139 changes: 120 additions & 19 deletions web-app/src/app/routes/alert/alert-setting/alert-setting.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@
(nzOnCancel)="onManageModalCancel()"
(nzOnOk)="onManageModalOk()"
nzMaskClosable="false"
nzWidth="60%"
nzWidth="70%"
[nzOkLoading]="isManageModalOkLoading"
>
<div *nzModalContent class="-inner-content">
<form nz-form #defineForm="ngForm">
<nz-form-item>
<nz-form-label [nzSpan]="7" nzFor="target" nzRequired="true">{{ 'alert.setting.target' | i18n }}</nz-form-label>
<nz-form-control [nzSpan]="10" [nzErrorTip]="'validation.required' | i18n">
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<nz-cascader
required
name="target"
Expand All @@ -158,17 +158,27 @@
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="cascadeValues.length != 2">
<nz-col [nzXs]="{ span: 24 }" [nzLg]="{ span: 10, offset: 7 }">
<nz-col [nzXs]="{ span: 24, offset: 0 }" [nzLg]="{ span: 8, offset: 16 }">
<button nz-button [nzType]="isExpr ? 'primary' : 'default'" (click)="switchAlertRuleShow()">
<i nz-icon nzType="code" nzTheme="outline"></i>
{{ 'alert.setting.rule.switch-expr' | i18n }}
</button>
</nz-col>
</nz-form-item>
<nz-form-item *ngIf="cascadeValues.length != 2 && isExpr">
<nz-col [nzXs]="{ span: 24 }" [nzLg]="{ span: 12, offset: 7 }">
<nz-collapse>
<nz-collapse-panel [nzActive]="isManageModalAdd" [nzHeader]="'alert.setting.expr.tip' | i18n">
<nz-list nzSize="small" nzSplit="false">
<nz-list-item *ngIf="cascadeValues.length == 3">
<code>{{ cascadeValues[2] }} : {{ 'alert.setting.target.tip' | i18n }}</code>
</nz-list-item>
<nz-list-item *ngFor="let item of otherMetrics">
<code>{{ item }} : {{ 'alert.setting.target.other' | i18n }}</code>
<nz-list-item *ngFor="let item of currentMetrics; let i = index">
<code>
{{ item.value }} : {{ i == 0 ? ('alert.setting.target.tip' | i18n) : ('alert.setting.target.other' | i18n) }}
</code>
<nz-tag [nzColor]="item.type === 0 ? 'success' : 'processing'">
{{ item.type === 0 ? ('alert.setting.number' | i18n) : ('alert.setting.string' | i18n) }}
</nz-tag>
</nz-list-item>
<nz-list-item *ngIf="otherMetrics.length != 0">
<nz-list-item *ngIf="currentMetrics.length > 1">
<code>instance : {{ 'alert.setting.target.instance' | i18n }}</code>
</nz-list-item>
<nz-list-item>
Expand All @@ -179,11 +189,11 @@
</nz-collapse>
</nz-col>
</nz-form-item>
<nz-form-item *ngIf="cascadeValues.length != 2">
<nz-form-item *ngIf="cascadeValues.length != 2 && isExpr">
<nz-form-label [nzSpan]="7" nzFor="expr" nzRequired="true" [nzTooltipTitle]="'alert.setting.expr.label' | i18n">
{{ 'alert.setting.expr' | i18n }}
{{ 'alert.setting.rule' | i18n }}
</nz-form-label>
<nz-form-control [nzSpan]="10" [nzErrorTip]="'validation.required' | i18n">
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<nz-textarea-count [nzMaxCharacterCount]="100">
<textarea
[(ngModel)]="define.expr"
Expand All @@ -198,6 +208,97 @@
</nz-textarea-count>
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="cascadeValues.length != 2 && !isExpr">
<nz-form-label [nzSpan]="7" nzFor="rule" nzRequired="true" [nzTooltipTitle]="'alert.setting.rule.label' | i18n">
{{ 'alert.setting.rule' | i18n }}
</nz-form-label>
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<div id="rule">
<div style="width: 100%; margin-bottom: 2px" nz-row *ngFor="let alertRule of alertRules; let i = index">
<nz-select
[(ngModel)]="alertRule.metric"
[ngModelOptions]="{ standalone: true }"
nz-col
nzSpan="8"
[nzDropdownMatchSelectWidth]="false"
[nzPlaceHolder]="'alert.setting.rule.metric.place-holder' | i18n"
>
<nz-option *ngFor="let item of currentMetrics" [nzValue]="item" [nzLabel]="item.value" nzCustomContent>
{{ item.value }}
<nz-tag [nzColor]="item.type === 0 ? 'success' : 'processing'">
{{ item.type === 0 ? ('alert.setting.number' | i18n) : ('alert.setting.string' | i18n) }}
</nz-tag>
<nz-tag *ngIf="item.unit">
{{ item.unit }}
</nz-tag>
</nz-option>
</nz-select>
<nz-select
[(ngModel)]="alertRule.operator"
[ngModelOptions]="{ standalone: true }"
nz-col
nzSpan="4"
[nzShowArrow]="false"
style="text-align: center; font-weight: bolder"
[nzDropdownStyle]="{ 'text-align': 'center', 'font-weight': 'bolder', 'font-size': 'larger' }"
[nzPlaceHolder]="'alert.setting.rule.operator' | i18n"
>
<nz-option *ngIf="!alertRule.metric || alertRule.metric.type === 0" [nzValue]="'>'" [nzLabel]="'>'"></nz-option>
<nz-option *ngIf="!alertRule.metric || alertRule.metric.type === 0" [nzValue]="'<'" [nzLabel]="'<'"></nz-option>
<nz-option *ngIf="!alertRule.metric || alertRule.metric.type === 0" [nzValue]="'=='" [nzLabel]="'=='"></nz-option>
<nz-option *ngIf="!alertRule.metric || alertRule.metric.type === 0" [nzValue]="'!='" [nzLabel]="'!='"></nz-option>
<nz-option *ngIf="!alertRule.metric || alertRule.metric.type === 0" [nzValue]="'<='" [nzLabel]="'<='"></nz-option>
<nz-option *ngIf="!alertRule.metric || alertRule.metric.type === 0" [nzValue]="'>='" [nzLabel]="'<='"></nz-option>
<nz-option
*ngIf="!alertRule.metric || alertRule.metric.type === 1"
[nzValue]="'equals'"
[nzLabel]="'alert.setting.rule.operator.str-equals' | i18n"
></nz-option>
<nz-option
*ngIf="!alertRule.metric || alertRule.metric.type === 1"
[nzValue]="'!equals'"
[nzLabel]="'alert.setting.rule.operator.str-no-equals' | i18n"
></nz-option>
</nz-select>
<input
nz-input
[type]="alertRule.metric?.type === 0 ? 'number' : 'text'"
[(ngModel)]="alertRule.value"
[ngModelOptions]="{ standalone: true }"
[placeholder]="
alertRule.metric?.type === 0
? ('alert.setting.rule.numeric-value.place-holder' | i18n)
: ('alert.setting.rule.string-value.place-holder' | i18n)
"
nz-col
nzSpan="10"
/>
<button
*ngIf="i === alertRules.length - 1 && i < 4"
nz-button
nzType="primary"
nz-col
nzSpan="2"
nzGhost="true"
(click)="onAddNewAlertRule()"
>
<span nz-icon nzType="plus"></span>
</button>
<button
*ngIf="i != alertRules.length - 1 || i == 4"
nz-button
nz-col
nzSpan="2"
nzDanger
nzGhost="true"
(click)="onRemoveAlertRule(i)"
>
<span nz-icon nzType="minus"></span>
</button>
</div>
</div>
</nz-form-control>
</nz-form-item>
<nz-form-item *ngIf="cascadeValues.length == 2">
<nz-form-label [nzSpan]="7" nzFor="available">
{{ 'monitor.availability' | i18n }}
Expand All @@ -214,7 +315,7 @@
<nz-form-label nzSpan="7" nzRequired="true" nzFor="priority" [nzTooltipTitle]="'alert.setting.priority.tip' | i18n">
{{ 'alert.priority' | i18n }}
</nz-form-label>
<nz-form-control nzSpan="10" [nzErrorTip]="'validation.required' | i18n">
<nz-form-control nzSpan="12" [nzErrorTip]="'validation.required' | i18n">
<nz-select [(ngModel)]="define.priority" nzPlaceHolder="Choose" name="priority" id="priority">
<nz-option [nzValue]="0" [nzLabel]="'alert.priority.0' | i18n"></nz-option>
<nz-option [nzValue]="1" [nzLabel]="'alert.priority.1' | i18n"></nz-option>
Expand All @@ -226,13 +327,13 @@
<nz-form-label nzSpan="7" nzRequired="true" nzFor="duration" [nzTooltipTitle]="'alert.setting.times.tip' | i18n">
{{ 'alert.setting.times' | i18n }}
</nz-form-label>
<nz-form-control nzSpan="10" [nzErrorTip]="'validation.required' | i18n">
<nz-form-control nzSpan="12" [nzErrorTip]="'validation.required' | i18n">
<nz-input-number [(ngModel)]="define.times" [nzMin]="1" [nzMax]="999" [nzStep]="1" required name="duration" id="duration">
</nz-input-number>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-col [nzXs]="{ span: 24 }" [nzLg]="{ span: 10, offset: 7 }">
<nz-col [nzXs]="{ span: 24 }" [nzLg]="{ span: 12, offset: 7 }">
<nz-collapse>
<nz-collapse-panel [nzActive]="isManageModalAdd" [nzHeader]="'alert.setting.template.tip' | i18n">
<nz-list nzSize="small" nzSplit="false">
Expand All @@ -248,7 +349,7 @@
<nz-list-item *ngIf="cascadeValues.length == 3">
<code>&#36;{{ '{' + cascadeValues[2] + '}' }} : {{ 'alert.setting.template.metric-value' | i18n }}</code>
</nz-list-item>
<nz-list-item *ngFor="let item of otherMetrics">
<nz-list-item *ngFor="let item of currentMetrics">
<code>&#36;{{ '{' + item + '}' }} : {{ 'alert.setting.template.other-value' | i18n }}</code>
</nz-list-item>
<nz-list-item *ngIf="cascadeValues.length == 3">
Expand All @@ -263,7 +364,7 @@
<nz-form-label [nzSpan]="7" nzFor="template" nzRequired="true" [nzTooltipTitle]="'alert.setting.template.label' | i18n">
{{ 'alert.setting.template' | i18n }}
</nz-form-label>
<nz-form-control [nzSpan]="10" [nzErrorTip]="'validation.required' | i18n">
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' | i18n">
<nz-textarea-count [nzMaxCharacterCount]="200">
<textarea
[(ngModel)]="define.template"
Expand All @@ -282,15 +383,15 @@
<nz-form-label nzSpan="7" nzFor="preset" [nzTooltipTitle]="'alert.setting.default.tip' | i18n">
{{ 'alert.setting.default' | i18n }}
</nz-form-label>
<nz-form-control nzSpan="10">
<nz-form-control nzSpan="12">
<nz-switch [(ngModel)]="define.preset" name="preset" id="preset"></nz-switch>
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzSpan="7" nzRequired="true" nzFor="enable" [nzTooltipTitle]="'alert.setting.enable.tip' | i18n">
{{ 'alert.setting.enable' | i18n }}
</nz-form-label>
<nz-form-control nzSpan="10">
<nz-form-control nzSpan="12">
<nz-switch [(ngModel)]="define.enable" [ngModelOptions]="{ standalone: true }" name="enable" id="enable"></nz-switch>
</nz-form-control>
</nz-form-item>
Expand Down
Loading

0 comments on commit 942b5c8

Please sign in to comment.