未验证 提交 63aa6157 编写于 作者: Y Yening Qin 提交者: GitHub

compatible with TDSQL-C Mysql (#1511)

上级 2a369027
......@@ -42,6 +42,9 @@ alter table `alert_his_event` add annotations text not null comment 'annotations
alter table `alert_his_event` add rule_config text not null comment 'rule_config';
alter table `alerting_engines` add datasource_id bigint unsigned not null default 0;
alter table `alerting_engines` change cluster engine_cluster varchar(128) not null default '' comment 'n9e engine cluster';
alter table `task_record` add event_id bigint not null comment 'event id' default 0;
CREATE TABLE `datasource`
(
......
......@@ -680,13 +680,13 @@ CREATE TABLE alerting_engines
id serial,
instance varchar(128) not null default '' ,
datasource_id bigint not null default 0 ,
cluster varchar(128) not null default '' ,
engine_cluster varchar(128) not null default '' ,
clock bigint not null,
PRIMARY KEY (id)
) ;
COMMENT ON COLUMN alerting_engines.instance IS 'instance identification, e.g. 10.9.0.9:9090';
COMMENT ON COLUMN alerting_engines.datasource_id IS 'datasource id';
COMMENT ON COLUMN alerting_engines.cluster IS 'target reader cluster';
COMMENT ON COLUMN alerting_engines.engine_cluster IS 'target reader cluster';
CREATE TABLE datasource
......
......@@ -557,12 +557,11 @@ CREATE TABLE `alerting_engines`
`id` int unsigned NOT NULL AUTO_INCREMENT,
`instance` varchar(128) not null default '' comment 'instance identification, e.g. 10.9.0.9:9090',
`datasource_id` bigint not null default 0 comment 'datasource id',
`cluster` varchar(128) not null default '' comment 'n9e-alert cluster',
`engine_cluster` varchar(128) not null default '' comment 'n9e-alert cluster',
`clock` bigint not null,
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
CREATE TABLE `datasource`
(
`id` int unsigned NOT NULL AUTO_INCREMENT,
......
......@@ -8,11 +8,11 @@ import (
)
type AlertingEngines struct {
Id int64 `json:"id" gorm:"primaryKey"`
Instance string `json:"instance"`
Cluster string `json:"cluster"`
DatasourceId int64 `json:"datasource_id"`
Clock int64 `json:"clock"`
Id int64 `json:"id" gorm:"primaryKey"`
Instance string `json:"instance"`
EngineCluster string `json:"cluster" gorm:"engine_cluster"`
DatasourceId int64 `json:"datasource_id"`
Clock int64 `json:"clock"`
}
func (e *AlertingEngines) TableName() string {
......@@ -130,7 +130,7 @@ func AlertingEngineGetsInstances(ctx *ctx.Context, where string, args ...interfa
func AlertingEngineHeartbeatWithCluster(ctx *ctx.Context, instance, cluster string, datasourceId int64) error {
var total int64
err := DB(ctx).Model(new(AlertingEngines)).Where("instance=? and `cluster` = ? and datasource_id=?", instance, cluster, datasourceId).Count(&total).Error
err := DB(ctx).Model(new(AlertingEngines)).Where("instance=? and engine_cluster = ? and datasource_id=?", instance, cluster, datasourceId).Count(&total).Error
if err != nil {
return err
}
......@@ -138,15 +138,15 @@ func AlertingEngineHeartbeatWithCluster(ctx *ctx.Context, instance, cluster stri
if total == 0 {
// insert
err = DB(ctx).Create(&AlertingEngines{
Instance: instance,
DatasourceId: datasourceId,
Cluster: cluster,
Clock: time.Now().Unix(),
Instance: instance,
DatasourceId: datasourceId,
EngineCluster: cluster,
Clock: time.Now().Unix(),
}).Error
} else {
// updates
fields := map[string]interface{}{"clock": time.Now().Unix()}
err = DB(ctx).Model(new(AlertingEngines)).Where("instance=? and `cluster` = ? and datasource_id=?", instance, cluster, datasourceId).Updates(fields).Error
err = DB(ctx).Model(new(AlertingEngines)).Where("instance=? and engine_cluster = ? and datasource_id=?", instance, cluster, datasourceId).Updates(fields).Error
}
return err
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册