update group data struct
This commit is contained in:
parent
29223f50a2
commit
49e6e27d3d
|
@ -17,6 +17,12 @@ type Metric struct {
|
|||
Title string `json:"title"` //text template
|
||||
Message string `json:"message"` // text template
|
||||
FormatType string `json:"format_type,omitempty"`
|
||||
Groups []MetricGroupItem `json:"groups"` //bucket group
|
||||
}
|
||||
|
||||
type MetricGroupItem struct {
|
||||
Field string `json:"field"`
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
func (m *Metric) GenerateExpression() (string, error){
|
||||
if len(m.Items) == 1 {
|
||||
|
@ -45,8 +51,6 @@ type MetricItem struct {
|
|||
Name string `json:"name"`
|
||||
Field string `json:"field"`
|
||||
Statistic string `json:"statistic"`
|
||||
Group []string `json:"group"` //bucket group
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
|
||||
type QueryResult struct {
|
||||
|
|
|
@ -76,19 +76,19 @@ func (engine *Engine) GenerateQuery(rule *alerting.Rule, filterParam *alerting.F
|
|||
}
|
||||
|
||||
var rootAggs util.MapStr
|
||||
groups := rule.Metrics.Items[0].Group
|
||||
limit := rule.Metrics.Items[0].Limit
|
||||
//top group 10
|
||||
if limit <= 0 {
|
||||
limit = 10
|
||||
}
|
||||
groups := rule.Metrics.Groups
|
||||
if grpLength := len(groups); grpLength > 0 {
|
||||
var lastGroupAgg util.MapStr
|
||||
|
||||
for i := grpLength-1; i>=0; i-- {
|
||||
limit := groups[i].Limit
|
||||
//top group 10
|
||||
if limit <= 0 {
|
||||
limit = 10
|
||||
}
|
||||
groupAgg := util.MapStr{
|
||||
"terms": util.MapStr{
|
||||
"field": groups[i],
|
||||
"field": groups[i].Field,
|
||||
"size": limit,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue