Skip to content

Commit

Permalink
feat: discard the old agent configuration - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
SongZhen0704 authored and ZhengYa-0110 committed Jan 23, 2025
1 parent 7f5faff commit 8993f34
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 247 deletions.
1 change: 1 addition & 0 deletions server/controller/trisolaris/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const (
CONFIG_KEY_INGESTER_PORT = "global.communication.ingester_port"
CONFIG_KEY_PROXY_CONTROLLER_IP = "global.communication.proxy_controller_ip"
CONFIG_KEY_PROXY_CONTROLLER_PORT = "global.communication.proxy_controller_port"
CONFIG_KEY_CAPTURE_MODE = "inputs.cbpf.common.capture_mode"
CONFIG_KEY_DOMAIN_FILTER = "inputs.resources.pull_resource_from_controller.domain_filter"
CONFIG_KEY_HYPERVISOR_RESOURCE_ENABLED = "inputs.resources.private_cloud.hypervisor_resource_enabled"
)
Expand Down
16 changes: 0 additions & 16 deletions server/controller/trisolaris/dbcache/db_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type DBDataCache struct {
azs []*models.AZ
hostDevices []*models.Host
podNodes []*models.PodNode
agentGroupConfigs []*agent_config.AgentGroupConfigModel
domains []*models.Domain
subDomains []*models.SubDomain
chVTapPorts []*models.ChVTapPort
Expand Down Expand Up @@ -174,14 +173,6 @@ func (d *DBDataCache) GetVipDomains() []*models.Domain {
return d.vipDomains
}

func (d *DBDataCache) GetAgentGroupConfigsFromDB(db *gorm.DB) []*agent_config.AgentGroupConfigModel {
agentGroupConfigs, err := dbmgr.DBMgr[agent_config.AgentGroupConfigModel](db).Gets()
if err != nil {
log.Error(d.Log(err.Error()))
}
return agentGroupConfigs
}

func (d *DBDataCache) GetAgentGroupUserConfigsFromDB(db *gorm.DB) []*agent_config.MySQLAgentGroupConfiguration {
agentGroupConfigs, err := dbmgr.DBMgr[agent_config.MySQLAgentGroupConfiguration](db).Gets()
if err != nil {
Expand Down Expand Up @@ -395,13 +386,6 @@ func (d *DBDataCache) GetDataCacheFromDB(db *gorm.DB) {
log.Error(d.Log(err.Error()))
}

agentGroupConfigs, err := dbmgr.DBMgr[agent_config.AgentGroupConfigModel](db).Gets()
if err == nil {
d.agentGroupConfigs = agentGroupConfigs
} else {
log.Error(d.Log(err.Error()))
}

domains, err := dbmgr.DBMgr[models.Domain](db).Gets()
if err == nil {
d.domains = domains
Expand Down
24 changes: 12 additions & 12 deletions server/controller/trisolaris/vtap/agent_plaform_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ func (v *AgentPlatformData) setPlatformDataByAgent(p *metadata.PlatformDataOP, c
if vtapConfig == nil {
return
}
log.Debug(v.Logf("%d %s", vtapConfig.PodClusterInternalIP, vtapConfig.ConvertedDomains))
if *vtapConfig.PodClusterInternalIP == ALL_CLUSTERS &&
SliceEqual[string](vtapConfig.ConvertedDomains, ALL_DOMAIMS) {

podClusterInternalIP := vtapConfig.getPodClusterInternalIP()
domainFilters := vtapConfig.getDomainFilters()
log.Debug(v.Logf("%d %s", podClusterInternalIP, domainFilters))
if !podClusterInternalIP && SliceEqual[string](domainFilters, ALL_DOMAIMS) {
// 下发的云平台列表=全部,容器集群内部IP下发=所有集群
// 所有云平台所有数据

log.Debug(v.Logf("all: %s", p.GetAllSimplePlatformData()))
log.Info(v.Logf("all: %s", p.GetAllSimplePlatformData()))
c.setAgentPlatformData(p.GetAllSimplePlatformData())
} else if *vtapConfig.PodClusterInternalIP == ALL_CLUSTERS {
} else if !podClusterInternalIP {
// 下发的云平台列表=xxx,容器集群内部IP下发=所有集群
// 云平台列表=xxx的所有数据

Expand All @@ -146,7 +147,7 @@ func (v *AgentPlatformData) setPlatformDataByAgent(p *metadata.PlatformDataOP, c
}
domainToAllPlatformData := p.GetDomainToAllPlatformData()
domainAllData := metadata.NewPlatformData("platformDataType1", "", 0, PLATFORM_DATA_TYPE_1)
for _, domainLcuuid := range vtapConfig.ConvertedDomains {
for _, domainLcuuid := range domainFilters {
domainData := domainToAllPlatformData[domainLcuuid]
if domainData == nil {
log.Errorf(v.Logf("domain(%s) no platform data", domainLcuuid))
Expand All @@ -159,8 +160,7 @@ func (v *AgentPlatformData) setPlatformDataByAgent(p *metadata.PlatformDataOP, c
v.platformDataType1.setPlatformDataCache(vTapGroupLcuuid, domainAllData)
c.setAgentPlatformData(domainAllData)
log.Debug(v.Logf("%s", domainAllData))
} else if *vtapConfig.PodClusterInternalIP == CLUSTER_OF_VTAP &&
SliceEqual[string](vtapConfig.ConvertedDomains, ALL_DOMAIMS) {
} else if podClusterInternalIP && SliceEqual[string](domainFilters, ALL_DOMAIMS) {
// 下发的云平台列表=全部,容器集群内部IP下发=采集器所在集群
// 所有云平台中devicetype != POD/容器服务的所有接口,采集器所在集群devicetype=POD/容器服务的所有接口

Expand Down Expand Up @@ -194,7 +194,7 @@ func (v *AgentPlatformData) setPlatformDataByAgent(p *metadata.PlatformDataOP, c
c.setAgentPlatformData(domainAllData)
v.platformDataType2.setPlatformDataCache(key, domainAllData)
log.Debug(v.Logf("%s", domainAllData))
} else if *vtapConfig.PodClusterInternalIP == CLUSTER_OF_VTAP {
} else if podClusterInternalIP {
// 下发的云平台列表=xxx,容器集群内部IP下发=采集器所在集群
// 云平台列表=xxx中devicetype != POD/容器服务所有接口,集器所在集群devicetype=POD/容器服务的所有接口

Expand Down Expand Up @@ -236,7 +236,7 @@ func (v *AgentPlatformData) setPlatformDataByAgent(p *metadata.PlatformDataOP, c
domainToPlatformDataExceptPod := p.GetDomainToPlatformDataExceptPod()
domainToPlarformDataOnlyPod := p.GetDomainToPlatformDataOnlyPod()
domainAllData := metadata.NewPlatformData("platformDataType3", "", 0, PLATFORM_DATA_TYPE_3)
for _, domainLcuuid := range vtapConfig.ConvertedDomains {
for _, domainLcuuid := range domainFilters {
domainData := domainToPlatformDataExceptPod[domainLcuuid]
if domainData == nil {
log.Errorf(v.Logf("domain(%s) no platform data", domainLcuuid))
Expand All @@ -251,7 +251,7 @@ func (v *AgentPlatformData) setPlatformDataByAgent(p *metadata.PlatformDataOP, c
log.Errorf(v.Logf("domain(%s) no platform data", podDomain))
continue
}
if Find[string](vtapConfig.ConvertedDomains, podDomain) {
if Find[string](domainFilters, podDomain) {
domainAllData.MergeInterfaces(vtapDomainData)
} else {
domainAllData.Merge(vtapDomainData)
Expand Down
2 changes: 1 addition & 1 deletion server/controller/trisolaris/vtap/plaform_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (v *VTapPlatformData) setPlatformDataByVTap(md *metadata.MetaData, c *VTapC
log.Debug(v.Logf("set platfrom data to %s %s %s", c.GetCtrlIP(), c.GetCtrlMac(), c.getPodDomains()))
vTapGroupLcuuid := c.GetVTapGroupLcuuid()
vtapConfig := c.GetVTapConfig()
if vtapConfig == nil {
if vtapConfig == nil || vtapConfig.PodClusterInternalIP == nil {
return
}
log.Debug(v.Logf("%d %s", vtapConfig.PodClusterInternalIP, vtapConfig.ConvertedDomains))
Expand Down
89 changes: 5 additions & 84 deletions server/controller/trisolaris/vtap/vtap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package vtap

import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
Expand All @@ -34,7 +33,6 @@ import (

"github.com/deepflowio/deepflow/message/agent"
"github.com/deepflowio/deepflow/message/trident"
"github.com/deepflowio/deepflow/server/agent_config"
"github.com/deepflowio/deepflow/server/controller/common"
. "github.com/deepflowio/deepflow/server/controller/common"
mysql_model "github.com/deepflowio/deepflow/server/controller/db/metadb/model" // FIXME: To avoid ambiguity, name the package either mysql_model or db_model.
Expand Down Expand Up @@ -73,7 +71,6 @@ type VTapInfo struct {
vtapGroupShortIDToLcuuid map[string]string
vtapGroupLcuuidToConfiguration map[string]*VTapConfig
vtapGroupLcuuidToLocalConfig map[string]string
vtapGroupLcuuidToEAHPEnabled map[string]*int
noVTapTapPortsMac mapset.Set
kvmVTapCtrlIPToTapPorts map[string]mapset.Set
kcData *KubernetesCluster
Expand Down Expand Up @@ -142,7 +139,6 @@ func NewVTapInfo(db *gorm.DB, metaData *metadata.MetaData, cfg *config.Config, o
vtapGroupShortIDToLcuuid: make(map[string]string),
vtapGroupLcuuidToConfiguration: make(map[string]*VTapConfig),
vtapGroupLcuuidToLocalConfig: make(map[string]string),
vtapGroupLcuuidToEAHPEnabled: make(map[string]*int),
noVTapTapPortsMac: mapset.NewSet(),
kvmVTapCtrlIPToTapPorts: make(map[string]mapset.Set),
pluginNameToUpdateTime: make(map[string]uint32),
Expand Down Expand Up @@ -424,18 +420,7 @@ func (v *VTapInfo) loadVTaps() {
}

func (v *VTapInfo) loadDefaultVtapConfig() {
deafaultConfiguration := &agent_config.AgentGroupConfigModel{}
b, err := json.Marshal(DefaultVTapGroupConfig)
if err == nil {
err = json.Unmarshal(b, deafaultConfiguration)
if err != nil {
log.Error(v.Logf("%s", err))
}
} else {
log.Error(v.Logf("%s", err))
}

v.realDefaultConfig = NewVTapConfig(deafaultConfiguration, "")
v.realDefaultConfig = NewVTapConfig("")
}

func (v *VTapInfo) loadBaseData() {
Expand Down Expand Up @@ -501,80 +486,16 @@ func (v *VTapInfo) getAgentConfigs() {
// agent configs
agentConfigs := v.metaData.GetDBDataCache().GetAgentGroupUserConfigsFromDB(v.db)
if agentConfigs == nil {
log.Error(v.Log("no agent user configs data"))
log.Error(v.Log("no agent configs data"))
return
}
agentGroupLcuuidToConfigYaml := make(map[string]string)
for _, agentConfig := range agentConfigs {
agentGroupLcuuidToConfigYaml[agentConfig.AgentGroupLcuuid] = agentConfig.Yaml
}

// vtap configs
configs := v.metaData.GetDBDataCache().GetAgentGroupConfigsFromDB(v.db)
if configs == nil {
log.Error(v.Log("no vtap configs data"))
return
}
vtapGroupLcuuidToConfiguration := make(map[string]*VTapConfig)
vtapGroupLcuuidToLocalConfig := make(map[string]string)
vtapGroupLcuuidToEAHPEnabled := make(map[string]*int)
typeOfDefaultConfig := reflect.ValueOf(DefaultVTapGroupConfig).Elem()
for _, config := range configs {
if config.VTapGroupLcuuid == nil {
continue
}
vtapGroupLcuuidToEAHPEnabled[*config.VTapGroupLcuuid] = config.ExternalAgentHTTPProxyEnabled
if config.YamlConfig != nil {
vtapGroupLcuuidToLocalConfig[*config.VTapGroupLcuuid] = *config.YamlConfig
} else {
vtapGroupLcuuidToLocalConfig[*config.VTapGroupLcuuid] = ""
}
tapConfiguration := &agent_config.AgentGroupConfigModel{}
typeOfVTapConfiguration := reflect.ValueOf(tapConfiguration).Elem()
tt := reflect.TypeOf(config).Elem()
tv := reflect.ValueOf(config).Elem()
for i := 0; i < tv.NumField(); i++ {
field := tt.Field(i)
value := tv.Field(i)
if JudgeField(field.Name) {
typeOfVTapConfiguration.Field(i).Set(value)
continue
}
// Allow empty values not to be overwritten as default values. For example, it can be set: `tap_interface_regex: ""`
if AllowEmptyField(field.Name) && value.Kind() == reflect.Ptr && !value.IsNil() {
typeOfVTapConfiguration.Field(i).Set(value)
continue
}
defaultValue := typeOfDefaultConfig.Field(i)
if !isBlank(value) {
typeOfVTapConfiguration.Field(i).Set(value)
} else {
typeOfVTapConfiguration.Field(i).Set(defaultValue)
}
}
// 转换结构体类型
rtapConfiguration := &agent_config.AgentGroupConfigModel{}
b, err := json.Marshal(tapConfiguration)
if err == nil {
err = json.Unmarshal(b, rtapConfiguration)
if err != nil {
log.Error(v.Logf("%s", err))
}
} else {
log.Error(v.Logf("%s", err))
}
agentConfigYaml, ok := agentGroupLcuuidToConfigYaml[*config.VTapGroupLcuuid]
if !ok {
log.Error(v.Logf("vtap group lcuuid(%s) not found agent config", *config.VTapGroupLcuuid))
}
vTapConfig := NewVTapConfig(rtapConfiguration, agentConfigYaml)
if config.VTapGroupLcuuid != nil {
vtapGroupLcuuidToConfiguration[*vTapConfig.VTapGroupLcuuid] = vTapConfig
}
for _, config := range agentConfigs {
vTapConfig := NewVTapConfig(config.Yaml)
vtapGroupLcuuidToConfiguration[config.AgentGroupLcuuid] = vTapConfig
}
v.vtapGroupLcuuidToConfiguration = vtapGroupLcuuidToConfiguration
v.vtapGroupLcuuidToLocalConfig = vtapGroupLcuuidToLocalConfig
v.vtapGroupLcuuidToEAHPEnabled = vtapGroupLcuuidToEAHPEnabled
}

func (v *VTapInfo) GetVTapConfigFromShortID(shortID string) *VTapConfig {
Expand Down
Loading

0 comments on commit 8993f34

Please sign in to comment.