mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #11462 from zhaoxiangchun/automated-cherry-pick-of-#11461-upstream-release-3.7
Automated cherry pick of #11461: fix(monitor): fix monitor overview
This commit is contained in:
@@ -109,9 +109,9 @@ func (c FormatCond) String() string {
|
||||
func (c *QueryCondition) filterTags(tags map[string]string, details monitor.CommonAlertMetricDetails) map[string]string {
|
||||
ret := make(map[string]string)
|
||||
for key, val := range tags {
|
||||
if strings.HasSuffix(key, "_id") {
|
||||
continue
|
||||
}
|
||||
//if strings.HasSuffix(key, "_id") {
|
||||
// continue
|
||||
//}
|
||||
if len(val) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -182,7 +182,6 @@ func (n *notificationService) createAlertRecordWhenNotify(evalCtx *EvalContext,
|
||||
recordCreateInput.ResType = recordCreateInput.AlertRule.ResType
|
||||
createData := recordCreateInput.JSON(recordCreateInput)
|
||||
alert, _ := models.CommonAlertManager.GetAlert(evalCtx.Rule.Id)
|
||||
log.Errorf("alert:%v", jsonutils.Marshal(alert))
|
||||
record, err := db.DoCreate(models.AlertRecordManager, evalCtx.Ctx, evalCtx.UserCred, jsonutils.NewDict(),
|
||||
createData, evalCtx.UserCred)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package models
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -213,6 +214,9 @@ func (record *SAlertRecord) GetMoreDetails(out monitor.AlertRecordDetails) (moni
|
||||
if err != nil {
|
||||
return out, errors.Wrap(err, "record Unmarshal evalMatchs error")
|
||||
}
|
||||
for i, _ := range evalMatchs {
|
||||
evalMatchs[i] = record.filterTags(evalMatchs[i])
|
||||
}
|
||||
out.ResNum = int64(len(evalMatchs))
|
||||
}
|
||||
commonAlert, _ := CommonAlertManager.GetAlert(record.AlertId)
|
||||
@@ -220,6 +224,15 @@ func (record *SAlertRecord) GetMoreDetails(out monitor.AlertRecordDetails) (moni
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (record *SAlertRecord) filterTags(match monitor.EvalMatch) monitor.EvalMatch {
|
||||
for key, _ := range match.Tags {
|
||||
if strings.HasSuffix(key, "_id") {
|
||||
delete(match.Tags, key)
|
||||
}
|
||||
}
|
||||
return match
|
||||
}
|
||||
|
||||
func (man *SAlertRecordManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, _ jsonutils.JSONObject, data monitor.AlertRecordCreateInput) (monitor.AlertRecordCreateInput, error) {
|
||||
return data, nil
|
||||
}
|
||||
@@ -292,19 +305,19 @@ getNewMatchTag:
|
||||
|
||||
func (record *SAlertRecord) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
record.SStatusStandaloneResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
err := MonitorResourceManager.UpdateMonitorResourceAttachJoint(ctx, userCred, record)
|
||||
if err != nil {
|
||||
log.Errorf("UpdateMonitorResourceAttachJoint error: %v", err)
|
||||
}
|
||||
if err := GetAlertResourceManager().ReconcileFromRecord(ctx, userCred, ownerId, record); err != nil {
|
||||
log.Errorf("Reconcile from alert record error: %v", err)
|
||||
return
|
||||
}
|
||||
err := GetAlertResourceManager().NotifyAlertResourceCount(ctx)
|
||||
err = GetAlertResourceManager().NotifyAlertResourceCount(ctx)
|
||||
if err != nil {
|
||||
log.Errorf("NotifyAlertResourceCount error: %v", err)
|
||||
return
|
||||
}
|
||||
err = MonitorResourceManager.UpdateMonitorResourceAttachJoint(ctx, userCred, record)
|
||||
if err != nil {
|
||||
log.Errorf("UpdateMonitorResourceAttachJoint error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (record *SAlertRecord) GetState() monitor.AlertStateType {
|
||||
|
||||
@@ -253,15 +253,19 @@ type AlertStatusCount struct {
|
||||
}
|
||||
|
||||
func (manager *SMonitorResourceManager) GetPropertyAlert(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
scope, _ := query.GetString("scope")
|
||||
data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
scope, _ := data.GetString("scope")
|
||||
if len(scope) == 0 {
|
||||
scope = "system"
|
||||
}
|
||||
result := jsonutils.NewDict()
|
||||
for resType, _ := range GetResourceSyncMap() {
|
||||
query := manager.Query("alert_state")
|
||||
manager.FilterByOwner(query, userCred, rbacutils.TRbacScope(scope))
|
||||
owner, _ := manager.FetchOwnerId(ctx, data)
|
||||
if owner == nil {
|
||||
owner = userCred
|
||||
}
|
||||
manager.FilterByOwner(query, owner, rbacutils.TRbacScope(scope))
|
||||
query.AppendField(sqlchemy.COUNT("count_id", query.Field("id")))
|
||||
input := monitor.MonitorResourceListInput{ResType: resType}
|
||||
query = manager.FieldListFilter(query, input)
|
||||
|
||||
@@ -179,7 +179,7 @@ func GetOnecloudResources(resTyep string) ([]jsonutils.JSONObject, error) {
|
||||
query.Add(jsonutils.NewString("true"), "admin")
|
||||
switch resTyep {
|
||||
case monitor.METRIC_RES_TYPE_HOST:
|
||||
query.Set("host-type", jsonutils.NewString(hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR))
|
||||
//query.Set("host-type", jsonutils.NewString(hostconsts.TELEGRAF_TAG_KEY_HYPERVISOR))
|
||||
allResources, err = ListAllResources(&mc_mds.Hosts, query)
|
||||
case monitor.METRIC_RES_TYPE_GUEST:
|
||||
allResources, err = ListAllResources(&mc_mds.Servers, query)
|
||||
|
||||
Reference in New Issue
Block a user