Skip to content

Commit

Permalink
ui improve
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Jul 3, 2020
1 parent 33d555a commit fbbadcf
Show file tree
Hide file tree
Showing 6 changed files with 1,291 additions and 1,258 deletions.
2,508 changes: 1,256 additions & 1,252 deletions api/static.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dashboard/src/components/MessageCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<div class="float-right" title="状态">
<b-badge v-if="message.status === 'pending'" variant="dark">准备中</b-badge>
<b-badge v-if="message.status === 'grouped'" variant="success">已分组</b-badge>
<b-badge v-if="message.status === 'canceled'" variant="danger">已取消</b-badge>
<b-badge v-if="message.status === 'canceled'" variant="danger">无规则,已取消</b-badge>
<b-badge v-if="message.status === 'expired'" variant="warning">匹配规则,已过期</b-badge>
</div>
</template>

Expand Down
5 changes: 3 additions & 2 deletions dashboard/src/views/Messages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
{value: null, text: '所有状态'},
{value: 'pending', text: '准备中'},
{value: 'grouped', text: '已分组'},
{value: 'canceled', text: '已取消'},
{value: 'canceled', text: '无规则,已取消'},
{value: 'expired', text: '匹配规则,已过期'},
],
messages: [],
cur: parseInt(this.$route.query.next !== undefined ? this.$route.query.next : 0),
Expand Down Expand Up @@ -77,7 +78,7 @@
this.search.origin = response.data.search.origin;
this.search.tags = response.data.search.tags;
this.search.meta = response.data.search.meta;
this.search.status = response.data.search.status.length == 0 ? null : response.data.search.status[0];
this.search.status = response.data.search.status.length === 0 ? null : response.data.search.status[0];
this.isBusy = false;
}).catch(error => {
Expand Down
9 changes: 7 additions & 2 deletions dashboard/src/views/RuleEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<b-form-group label-cols="2" id="rule_interval" label="报警周期*" label-for="rule_interval_input"
:description="'当前:' + (parseInt(form.interval) === 0 ? 1 : form.interval) + ' 分钟,每隔 ' + (parseInt(form.interval) === 0 ? 1 : form.interval) + ' 分钟后触发一次报警'">
<b-form-input id="rule_interval_input" type="range" min="1" max="1440" step="5"
<b-form-input id="rule_interval_input" type="range" min="0" max="1440" step="5"
v-model="form.interval" required/>
</b-form-group>

Expand Down Expand Up @@ -723,7 +723,6 @@
let requestData = {};
requestData.name = this.form.name;
requestData.description = this.form.description;
requestData.interval = this.form.interval * 60;
requestData.rule = this.form.rule;
requestData.tags = this.form.tags;
requestData.template = this.form.template;
Expand All @@ -733,6 +732,12 @@
});
requestData.status = this.form.status ? 'enabled' : 'disabled';
if (this.form.interval <= 0) {
requestData.interval = 60;
} else {
requestData.interval = this.form.interval * 60;
}
return requestData;
},
},
Expand Down
23 changes: 22 additions & 1 deletion internal/job/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (a *AggregationJob) groupingMessages(msgRepo repository.MessageRepo, groupR
}

collectingGroups := make(map[primitive.ObjectID]repository.MessageGroup)
return msgRepo.Traverse(bson.M{"status": repository.MessageStatusPending}, func(msg repository.Message) error {
err = msgRepo.Traverse(bson.M{"status": repository.MessageStatusPending}, func(msg repository.Message) error {
for _, m := range matchers {
matched, err := m.Match(msg)
if err != nil {
Expand Down Expand Up @@ -79,6 +79,27 @@ func (a *AggregationJob) groupingMessages(msgRepo repository.MessageRepo, groupR
"status": msg.Status,
}).Debug("change message status")

return msgRepo.UpdateID(msg.ID, msg)
})
if err != nil {
return err
}

// 将能够与规则匹配的 Canceled 的 message 转换为 Expired
return msgRepo.Traverse(bson.M{"status": repository.MessageStatusCanceled}, func(msg repository.Message) error {
for _, m := range matchers {
matched, err := m.Match(msg)
if err != nil {
continue
}

// if the message matched a rule, update message's group_id and skip to next message
if matched {
msg.Status = repository.MessageStatusExpired
break
}
}

return msgRepo.UpdateID(msg.ID, msg)
})
}
Expand Down
1 change: 1 addition & 0 deletions internal/repository/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
MessageStatusPending MessageStatus = "pending"
MessageStatusGrouped MessageStatus = "grouped"
MessageStatusCanceled MessageStatus = "canceled"
MessageStatusExpired MessageStatus = "expired"
)

type Message struct {
Expand Down

0 comments on commit fbbadcf

Please sign in to comment.