Skip to content

Commit

Permalink
feat: [controller] support agent config sys_free_memory_metric
Browse files Browse the repository at this point in the history
  • Loading branch information
SongZhen0704 authored and rvql committed Oct 24, 2024
1 parent db5deb2 commit 24f651b
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/bitly/go-simplejson v0.5.0
github.com/deepflowio/deepflow/message v0.0.0-20240924113131-ec9660ac2e46
github.com/deepflowio/deepflow/message v0.0.0-20241024071835-db5deb27da47
github.com/deepflowio/deepflow/server v0.0.0-20240913001216-68c04e44504b
github.com/golang/protobuf v1.5.4
github.com/mattn/go-runewidth v0.0.14
Expand Down
4 changes: 2 additions & 2 deletions cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deepflowio/deepflow/message v0.0.0-20240924113131-ec9660ac2e46 h1:uoBpoM3HHixjjz4aELXSGc0rHjMRhqbrF52aI+QhaKg=
github.com/deepflowio/deepflow/message v0.0.0-20240924113131-ec9660ac2e46/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0=
github.com/deepflowio/deepflow/message v0.0.0-20241024071835-db5deb27da47 h1:BNw0Ez+bbmmF4rn6oVcwzyd/Q+p9lxbeA+sZJ8CRTGI=
github.com/deepflowio/deepflow/message v0.0.0-20241024071835-db5deb27da47/go.mod h1:e+1lUMMlycCvFRKvlwt/y/0vxJnF8wVss3GyR1ARXY0=
github.com/deepflowio/deepflow/server v0.0.0-20240913001216-68c04e44504b h1:sfsFOMxr0zACQjtzHuee3i/tDDnDHStKApyf6mPnpbY=
github.com/deepflowio/deepflow/server v0.0.0-20240913001216-68c04e44504b/go.mod h1:0FBQRNqe8wEbd17MR/cBedYnwZmGIaA0+23RwB98axo=
github.com/deepflowio/deepflow/server/controller/db/mysql/migrator/edition v0.0.0-20240913001216-68c04e44504b h1:SuS5rJsqJBupkI1rJdhp2I+5aFjzONlM+/PhAkgDISY=
Expand Down
1 change: 1 addition & 0 deletions server/agent_config/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type AgentGroupConfigModel struct {
Domains *string `gorm:"column:domains;type:text;default:null" json:"DOMAINS"` // domains info, separate by ","
DecapType *string `gorm:"column:decap_type;type:text;default:null" json:"DECAP_TYPE"` // separate by ","
HTTPLogSpanID *string `gorm:"column:http_log_span_id;type:text;default:null" json:"HTTP_LOG_SPAN_ID"`
SysFreeMemoryMetric *string `gorm:"column:sys_free_memory_metric;type:char(64);default:null" json:"SYS_FREE_MEMORY_METRIC"`
SysFreeMemoryLimit *int `gorm:"column:sys_free_memory_limit;type:int;default:null" json:"SYS_FREE_MEMORY_LIMIT"` // unit: %
LogFileSize *int `gorm:"column:log_file_size;type:int;default:null" json:"LOG_FILE_SIZE"` // unit: MB
HTTPLogXRequestID *string `gorm:"column:http_log_x_request_id;type:char(64);default:null" json:"HTTP_LOG_X_REQUEST_ID"`
Expand Down
1 change: 1 addition & 0 deletions server/agent_config/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type AgentGroupConfigResponse struct {
Domains []*DomainInfo `json:"DOMAINS"` // domains info, separate by ","
DecapType []*TypeInfo `json:"DECAP_TYPE"` // separate by ","
HTTPLogSpanID *string `json:"HTTP_LOG_SPAN_ID"`
SysFreeMemoryMetric *string `json:"SYS_FREE_MEMORY_METRIC"`
SysFreeMemoryLimit *int `json:"SYS_FREE_MEMORY_LIMIT"` // unit: %
LogFileSize *int `json:"LOG_FILE_SIZE"` // unit: MB
HTTPLogXRequestID *string `json:"HTTP_LOG_X_REQUEST_ID"`
Expand Down
2 changes: 2 additions & 0 deletions server/controller/common/vtap_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var DefaultVTapGroupConfig = &agent_config.AgentGroupConfigModel{
Domains: &DefaultDomains,
DecapType: &DefaultDecapType,
HTTPLogSpanID: &DefaultHTTPLogSpanID,
SysFreeMemoryMetric: &DefaultSysFreeMemoryMetric,
SysFreeMemoryLimit: &DefaultSysFreeMemoryLimit,
LogFileSize: &DefaultLogFileSize,
HTTPLogXRequestID: &DefaultHTTPLogXRequestID,
Expand Down Expand Up @@ -146,6 +147,7 @@ var (
DefaultDomains = "0"
DefaultDecapType = "1,2"
DefaultHTTPLogSpanID = "traceparent, sw8"
DefaultSysFreeMemoryMetric = "free"
DefaultSysFreeMemoryLimit = 0
DefaultLogFileSize = 1000
DefaultHTTPLogXRequestID = "X-Request-ID"
Expand Down
1 change: 1 addition & 0 deletions server/controller/db/mysql/migrator/schema/rawsql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ CREATE TABLE IF NOT EXISTS vtap_group_configuration(
domains TEXT COMMENT 'domains info, separate by ","',
http_log_span_id TEXT DEFAULT NULL,
http_log_x_request_id CHAR(64),
sys_free_memory_metric CHAR(64),
sys_free_memory_limit INTEGER DEFAULT NULL COMMENT 'unit: %',
log_file_size INTEGER DEFAULT NULL COMMENT 'unit: MB',
external_agent_http_proxy_enabled TINYINT(1) COMMENT '0: disabled 1: enabled',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- modify start, add upgrade sql
DROP PROCEDURE IF EXISTS AddColumnIfNotExists;

CREATE PROCEDURE AddColumnIfNotExists(
IN tableName VARCHAR(255),
IN colName VARCHAR(255),
IN afterCol VARCHAR(255)
)
BEGIN
DECLARE column_count INT;

-- 检查列是否存在
SELECT COUNT(*)
INTO column_count
FROM information_schema.columns
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = tableName
AND column_name = colName;

-- 如果列不存在,则添加列
IF column_count = 0 THEN
SET @sql = CONCAT('ALTER TABLE ', tableName, ' ADD COLUMN ', colName, ' TEXT COMMENT "separated by ," AFTER ', afterCol);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END IF;
END;

CALL AddColumnIfNotExists('vtap_group_configuration', 'sys_free_memory_metric', 'http_log_x_request_id');

DROP PROCEDURE AddColumnIfNotExists;

-- update db_version to latest, remeber update DB_VERSION_EXPECT in migrate/init.go
UPDATE db_version SET version='6.6.1.14';
-- modify end
2 changes: 1 addition & 1 deletion server/controller/db/mysql/migrator/schema/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package schema

const (
DB_VERSION_TABLE = "db_version"
DB_VERSION_EXPECTED = "6.6.1.13"
DB_VERSION_EXPECTED = "6.6.1.14"
)

const (
Expand Down
21 changes: 21 additions & 0 deletions server/controller/trisolaris/services/grpc/synchronize/vtap.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ var SOCKET_TYPE_TO_MESSAGE = map[string]api.SocketType{
"FILE": FILE_SOCKET,
}

var (
FREE_SYS_MEMORY_METRIC = api.SysMemoryMetric_Free
AVAILABLE_SYS_MEMORY_METRIC = api.SysMemoryMetric_Available
)

var SYS_MEMORY_METRIC_TO_MESSAGE = map[string]api.SysMemoryMetric{
"free": FREE_SYS_MEMORY_METRIC,
"available": AVAILABLE_SYS_MEMORY_METRIC,
}

type VTapEvent struct{}

func NewVTapEvent() *VTapEvent {
Expand Down Expand Up @@ -88,6 +98,10 @@ func (e *VTapEvent) generateConfigInfo(c *vtap.VTapCache, clusterID string, gVTa
if ok == false {
npbSocketType = RAW_UDP_SOCKET
}
sysFreeMemoryMetric, ok := SYS_MEMORY_METRIC_TO_MESSAGE[*vtapConfig.SysFreeMemoryMetric]
if ok == false {
sysFreeMemoryMetric = FREE_SYS_MEMORY_METRIC
}
decapTypes := make([]api.DecapType, 0, len(vtapConfig.ConvertedDecapType))
for _, decap := range vtapConfig.ConvertedDecapType {
decapTypes = append(decapTypes, api.DecapType(decap))
Expand Down Expand Up @@ -155,6 +169,7 @@ func (e *VTapEvent) generateConfigInfo(c *vtap.VTapCache, clusterID string, gVTa
NtpEnabled: proto.Bool(Int2Bool(*vtapConfig.NtpEnabled)),
L4PerformanceEnabled: proto.Bool(Int2Bool(*vtapConfig.L4PerformanceEnabled)),
KubernetesApiEnabled: proto.Bool(false),
SysFreeMemoryMetric: &sysFreeMemoryMetric,
SysFreeMemoryLimit: proto.Uint32(uint32(*vtapConfig.SysFreeMemoryLimit)),
LogFileSize: proto.Uint32(uint32(*vtapConfig.LogFileSize)),
ExternalAgentHttpProxyEnabled: proto.Bool(Int2Bool(c.GetExternalAgentHTTPProxyEnabledConfig())),
Expand Down Expand Up @@ -503,6 +518,10 @@ func (e *VTapEvent) generateNoVTapCacheConfig(groupID string, orgID int) *api.Co
if ok == false {
npbSocketType = RAW_UDP_SOCKET
}
sysFreeMemoryMetric, ok := SYS_MEMORY_METRIC_TO_MESSAGE[*vtapConfig.SysFreeMemoryMetric]
if ok == false {
sysFreeMemoryMetric = FREE_SYS_MEMORY_METRIC
}
decapTypes := make([]api.DecapType, 0, len(vtapConfig.ConvertedDecapType))
for _, decap := range vtapConfig.ConvertedDecapType {
decapTypes = append(decapTypes, api.DecapType(decap))
Expand All @@ -513,6 +532,7 @@ func (e *VTapEvent) generateNoVTapCacheConfig(groupID string, orgID int) *api.Co
tapMode := api.TapMode(*vtapConfig.TapMode)
breakerMetricStr := convertBreakerMetric(*vtapConfig.SystemLoadCircuitBreakerMetric)
loadMetric := api.SystemLoadMetric(api.SystemLoadMetric_value[breakerMetricStr])

configure := &api.Config{
CollectorEnabled: proto.Bool(Int2Bool(*vtapConfig.CollectorEnabled)),
CollectorSocketType: &collectorSocketType,
Expand Down Expand Up @@ -560,6 +580,7 @@ func (e *VTapEvent) generateNoVTapCacheConfig(groupID string, orgID int) *api.Co
NtpEnabled: proto.Bool(Int2Bool(*vtapConfig.NtpEnabled)),
L4PerformanceEnabled: proto.Bool(Int2Bool(*vtapConfig.L4PerformanceEnabled)),
KubernetesApiEnabled: proto.Bool(false),
SysFreeMemoryMetric: &sysFreeMemoryMetric,
SysFreeMemoryLimit: proto.Uint32(uint32(*vtapConfig.SysFreeMemoryLimit)),
LogFileSize: proto.Uint32(uint32(*vtapConfig.LogFileSize)),
ExternalAgentHttpProxyEnabled: proto.Bool(Int2Bool(*vtapConfig.ExternalAgentHTTPProxyEnabled)),
Expand Down

0 comments on commit 24f651b

Please sign in to comment.