mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(monitor): skip check series options
This commit is contained in:
@@ -77,14 +77,14 @@ type MetricInputQuery struct {
|
||||
Slimit string `json:"slimit"`
|
||||
Soffset string `json:"soffset"`
|
||||
//default group by
|
||||
Unit bool `json:"unit"`
|
||||
Interval string `json:"interval"`
|
||||
DomainId string `json:"domain_id"`
|
||||
ProjectId string `json:"project_id"`
|
||||
MetricQuery []*AlertQuery `json:"metric_query"`
|
||||
Signature string `json:"signature"`
|
||||
ShowMeta bool `json:"show_meta"`
|
||||
ForceCheckSeries bool `json:"force_check_series"`
|
||||
Unit bool `json:"unit"`
|
||||
Interval string `json:"interval"`
|
||||
DomainId string `json:"domain_id"`
|
||||
ProjectId string `json:"project_id"`
|
||||
MetricQuery []*AlertQuery `json:"metric_query"`
|
||||
Signature string `json:"signature"`
|
||||
ShowMeta bool `json:"show_meta"`
|
||||
SkipCheckSeries bool `json:"skip_check_series"`
|
||||
}
|
||||
|
||||
type SimpleQueryInput struct {
|
||||
|
||||
@@ -71,7 +71,7 @@ func NewMetricQueryCondition(models []*monitor.AlertCondition) (*MetricQueryCond
|
||||
return cond, nil
|
||||
}
|
||||
|
||||
func (query *MetricQueryCondition) ExecuteQuery(userCred mcclient.TokenCredential, forceCheckSeries bool) (*mq.Metrics, error) {
|
||||
func (query *MetricQueryCondition) ExecuteQuery(userCred mcclient.TokenCredential, skipCheckSeries bool) (*mq.Metrics, error) {
|
||||
firstCond := query.QueryCons[0]
|
||||
timeRange := tsdb.NewTimeRange(firstCond.Query.From, firstCond.Query.To)
|
||||
ctx := gocontext.Background()
|
||||
@@ -88,7 +88,7 @@ func (query *MetricQueryCondition) ExecuteQuery(userCred mcclient.TokenCredentia
|
||||
Series: make(tsdb.TimeSeriesSlice, 0),
|
||||
Metas: queryResult.metas,
|
||||
}
|
||||
if query.noCheckSeries() && !forceCheckSeries {
|
||||
if query.noCheckSeries(skipCheckSeries) {
|
||||
metrics.Series = queryResult.series
|
||||
return &metrics, nil
|
||||
}
|
||||
@@ -110,16 +110,26 @@ func (query *MetricQueryCondition) ExecuteQuery(userCred mcclient.TokenCredentia
|
||||
return &metrics, nil
|
||||
}
|
||||
|
||||
func (query *MetricQueryCondition) noCheckSeries() bool {
|
||||
if len(query.QueryCons[0].ResType) == 0 ||
|
||||
strings.HasPrefix(query.QueryCons[0].ResType, monitor.EXT_PREFIX) {
|
||||
func (query *MetricQueryCondition) noCheckSeries(skipCheckSeries bool) bool {
|
||||
firstCond := query.QueryCons[0]
|
||||
// always check series when resource type is "" or external resource
|
||||
if len(firstCond.ResType) == 0 || strings.HasPrefix(firstCond.ResType, monitor.EXT_PREFIX) {
|
||||
return true
|
||||
}
|
||||
if len(query.QueryCons[0].Query.Model.GroupBy) == 0 {
|
||||
if len(firstCond.Query.Model.GroupBy) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if skipCheckSeries {
|
||||
return true
|
||||
}
|
||||
|
||||
groupBys := make([]string, 0)
|
||||
for _, groupby := range query.QueryCons[0].Query.Model.GroupBy {
|
||||
containGlob := false
|
||||
for _, groupby := range firstCond.Query.Model.GroupBy {
|
||||
if utils.IsInStringArray("*", groupby.Params) {
|
||||
containGlob = true
|
||||
}
|
||||
groupBys = append(groupBys, groupby.Params...)
|
||||
}
|
||||
for _, supportId := range monitor.MEASUREMENT_TAG_ID {
|
||||
@@ -127,6 +137,9 @@ func (query *MetricQueryCondition) noCheckSeries() bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if containGlob {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -592,6 +592,8 @@ func (self *SDataSourceManager) GetMetricMeasurement(userCred mcclient.TokenCred
|
||||
return nil, errors.Wrap(err, "getFromAndToFromParam")
|
||||
}
|
||||
|
||||
skipCheckSeries := jsonutils.QueryBoolean(query, "skip_check_series", false)
|
||||
|
||||
db := influxdb.NewInfluxdb(dataSource.Url)
|
||||
db.SetDatabase(database)
|
||||
|
||||
@@ -637,7 +639,7 @@ func (self *SDataSourceManager) GetMetricMeasurement(userCred mcclient.TokenCred
|
||||
// if err != nil {
|
||||
// return jsonutils.JSONNull, errors.Wrap(err, "getTagValue error")
|
||||
//** }
|
||||
if err := getTagValues(userCred, output, timeF, dataSource.GetId(), tagFilter); err != nil {
|
||||
if err := getTagValues(userCred, output, timeF, dataSource.GetId(), tagFilter, skipCheckSeries); err != nil {
|
||||
return jsonutils.JSONNull, errors.Wrap(err, "getTagValues error")
|
||||
}
|
||||
|
||||
@@ -826,7 +828,7 @@ func getAttributesOnMeasurement(database, tp string, output *monitor.InfluxMeasu
|
||||
return nil
|
||||
}
|
||||
|
||||
func getTagValues(userCred mcclient.TokenCredential, output *monitor.InfluxMeasurement, timeF timeFilter, dsId string, tagFilter string) error {
|
||||
func getTagValues(userCred mcclient.TokenCredential, output *monitor.InfluxMeasurement, timeF timeFilter, dsId string, tagFilter string, skipCheckSeries bool) error {
|
||||
mq := monitor.MetricQuery{
|
||||
Database: output.Database,
|
||||
Measurement: output.Measurement,
|
||||
@@ -872,7 +874,7 @@ func getTagValues(userCred mcclient.TokenCredential, output *monitor.InfluxMeasu
|
||||
MetricQuery: []*monitor.AlertQuery{
|
||||
aq,
|
||||
},
|
||||
ForceCheckSeries: true,
|
||||
SkipCheckSeries: skipCheckSeries,
|
||||
}
|
||||
|
||||
ret, err := doQuery(userCred, q)
|
||||
|
||||
@@ -294,7 +294,7 @@ func doQuery(userCred mcclient.TokenCredential, query monitor.MetricInputQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
metrics, err := metricQ.ExecuteQuery(userCred, query.ForceCheckSeries)
|
||||
metrics, err := metricQ.ExecuteQuery(userCred, query.SkipCheckSeries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user