diff --git a/pkg/apihelper/apihelper.go b/pkg/apihelper/apihelper.go index 5a7cb71135..d49c2c2c47 100644 --- a/pkg/apihelper/apihelper.go +++ b/pkg/apihelper/apihelper.go @@ -137,7 +137,7 @@ func (h *APIHelper) RunManually(ctx context.Context) { func (h *APIHelper) run(ctx context.Context) { changed, err := h.doSync(ctx) if err != nil { - log.Errorln(err) + log.Errorf("doSync error: %v", err) } if changed { mssCopy := h.modelSets.CopyJoined() @@ -161,7 +161,7 @@ func (h *APIHelper) doSync(ctx context.Context) (changed bool, err error) { mss := h.modelSets.Copy() r, err := SyncModelSets(mss, s, h.opts) if err != nil { - return false, err + return false, errors.Wrap(err, "SyncModelSets") } h.modelSets = mss if !r.Correct { diff --git a/pkg/apihelper/interface.go b/pkg/apihelper/interface.go index a44a9bef90..79a54f6274 100644 --- a/pkg/apihelper/interface.go +++ b/pkg/apihelper/interface.go @@ -54,6 +54,10 @@ type IModelListParam interface { ModelParamFilter() jsonutils.JSONObject } +type IModelListSetParams interface { + SetModelListParams(params *jsonutils.JSONDict) *jsonutils.JSONDict +} + func SyncModelSets(mssOld IModelSets, s *mcclient.ClientSession, opt *Options) (r ModelSetsUpdateResult, err error) { mss := mssOld.ModelSetList() mssNews := mssOld.NewEmpty() diff --git a/pkg/apihelper/reflect.go b/pkg/apihelper/reflect.go index 726093d7b6..1603e9afe2 100644 --- a/pkg/apihelper/reflect.go +++ b/pkg/apihelper/reflect.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/printutils" "yunion.io/x/pkg/util/timeutils" @@ -140,6 +141,9 @@ func GetModels(opts *GetModelsOptions) error { filter := inter.ModelParamFilter() params.Update(filter) } + if inter, ok := opts.ModelSet.(IModelListSetParams); ok { + params = inter.SetModelListParams(params) + } //XXX //params.Set(api.LBAGENT_QUERY_ORIG_KEY, jsonutils.NewString(api.LBAGENT_QUERY_ORIG_VAL)) @@ -148,8 +152,8 @@ func GetModels(opts *GetModelsOptions) error { var err error listResult, err := opts.ModelManager.List(opts.ClientSession, params) if err != nil { - return fmt.Errorf("%s: list failed with updated_at.gt('%s'): %s", - manKeyPlural, minUpdatedAt, err) + log.Errorf("%s: list failed with updated_at.gt('%s'): %s", manKeyPlural, minUpdatedAt, err) + return errors.Wrapf(err, "%s list failed with params: %s", manKeyPlural, params.QueryString()) } entriesJson = append(entriesJson, listResult.Data...) if listResult.Offset+len(listResult.Data) >= listResult.Total { diff --git a/pkg/monitor/alerting/conditions/query.go b/pkg/monitor/alerting/conditions/query.go index 40539b2c19..f2923fa36c 100644 --- a/pkg/monitor/alerting/conditions/query.go +++ b/pkg/monitor/alerting/conditions/query.go @@ -246,12 +246,18 @@ func (c *QueryCondition) serieIsLatestResource(resources []jsonutils.JSONObject, tagId = "host_id" } resId := series.Tags[tagId] + log.Debugf("serieIsLatestResource use tagId %q, found resId %q", tagId, resId) if len(resources) != 0 { for _, resource := range resources { id, _ := resource.GetString("id") if resId == id { - // return true, resource - return models.MonitorResourceManager.GetResourceObj(resId) + got, obj := models.MonitorResourceManager.GetResourceObj(resId) + if got { + return true, obj + } else { + log.Warningf("not found resource %s %s from cache, use list item directly", c.ResType, resId) + return true, resource + } } else { continue } diff --git a/pkg/monitor/models/modelset.go b/pkg/monitor/models/modelset.go index d4797785d2..64e7164a0e 100644 --- a/pkg/monitor/models/modelset.go +++ b/pkg/monitor/models/modelset.go @@ -330,6 +330,12 @@ func (s Storages) NeedSync() bool { return true } +func (s Storages) SetModelListParams(params *jsonutils.JSONDict) *jsonutils.JSONDict { + // list storages with details is too long + params.Set("details", jsonutils.JSONFalse) + return params +} + func (d Domains) ModelManager() modulebase.IBaseManager { return &identity.Domains } diff --git a/pkg/monitor/models/monitor_resource.go b/pkg/monitor/models/monitor_resource.go index 62d2e03554..1cc4639b79 100644 --- a/pkg/monitor/models/monitor_resource.go +++ b/pkg/monitor/models/monitor_resource.go @@ -559,7 +559,7 @@ func (manager *SMonitorResourceManager) SyncResources(ctx context.Context, mss * return err } } - log.Infoln("SMonitorResourceManager SyncResources End") + log.Infof("SMonitorResourceManager SyncResources End") err := CommonAlertManager.Run(ctx) if err != nil { log.Errorf("CommonAlertManager UpdateMonitorResourceJoint err:%v", err) diff --git a/pkg/monitor/service/service.go b/pkg/monitor/service/service.go index 74e586dc5e..2f99f31b13 100644 --- a/pkg/monitor/service/service.go +++ b/pkg/monitor/service/service.go @@ -92,7 +92,7 @@ func StartService() { if err != nil { log.Fatalf("new worker failed: %v", err) } - go worker.Start(context.Background(), app, "") + go worker.Start(app.GetContext(), app, "") //common_app.ServeForever(app, baseOpts) InitInfluxDBSubscriptionHandlers(app, baseOpts)