insight metric support formula template (#158)
only support template variable 'bucket_size_in_second' currently, eg frmula: `a/{{.bucket_size_in_second}}` Reviewed-on: https://git.infini.ltd:64443/infini/console/pulls/158 Co-authored-by: liugq <silenceqi@hotmail.com> Co-committed-by: liugq <silenceqi@hotmail.com>
This commit is contained in:
parent
288a2e0304
commit
d0ab79f47d
|
@ -5,8 +5,10 @@
|
|||
package insight
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/Knetic/govaluate"
|
||||
log "github.com/cihub/seelog"
|
||||
"text/template"
|
||||
"infini.sh/console/model/insight"
|
||||
httprouter "infini.sh/framework/core/api/router"
|
||||
"infini.sh/framework/core/elastic"
|
||||
|
@ -224,6 +226,24 @@ func getMetricData(metric *insight.Metric) (interface{}, error) {
|
|||
if len(metric.Items) == 1 && formula == "" {
|
||||
targetMetricData = metricData
|
||||
}else {
|
||||
tpl, err := template.New("insight_formula").Parse(formula)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
msgBuffer := &bytes.Buffer{}
|
||||
params := map[string]interface{}{}
|
||||
if metric.BucketSize != "" {
|
||||
du, err := util.ParseDuration(metric.BucketSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params["bucket_size_in_second"] = du.Seconds()
|
||||
}
|
||||
err = tpl.Execute(msgBuffer, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
formula = msgBuffer.String()
|
||||
for _, md := range metricData {
|
||||
targetData := insight.MetricData{
|
||||
Groups: md.Groups,
|
||||
|
|
|
@ -439,6 +439,7 @@ type RepeatStatus struct {
|
|||
LastRunTime int64 `json:"last_run_time"`
|
||||
NextRunTime int64 `json:"next_run_time"`
|
||||
LastRunChildTaskID string `json:"last_run_child_task_id"`
|
||||
LastCompleteTime int64 `json:"last_complete_time"`
|
||||
}
|
||||
|
||||
func (h *APIHandler) calcRepeatingStatus(taskItem *task.Task) (*task.Task, *RepeatStatus, error) {
|
||||
|
@ -470,6 +471,9 @@ func (h *APIHandler) calcRepeatingStatus(taskItem *task.Task) (*task.Task, *Repe
|
|||
ret.LastRunTime = lastRepeatingChild.StartTimeInMillis
|
||||
if ret.LastRunTime == 0 && lastRunChild != nil {
|
||||
ret.LastRunTime = lastRunChild.StartTimeInMillis
|
||||
if !lastRunChild.CompletedTime.IsZero(){
|
||||
ret.LastCompleteTime = lastRunChild.CompletedTime.UnixMilli()
|
||||
}
|
||||
}
|
||||
if lastRunChild != nil {
|
||||
ret.LastRunChildTaskID = lastRunChild.ID
|
||||
|
|
Loading…
Reference in New Issue