Skip to content

Commit c29adff

Browse files
weiqiangSongZhen0704
authored andcommitted
[Server] add team id to agent, agent group, agent group config
1 parent 9bae310 commit c29adff

File tree

19 files changed

+756
-348
lines changed

19 files changed

+756
-348
lines changed

server/agent_config/json.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ type AgentGroupConfigResponse struct {
8989
AnalyzerIP *string `json:"ANALYZER_IP"`
9090
WasmPlugins []string `json:"WASM_PLUGINS"`
9191
SoPlugins []string `json:"SO_PLUGINS"`
92+
TeamID int `json:"TEAM_ID"`
9293
}

server/controller/common/const.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ const (
677677
)
678678

679679
const (
680-
HEADER_KEY_X_ORG_ID = "X-Org-Id"
681-
INGESTER_BODY_ORG_ID = "org-id"
680+
HEADER_KEY_X_ORG_ID = "X-Org-Id"
681+
INGESTER_BODY_ORG_ID = "org-id"
682+
HEADER_KEY_X_USER_TYPE = "X-User-Type"
683+
HEADER_KEY_X_USER_ID = "X-User-Id"
682684
)

server/controller/db/mysql/migration/rawsql/init.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ TRUNCATE TABLE vtap;
10571057

10581058
CREATE TABLE IF NOT EXISTS vtap_group (
10591059
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
1060+
team_id INTEGER,
10601061
name VARCHAR(64) NOT NULL,
10611062
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
10621063
updated_at DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@@ -1615,6 +1616,7 @@ TRUNCATE TABLE policy_acl_group;
16151616

16161617
CREATE TABLE IF NOT EXISTS vtap_group_configuration(
16171618
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
1619+
team_id INTEGER,
16181620
max_collect_pps INTEGER DEFAULT NULL,
16191621
max_npb_bps BIGINT DEFAULT NULL COMMENT 'unit: bps',
16201622
max_cpus INTEGER DEFAULT NULL,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- modify start, add upgrade sql
2+
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;
3+
4+
CREATE PROCEDURE AddColumnIfNotExists(
5+
IN tableName VARCHAR(255),
6+
IN colName VARCHAR(255),
7+
IN colType VARCHAR(255)
8+
)
9+
BEGIN
10+
DECLARE column_count INT;
11+
12+
-- 检查列是否存在
13+
SELECT COUNT(*)
14+
INTO column_count
15+
FROM information_schema.columns
16+
WHERE TABLE_SCHEMA = DATABASE()
17+
AND TABLE_NAME = tableName
18+
AND column_name = colName;
19+
20+
-- 如果列不存在,则添加列
21+
IF column_count = 0 THEN
22+
SET @sql = CONCAT('ALTER TABLE ', tableName, ' ADD COLUMN ', colName, ' ', colType);
23+
PREPARE stmt FROM @sql;
24+
EXECUTE stmt;
25+
DEALLOCATE PREPARE stmt;
26+
END IF;
27+
END;
28+
29+
CALL AddColumnIfNotExists('vtap_group', 'team_id', 'INTEGER');
30+
31+
DROP PROCEDURE AddColumnIfNotExists;
32+
33+
update vtap_group set team_id=1 where team_id is NULL;
34+
35+
-- update db_version to latest, remeber update DB_VERSION_EXPECT in migrate/init.go
36+
UPDATE db_version SET version='6.5.1.24';
37+
-- modify end

server/controller/db/mysql/migration/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ package migration
1818

1919
const (
2020
DB_VERSION_TABLE = "db_version"
21-
DB_VERSION_EXPECTED = "6.5.1.23"
21+
DB_VERSION_EXPECTED = "6.5.1.24"
2222
)

server/controller/db/mysql/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ type VTapGroup struct {
211211
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"UPDATED_AT"`
212212
Lcuuid string `gorm:"column:lcuuid;type:char(64);not null" json:"LCUUID"`
213213
ShortUUID string `gorm:"column:short_uuid;type:char(32);default:null" json:"SHORT_UUID"`
214+
TeamID int `gorm:"column:team_id;type:int;default:0" json:"TEAM_ID"`
214215
}
215216

216217
func (VTapGroup) TableName() string {

server/controller/http/middleware.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package http
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"strconv"
2223

@@ -42,6 +43,32 @@ func HandleOrgIDMiddleware() gin.HandlerFunc {
4243
}
4344
}
4445
ctx.Set(common.HEADER_KEY_X_ORG_ID, orgID)
46+
47+
var err error
48+
var userType, userID int
49+
userTypeString := ctx.Request.Header.Get(common.HEADER_KEY_X_USER_TYPE)
50+
if userTypeString == "" {
51+
log.Warningf("header is invalid: no %s", common.HEADER_KEY_X_USER_TYPE)
52+
} else {
53+
userType, err = strconv.Atoi(userTypeString)
54+
if err != nil {
55+
ctx.Abort()
56+
return
57+
}
58+
}
59+
userIDString := ctx.Request.Header.Get(common.HEADER_KEY_X_USER_ID)
60+
if len(userIDString) == 0 {
61+
err = errors.New(fmt.Sprintf("header is invalid: no %s", common.HEADER_KEY_X_USER_ID))
62+
} else {
63+
userID, err = strconv.Atoi(userIDString)
64+
if err != nil {
65+
ctx.Abort()
66+
return
67+
}
68+
}
69+
ctx.Set(common.HEADER_KEY_X_USER_TYPE, userType)
70+
ctx.Set(common.HEADER_KEY_X_USER_ID, userID)
71+
4572
ctx.Next()
4673
}
4774
}

0 commit comments

Comments
 (0)