Merge pull request #12038 from zhaoxiangchun/feature/zxc-agent-metirc

fix(monitor): monitor rds sync
This commit is contained in:
Zexi Li
2021-08-27 16:56:42 +08:00
committed by GitHub
5 changed files with 118 additions and 6 deletions
+11 -1
View File
@@ -22,6 +22,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/apis/monitor"
"yunion.io/x/onecloud/pkg/monitor/alerting"
@@ -107,7 +108,16 @@ func (query *MetricQueryCondition) noCheckSeries() bool {
if len(query.QueryCons[0].Query.Model.GroupBy) == 0 {
return true
}
return false
groupBys := make([]string, 0)
for _, groupby := range query.QueryCons[0].Query.Model.GroupBy {
groupBys = append(groupBys, groupby.Params...)
}
for _, supportId := range monitor.MEASUREMENT_TAG_ID {
if utils.IsInStringArray(supportId, groupBys) {
return false
}
}
return true
}
func (c *MetricQueryCondition) executeQuery(context *alerting.EvalContext, timeRange *tsdb.TimeRange) (*queryResult, error) {
+92
View File
@@ -19,6 +19,7 @@ import (
"yunion.io/x/onecloud/pkg/apis/monitor"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
compute_models "yunion.io/x/onecloud/pkg/compute/models"
keystone_models "yunion.io/x/onecloud/pkg/keystone/models"
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
mcclient_modules "yunion.io/x/onecloud/pkg/mcclient/modules"
)
@@ -26,6 +27,7 @@ import (
type IMonitorResModelSet interface {
apihelper.IModelSet
GetResType() string
NeedSync() bool
}
type (
@@ -36,6 +38,8 @@ type (
Oss map[string]*SOss
Accounts map[string]*SAccount
Storages map[string]*SStorage
Domains map[string]*SDomain
Projects map[string]*SProject
)
type Details struct {
@@ -91,6 +95,16 @@ type SAccount struct {
Details
}
type SDomain struct {
Id string
keystone_models.SDomain
}
type SProject struct {
Id string
keystone_models.SProject
}
func (s Servers) ModelManager() modulebase.IBaseManager {
return &mcclient_modules.Servers
}
@@ -112,6 +126,10 @@ func (s Servers) GetResType() string {
return monitor.METRIC_RES_TYPE_GUEST
}
func (s Servers) NeedSync() bool {
return true
}
func (h Hosts) AddModel(i db.IModel) {
resource := i.(*Host)
h[resource.Id] = resource
@@ -133,6 +151,10 @@ func (h Hosts) GetResType() string {
return monitor.METRIC_RES_TYPE_HOST
}
func (s Hosts) NeedSync() bool {
return true
}
func (r Rds) ModelManager() modulebase.IBaseManager {
return &mcclient_modules.DBInstance
}
@@ -154,6 +176,10 @@ func (r Rds) GetResType() string {
return monitor.METRIC_RES_TYPE_RDS
}
func (s Rds) NeedSync() bool {
return true
}
func (r Redis) ModelManager() modulebase.IBaseManager {
return &mcclient_modules.ElasticCache
}
@@ -175,6 +201,10 @@ func (r Redis) GetResType() string {
return monitor.METRIC_RES_TYPE_REDIS
}
func (s Redis) NeedSync() bool {
return true
}
func (o Oss) ModelManager() modulebase.IBaseManager {
return &mcclient_modules.Buckets
}
@@ -196,6 +226,10 @@ func (o Oss) GetResType() string {
return monitor.METRIC_RES_TYPE_OSS
}
func (s Oss) NeedSync() bool {
return true
}
func (a Accounts) ModelManager() modulebase.IBaseManager {
return &mcclient_modules.Cloudaccounts
}
@@ -217,6 +251,10 @@ func (a Accounts) GetResType() string {
return monitor.METRIC_RES_TYPE_CLOUDACCOUNT
}
func (s Accounts) NeedSync() bool {
return true
}
func (s Storages) ModelManager() modulebase.IBaseManager {
return &mcclient_modules.Storages
}
@@ -237,3 +275,57 @@ func (s Storages) Copy() apihelper.IModelSet {
func (s Storages) GetResType() string {
return monitor.METRIC_RES_TYPE_STORAGE
}
func (s Storages) NeedSync() bool {
return true
}
func (d Domains) ModelManager() modulebase.IBaseManager {
return &mcclient_modules.Domains
}
func (d Domains) NewModel() db.IModel {
return &SDomain{}
}
func (d Domains) AddModel(i db.IModel) {
resource := i.(*SDomain)
d[resource.Id] = resource
}
func (d Domains) Copy() apihelper.IModelSet {
return d
}
func (d Domains) GetResType() string {
return monitor.METRIC_RES_TYPE_DOMAIN
}
func (d Domains) NeedSync() bool {
return false
}
func (p Projects) ModelManager() modulebase.IBaseManager {
return &mcclient_modules.Projects
}
func (p Projects) NewModel() db.IModel {
return &SProject{}
}
func (p Projects) AddModel(i db.IModel) {
resource := i.(*SProject)
p[resource.Id] = resource
}
func (p Projects) Copy() apihelper.IModelSet {
return p
}
func (p Projects) GetResType() string {
return monitor.METRIC_RES_TYPE_TENANT
}
func (p Projects) NeedSync() bool {
return false
}
+6
View File
@@ -24,6 +24,8 @@ type MonitorResModelSets struct {
Oss Oss
Accounts Accounts
Storages Storages
Domains Domains
Projects Projects
}
func (m *MonitorResModelSets) NewEmpty() apihelper.IModelSets {
@@ -39,6 +41,8 @@ func (m *MonitorResModelSets) ModelSetList() []apihelper.IModelSet {
m.Oss,
m.Accounts,
m.Storages,
m.Domains,
m.Projects,
}
}
@@ -78,5 +82,7 @@ func NewModelSets() *MonitorResModelSets {
Oss: Oss{},
Accounts: Accounts{},
Storages: Storages{},
Domains: Domains{},
Projects: Projects{},
}
}
+8 -4
View File
@@ -425,8 +425,12 @@ func (manager *SMonitorResourceManager) SyncResources(ctx context.Context, mss *
log.Infoln("start sync")
for _, set := range mss.ModelSetList() {
setRv := reflect.ValueOf(set)
typ := manager.GetSetType(set)
needSync, typ := manager.GetSetType(set)
log.Infof("Type: %s,length: %d", typ, len(setRv.MapKeys()))
if !needSync {
log.Infof("Type: %s don't sync", typ)
continue
}
for _, kRv := range setRv.MapKeys() {
mRv := setRv.MapIndex(kRv)
//log.Errorf("resID:%s", kRv.String())
@@ -479,11 +483,11 @@ func (manager *SMonitorResourceManager) SyncResources(ctx context.Context, mss *
return errors.NewAggregate(errs)
}
func (manager *SMonitorResourceManager) GetSetType(set apihelper.IModelSet) string {
func (manager *SMonitorResourceManager) GetSetType(set apihelper.IModelSet) (bool, string) {
if iset, ok := set.(IMonitorResModelSet); ok {
return iset.GetResType()
return iset.NeedSync(), iset.GetResType()
}
return "NONE"
return false, "NONE"
}
func newMonitorResourceCreateInput(input jsonutils.JSONObject, typ string) jsonutils.JSONObject {
+1 -1
View File
@@ -138,7 +138,7 @@ type RdsResourceSync struct {
func NewRdsResourceSync() IResourceSync {
if rdsResourceSync == nil {
sync := new(RedisResourceSync)
sync := new(RdsResourceSync)
obj := newSyncObj(sync)
sync.SyncObject = obj
rdsResourceSync = sync