Skip to content

Commit 6617754

Browse files
askyrieSongZhen0704
authored andcommitted
feat: vtap add exception description
1 parent cb14528 commit 6617754

11 files changed

Lines changed: 187 additions & 111 deletions

File tree

message/agent.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ message SyncRequest {
102102
optional uint64 version_groups = 11 [default = 0];
103103
optional string current_k8s_image = 12;
104104
optional CustomAppConfig custom_app_config = 13; // agent will only populate `version`
105+
optional string exception_description = 14;
105106

106107
optional string ctrl_ip = 21;
107108
optional string host = 22; // 表示hostname,操作系统的原始主机名,注册和信息同步使用

server/controller/db/metadb/migrator/schema/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ const (
2020
RAW_SQL_ROOT_DIR = "/etc/metadb/schema/rawsql"
2121

2222
DB_VERSION_TABLE = "db_version"
23-
DB_VERSION_EXPECTED = "7.1.0.37"
23+
DB_VERSION_EXPECTED = "7.1.0.38"
2424
)

server/controller/db/metadb/migrator/schema/rawsql/mysql/ddl_create_table.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ CREATE TABLE IF NOT EXISTS vtap (
212212
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
213213
boot_time INTEGER DEFAULT 0,
214214
exceptions BIGINT UNSIGNED DEFAULT 0,
215+
exception_description VARCHAR(256) DEFAULT '',
215216
vtap_lcuuid CHAR(64) DEFAULT NULL,
216217
vtap_group_lcuuid CHAR(64) DEFAULT NULL,
217218
cpu_num INTEGER DEFAULT 0 COMMENT 'logical number of cpu',
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- ColumnExists function
2+
DROP PROCEDURE IF EXISTS ColumnExists;
3+
4+
CREATE PROCEDURE ColumnExists(
5+
IN p_table_name VARCHAR(255),
6+
IN p_col_name VARCHAR(255),
7+
OUT p_exists TINYINT(1)
8+
)
9+
BEGIN
10+
SELECT COUNT(*) > 0
11+
INTO p_exists
12+
FROM information_schema.columns
13+
WHERE TABLE_SCHEMA = DATABASE()
14+
AND TABLE_NAME = p_table_name
15+
AND COLUMN_NAME = p_col_name;
16+
END;
17+
18+
-- AddColumnIfNotExists procedure
19+
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
20+
21+
CREATE PROCEDURE AddColumnIfNotExists(
22+
IN tableName VARCHAR(255),
23+
IN colName VARCHAR(255),
24+
IN colType VARCHAR(255),
25+
IN afterCol VARCHAR(255)
26+
)
27+
BEGIN
28+
CALL ColumnExists(tableName, colName, @exists);
29+
IF NOT @exists THEN
30+
SET @sql = CONCAT('ALTER TABLE ', tableName, ' ADD COLUMN ', colName, ' ', colType, ' AFTER ', afterCol);
31+
PREPARE stmt FROM @sql;
32+
EXECUTE stmt;
33+
DEALLOCATE PREPARE stmt;
34+
END IF;
35+
END;
36+
CALL AddColumnIfNotExists('vtap', 'exception_description', "VARCHAR(256) DEFAULT ''", 'exceptions');
37+
38+
-- Cleanup
39+
DROP PROCEDURE IF EXISTS ColumnExists;
40+
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
41+
42+
-- Update DB version
43+
UPDATE db_version SET version='7.1.0.38';

server/controller/db/metadb/migrator/schema/rawsql/postgres/ddl_create_table.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ CREATE TABLE IF NOT EXISTS vtap (
218218
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
219219
boot_time INTEGER DEFAULT 0,
220220
exceptions BIGINT DEFAULT 0 CHECK (exceptions >= 0),
221+
exception_description VARCHAR(256) DEFAULT '',
221222
vtap_lcuuid VARCHAR(64) DEFAULT NULL,
222223
vtap_group_lcuuid VARCHAR(64) DEFAULT NULL,
223224
cpu_num INTEGER DEFAULT 0,

server/controller/db/metadb/model/model.go

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -166,50 +166,51 @@ func (AZAnalyzerConnection) TableName() string {
166166
}
167167

168168
type VTap struct {
169-
ID int `gorm:"primaryKey;column:id;type:int;not null" json:"ID"`
170-
Name string `gorm:"column:name;type:varchar(256);not null" json:"NAME"`
171-
RawHostname string `gorm:"column:raw_hostname;type:varchar(256);" json:"RAW_HOSTNAME"`
172-
Owner string `gorm:"column:owner;type:varchar(64);default:''" json:"OWNER"`
173-
State int `gorm:"column:state;type:int;default:1" json:"STATE"` // 0.not-connected 1.normal
174-
Enable int `gorm:"column:enable;type:int;default:1" json:"ENABLE"` // 0: stop 1: running
175-
Type int `gorm:"column:type;type:int;default:0" json:"TYPE"` // 1: process 2: vm 3: public cloud 4: analyzer 5: physical machine 6: dedicated physical machine 7: host pod 8: vm pod
176-
CtrlIP string `gorm:"column:ctrl_ip;type:char(64);not null" json:"CTRL_IP"`
177-
CtrlMac string `gorm:"column:ctrl_mac;type:char(64);default:null" json:"CTRL_MAC"`
178-
TapMac string `gorm:"column:tap_mac;type:char(64);default:null" json:"TAP_MAC"`
179-
AnalyzerIP string `gorm:"column:analyzer_ip;type:char(64);not null" json:"ANALYZER_IP"`
180-
CurAnalyzerIP string `gorm:"column:cur_analyzer_ip;type:char(64);not null" json:"CUR_ANALYZER_IP"`
181-
ControllerIP string `gorm:"column:controller_ip;type:char(64);not null" json:"CONTROLLER_IP"`
182-
CurControllerIP string `gorm:"column:cur_controller_ip;type:char(64);not null" json:"CUR_CONTROLLER_IP"`
183-
LaunchServer string `gorm:"column:launch_server;type:char(64);not null" json:"LAUNCH_SERVER"`
184-
LaunchServerID int `gorm:"column:launch_server_id;type:int;default:null" json:"LAUNCH_SERVER_ID"`
185-
AZ string `gorm:"column:az;type:char(64);default:''" json:"AZ"`
186-
Region string `gorm:"column:region;type:char(64);default:''" json:"REGION"`
187-
Revision string `gorm:"column:revision;type:varchar(256);default:null" json:"REVISION"`
188-
SyncedControllerAt time.Time `gorm:"column:synced_controller_at;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"SYNCED_CONTROLLER_AT"`
189-
SyncedAnalyzerAt time.Time `gorm:"column:synced_analyzer_at;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"SYNCED_ANALYZER_AT"`
190-
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"CREATED_AT"`
191-
BootTime int `gorm:"column:boot_time;type:int;default:0" json:"BOOT_TIME"`
192-
Exceptions int64 `gorm:"column:exceptions;type:bigint unsigned;default:0" json:"EXCEPTIONS"`
193-
VTapLcuuid string `gorm:"column:vtap_lcuuid;type:char(64);default:null" json:"VTAP_LCUUID"`
194-
VtapGroupLcuuid string `gorm:"column:vtap_group_lcuuid;type:char(64);default:null" json:"VTAP_GROUP_LCUUID"`
195-
CPUNum int `gorm:"column:cpu_num;type:int;default:0" json:"CPU_NUM"` // logical number of cpu
196-
MemorySize int64 `gorm:"column:memory_size;type:bigint;default:0" json:"MEMORY_SIZE"`
197-
GRPCBufferSize uint64 `gorm:"column:grpc_buffer_size;type:bigint;default:0" json:"GRPC_BUFFER_SIZE"`
198-
Arch string `gorm:"column:arch;type:varchar(256);default:null" json:"ARCH"`
199-
Os string `gorm:"column:os;type:varchar(256);default:null" json:"OS"`
200-
KernelVersion string `gorm:"column:kernel_version;type:varchar(256);default:null" json:"KERNEL_VERSION"`
201-
ProcessName string `gorm:"column:process_name;type:varchar(256);default:null" json:"PROCESS_NAME"`
202-
CurrentK8sImage string `gorm:"column:current_k8s_image;type:varchar(512);default:null" json:"CURRENT_K8S_IMAGE"`
203-
LicenseType int `gorm:"column:license_type;type:int;default:null" json:"LICENSE_TYPE"` // 1: A类 2: B类 3: C类
204-
LicenseFunctions string `gorm:"column:license_functions;type:char(64)" json:"LICENSE_FUNCTIONS"` // separated by ,; 1: 流量分发 2: 网络监控 3: 应用监控
205-
EnableFeatures string `gorm:"column:enable_features;type:char(64)" json:"ENABLE_FEATURES"` // separated by ,
206-
DisableFeatures string `gorm:"column:disable_features;type:char(64)" json:"DISABLE_FEATURES"` // separated by ,
207-
FollowGroupFeatures string `gorm:"column:follow_group_features;type:char(64)" json:"FOLLOW_GROUP_FEATURES"` // separated by ,
208-
TapMode int `gorm:"column:tap_mode;type:int;default:null" json:"TAP_MODE"`
209-
ExpectedRevision string `gorm:"column:expected_revision;type:text;default null" json:"EXPECTED_REVISION"`
210-
UpgradePackage string `gorm:"column:upgrade_package;type:text;default null" json:"UPGRADE_PACKAGE"`
211-
TeamID int `gorm:"column:team_id;type:int;default:0" json:"TEAM_ID"`
212-
Lcuuid string `gorm:"column:lcuuid;type:char(64);not null" json:"LCUUID"`
169+
ID int `gorm:"primaryKey;column:id;type:int;not null" json:"ID"`
170+
Name string `gorm:"column:name;type:varchar(256);not null" json:"NAME"`
171+
RawHostname string `gorm:"column:raw_hostname;type:varchar(256);" json:"RAW_HOSTNAME"`
172+
Owner string `gorm:"column:owner;type:varchar(64);default:''" json:"OWNER"`
173+
State int `gorm:"column:state;type:int;default:1" json:"STATE"` // 0.not-connected 1.normal
174+
Enable int `gorm:"column:enable;type:int;default:1" json:"ENABLE"` // 0: stop 1: running
175+
Type int `gorm:"column:type;type:int;default:0" json:"TYPE"` // 1: process 2: vm 3: public cloud 4: analyzer 5: physical machine 6: dedicated physical machine 7: host pod 8: vm pod
176+
CtrlIP string `gorm:"column:ctrl_ip;type:char(64);not null" json:"CTRL_IP"`
177+
CtrlMac string `gorm:"column:ctrl_mac;type:char(64);default:null" json:"CTRL_MAC"`
178+
TapMac string `gorm:"column:tap_mac;type:char(64);default:null" json:"TAP_MAC"`
179+
AnalyzerIP string `gorm:"column:analyzer_ip;type:char(64);not null" json:"ANALYZER_IP"`
180+
CurAnalyzerIP string `gorm:"column:cur_analyzer_ip;type:char(64);not null" json:"CUR_ANALYZER_IP"`
181+
ControllerIP string `gorm:"column:controller_ip;type:char(64);not null" json:"CONTROLLER_IP"`
182+
CurControllerIP string `gorm:"column:cur_controller_ip;type:char(64);not null" json:"CUR_CONTROLLER_IP"`
183+
LaunchServer string `gorm:"column:launch_server;type:char(64);not null" json:"LAUNCH_SERVER"`
184+
LaunchServerID int `gorm:"column:launch_server_id;type:int;default:null" json:"LAUNCH_SERVER_ID"`
185+
AZ string `gorm:"column:az;type:char(64);default:''" json:"AZ"`
186+
Region string `gorm:"column:region;type:char(64);default:''" json:"REGION"`
187+
Revision string `gorm:"column:revision;type:varchar(256);default:null" json:"REVISION"`
188+
SyncedControllerAt time.Time `gorm:"column:synced_controller_at;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"SYNCED_CONTROLLER_AT"`
189+
SyncedAnalyzerAt time.Time `gorm:"column:synced_analyzer_at;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"SYNCED_ANALYZER_AT"`
190+
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"CREATED_AT"`
191+
BootTime int `gorm:"column:boot_time;type:int;default:0" json:"BOOT_TIME"`
192+
Exceptions int64 `gorm:"column:exceptions;type:bigint unsigned;default:0" json:"EXCEPTIONS"`
193+
ExceptionDescription string `gorm:"column:exception_description;type:varchar(256);default:''" json:"EXCEPTION_DESCRIPTION"`
194+
VTapLcuuid string `gorm:"column:vtap_lcuuid;type:char(64);default:null" json:"VTAP_LCUUID"`
195+
VtapGroupLcuuid string `gorm:"column:vtap_group_lcuuid;type:char(64);default:null" json:"VTAP_GROUP_LCUUID"`
196+
CPUNum int `gorm:"column:cpu_num;type:int;default:0" json:"CPU_NUM"` // logical number of cpu
197+
MemorySize int64 `gorm:"column:memory_size;type:bigint;default:0" json:"MEMORY_SIZE"`
198+
GRPCBufferSize uint64 `gorm:"column:grpc_buffer_size;type:bigint;default:0" json:"GRPC_BUFFER_SIZE"`
199+
Arch string `gorm:"column:arch;type:varchar(256);default:null" json:"ARCH"`
200+
Os string `gorm:"column:os;type:varchar(256);default:null" json:"OS"`
201+
KernelVersion string `gorm:"column:kernel_version;type:varchar(256);default:null" json:"KERNEL_VERSION"`
202+
ProcessName string `gorm:"column:process_name;type:varchar(256);default:null" json:"PROCESS_NAME"`
203+
CurrentK8sImage string `gorm:"column:current_k8s_image;type:varchar(512);default:null" json:"CURRENT_K8S_IMAGE"`
204+
LicenseType int `gorm:"column:license_type;type:int;default:null" json:"LICENSE_TYPE"` // 1: A类 2: B类 3: C类
205+
LicenseFunctions string `gorm:"column:license_functions;type:char(64)" json:"LICENSE_FUNCTIONS"` // separated by ,; 1: 流量分发 2: 网络监控 3: 应用监控
206+
EnableFeatures string `gorm:"column:enable_features;type:char(64)" json:"ENABLE_FEATURES"` // separated by ,
207+
DisableFeatures string `gorm:"column:disable_features;type:char(64)" json:"DISABLE_FEATURES"` // separated by ,
208+
FollowGroupFeatures string `gorm:"column:follow_group_features;type:char(64)" json:"FOLLOW_GROUP_FEATURES"` // separated by ,
209+
TapMode int `gorm:"column:tap_mode;type:int;default:null" json:"TAP_MODE"`
210+
ExpectedRevision string `gorm:"column:expected_revision;type:text;default null" json:"EXPECTED_REVISION"`
211+
UpgradePackage string `gorm:"column:upgrade_package;type:text;default null" json:"UPGRADE_PACKAGE"`
212+
TeamID int `gorm:"column:team_id;type:int;default:0" json:"TEAM_ID"`
213+
Lcuuid string `gorm:"column:lcuuid;type:char(64);not null" json:"LCUUID"`
213214
}
214215

215216
func (VTap) TableName() string {

server/controller/http/service/vtap.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -179,32 +179,33 @@ func (a *Agent) Get(filter map[string]interface{}) (resp []model.Vtap, err error
179179
}
180180
for _, vtap := range agents {
181181
vtapResp := model.Vtap{
182-
ID: vtap.ID,
183-
Name: vtap.Name,
184-
Lcuuid: vtap.Lcuuid,
185-
Enable: vtap.Enable,
186-
Type: vtap.Type,
187-
CtrlIP: vtap.CtrlIP,
188-
CtrlMac: vtap.CtrlMac,
189-
ControllerIP: vtap.ControllerIP,
190-
AnalyzerIP: vtap.AnalyzerIP,
191-
CurControllerIP: vtap.CurControllerIP,
192-
CurAnalyzerIP: vtap.CurAnalyzerIP,
193-
BootTime: vtap.BootTime,
194-
CPUNum: vtap.CPUNum,
195-
MemorySize: vtap.MemorySize,
196-
Arch: vtap.Arch,
197-
ArchType: common.GetArchType(vtap.Arch),
198-
Os: vtap.Os,
199-
OsType: common.GetOsType(vtap.Os),
200-
KernelVersion: vtap.KernelVersion,
201-
ProcessName: vtap.ProcessName,
202-
CurrentK8sImage: vtap.CurrentK8sImage,
203-
LicenseType: vtap.LicenseType,
204-
ExpectedRevision: vtap.ExpectedRevision,
205-
UpgradePackage: vtap.UpgradePackage,
206-
TapMode: vtap.TapMode,
207-
TeamID: vtap.TeamID,
182+
ID: vtap.ID,
183+
Name: vtap.Name,
184+
Lcuuid: vtap.Lcuuid,
185+
Enable: vtap.Enable,
186+
Type: vtap.Type,
187+
CtrlIP: vtap.CtrlIP,
188+
CtrlMac: vtap.CtrlMac,
189+
ControllerIP: vtap.ControllerIP,
190+
AnalyzerIP: vtap.AnalyzerIP,
191+
CurControllerIP: vtap.CurControllerIP,
192+
CurAnalyzerIP: vtap.CurAnalyzerIP,
193+
BootTime: vtap.BootTime,
194+
CPUNum: vtap.CPUNum,
195+
MemorySize: vtap.MemorySize,
196+
Arch: vtap.Arch,
197+
ArchType: common.GetArchType(vtap.Arch),
198+
Os: vtap.Os,
199+
OsType: common.GetOsType(vtap.Os),
200+
KernelVersion: vtap.KernelVersion,
201+
ProcessName: vtap.ProcessName,
202+
CurrentK8sImage: vtap.CurrentK8sImage,
203+
LicenseType: vtap.LicenseType,
204+
ExpectedRevision: vtap.ExpectedRevision,
205+
ExceptionDescription: vtap.ExceptionDescription,
206+
UpgradePackage: vtap.UpgradePackage,
207+
TapMode: vtap.TapMode,
208+
TeamID: vtap.TeamID,
208209
}
209210
// state
210211
if vtap.Enable == common.VTAP_ENABLE_FALSE {

server/controller/model/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ type Vtap struct {
148148
UpgradeRevision string `json:"UPGRADE_REVISION"`
149149
CompleteRevision string `json:"COMPLETE_REVISION"`
150150
Exceptions []int64 `json:"EXCEPTIONS"`
151+
ExceptionDescription string `json:"EXCEPTION_DESCRIPTION"`
151152
VtapGroupLcuuid string `json:"VTAP_GROUP_LCUUID"`
152153
VtapGroupName string `json:"VTAP_GROUP_NAME"`
153154
AZ string `json:"AZ"`

server/controller/trisolaris/services/grpc/agentsynchronize/sync_push.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ func (e *AgentEvent) Sync(ctx context.Context, in *api.SyncRequest) (*api.SyncRe
265265
if tridentException != int64(in.GetException()) {
266266
vtapCache.UpdateExceptions(int64(in.GetException()))
267267
}
268+
vtapCache.UpdateExceptionDescription(in.GetExceptionDescription())
268269
vtapCache.UpdateVTapRawHostname(in.GetHost())
269270
vtapCache.UpdateSyncedControllerAt(time.Now())
270271
vtapCache.UpdateSystemInfoFromGrpc(

server/controller/trisolaris/vtap/vtap.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,11 @@ func (v *VTapInfo) updateCacheToDB() {
11611161
tridentExceptions := uint64(VTAP_TRIDENT_EXCEPTIONS_MASK) & uint64(cacheExceptions)
11621162
controllerException := uint64(VTAP_CONTROLLER_EXCEPTIONS_MASK) & uint64(dbVTap.Exceptions)
11631163
dbVTap.Exceptions = int64(controllerException | tridentExceptions)
1164+
exceptionDescription := cacheVTap.GetExceptionDescription()
1165+
if len(exceptionDescription) > 255 {
1166+
exceptionDescription = exceptionDescription[:255]
1167+
}
1168+
dbVTap.ExceptionDescription = exceptionDescription
11641169
cacheVTap.UpdateCurControllerIP(hostIP)
11651170
dbVTap.CurControllerIP = cacheVTap.GetCurControllerIP()
11661171
dbVTap.ExpectedRevision = cacheVTap.GetExpectedRevision()

0 commit comments

Comments
 (0)