Skip to content

Commit

Permalink
[Server] Add license function item
Browse files Browse the repository at this point in the history
  • Loading branch information
roryye authored and SongZhen0704 committed Aug 25, 2023
1 parent 2d068c5 commit 5f8e8af
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
3 changes: 3 additions & 0 deletions server/controller/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ const (
VTAP_LICENSE_FUNCTION_NONE = iota
VTAP_LICENSE_FUNCTION_TRAFFIC_DISTRIBUTION
VTAP_LICENSE_FUNCTION_NETWORK_MONITORING
VTAP_LICENSE_FUNCTION_CALL_MONITORING
VTAP_LICENSE_FUNCTION_FUNCTION_MONITORING
VTAP_LICENSE_FUNCTION_APPLICATION_MONITORING
VTAP_LICENSE_FUNCTION_INDICATOR_MONITORING
VTAP_LICENSE_FUNCTION_MAX
)

Expand Down
3 changes: 3 additions & 0 deletions server/controller/monitor/license/pseudo_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ var log = logging.MustGetLogger("monitor.license")
var VTAP_LICENSE_TYPE_DEFAULT = common.VTAP_LICENSE_TYPE_A
var VTAP_LICENSE_FUNCTIONS = []string{
strconv.Itoa(common.VTAP_LICENSE_FUNCTION_NETWORK_MONITORING),
strconv.Itoa(common.VTAP_LICENSE_FUNCTION_CALL_MONITORING),
strconv.Itoa(common.VTAP_LICENSE_FUNCTION_FUNCTION_MONITORING),
strconv.Itoa(common.VTAP_LICENSE_FUNCTION_APPLICATION_MONITORING),
strconv.Itoa(common.VTAP_LICENSE_FUNCTION_INDICATOR_MONITORING),
}

type VTapLicenseAllocation struct {
Expand Down
71 changes: 62 additions & 9 deletions server/controller/trisolaris/vtap/vtap_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ type VTapCache struct {

enabledTrafficDistribution atomicbool.Bool
enabledNetworkMonitoring atomicbool.Bool
enabledCallMonitoring atomicbool.Bool
enabledFunctionMonitoring atomicbool.Bool
enabledApplicationMonitoring atomicbool.Bool
enabledIndicatorMonitoring atomicbool.Bool

cachedAt time.Time
expectedRevision *string
Expand Down Expand Up @@ -214,7 +217,10 @@ func NewVTapCache(vtap *models.VTap) *VTapCache {
vTapCache.licenseFunctionSet = mapset.NewSet()
vTapCache.enabledTrafficDistribution = atomicbool.NewBool(false)
vTapCache.enabledNetworkMonitoring = atomicbool.NewBool(false)
vTapCache.enabledCallMonitoring = atomicbool.NewBool(false)
vTapCache.enabledFunctionMonitoring = atomicbool.NewBool(false)
vTapCache.enabledApplicationMonitoring = atomicbool.NewBool(false)
vTapCache.enabledIndicatorMonitoring = atomicbool.NewBool(false)

vTapCache.cachedAt = time.Now()
vTapCache.config = &atomic.Value{}
Expand Down Expand Up @@ -254,9 +260,12 @@ func ConvertStrToIntList(convertStr string) ([]int, error) {
}

func (c *VTapCache) unsetLicenseFunctionEnable() {
c.enabledApplicationMonitoring.Unset()
c.enabledCallMonitoring.Unset()
c.enabledNetworkMonitoring.Unset()
c.enabledTrafficDistribution.Unset()
c.enabledFunctionMonitoring.Unset()
c.enabledApplicationMonitoring.Unset()
c.enabledIndicatorMonitoring.Unset()
}

func (c *VTapCache) convertLicenseFunctions() {
Expand All @@ -278,15 +287,24 @@ func (c *VTapCache) convertLicenseFunctions() {
}
c.licenseFunctionSet = functionSet

if Find[int](licenseFunctionsInt, VTAP_LICENSE_FUNCTION_APPLICATION_MONITORING) {
c.enabledApplicationMonitoring.Set()
if Find[int](licenseFunctionsInt, VTAP_LICENSE_FUNCTION_CALL_MONITORING) {
c.enabledCallMonitoring.Set()
}
if Find[int](licenseFunctionsInt, VTAP_LICENSE_FUNCTION_NETWORK_MONITORING) {
c.enabledNetworkMonitoring.Set()
}
if Find[int](licenseFunctionsInt, VTAP_LICENSE_FUNCTION_TRAFFIC_DISTRIBUTION) {
c.enabledTrafficDistribution.Set()
}
if Find[int](licenseFunctionsInt, VTAP_LICENSE_FUNCTION_FUNCTION_MONITORING) {
c.enabledFunctionMonitoring.Set()
}
if Find[int](licenseFunctionsInt, VTAP_LICENSE_FUNCTION_APPLICATION_MONITORING) {
c.enabledApplicationMonitoring.Set()
}
if Find[int](licenseFunctionsInt, VTAP_LICENSE_FUNCTION_INDICATOR_MONITORING) {
c.enabledIndicatorMonitoring.Set()
}
}

func (c *VTapCache) GetLocalConfig() string {
Expand All @@ -304,7 +322,7 @@ func (c *VTapCache) modifyVTapConfigByLicense(configure *VTapConfig) {
if configure == nil {
return
}
if c.EnabledApplicationMonitoring() == false &&
if c.EnabledCallMonitoring() == false &&
c.EnabledNetworkMonitoring() == false {
configure.L7MetricsEnabled = DISABLED
configure.ConvertedL7LogStoreTapTypes = nil
Expand All @@ -324,14 +342,14 @@ func (c *VTapCache) modifyVTapConfigByLicense(configure *VTapConfig) {
}

if c.EnabledNetworkMonitoring() == true &&
c.EnabledApplicationMonitoring() == false {
c.EnabledCallMonitoring() == false {
yamlConfig.L7ProtocolEnabled = NetWorkL7ProtocolEnabled
} else if c.EnabledNetworkMonitoring() == false &&
c.EnabledApplicationMonitoring() == false {
c.EnabledCallMonitoring() == false {
yamlConfig.L7ProtocolEnabled = nil
}

if c.EnabledApplicationMonitoring() == false {
if c.EnabledCallMonitoring() == false {
if yamlConfig.Ebpf == nil {
yamlConfig.Ebpf = &cmodel.EbpfConfig{
Disabled: proto.Bool(true),
Expand All @@ -341,6 +359,29 @@ func (c *VTapCache) modifyVTapConfigByLicense(configure *VTapConfig) {
}
}

if c.EnabledFunctionMonitoring() == false {
if yamlConfig.Ebpf == nil {
yamlConfig.Ebpf = &cmodel.EbpfConfig{}
}
if yamlConfig.Ebpf.OnCpuProfile == nil {
yamlConfig.Ebpf.OnCpuProfile = &cmodel.OnCpuProfile{
Disabled: proto.Bool(true),
}
} else {
yamlConfig.Ebpf.OnCpuProfile.Disabled = proto.Bool(true)
}

yamlConfig.ExternalProfileIntegrationDisabled = proto.Bool(true)
}

if c.EnabledApplicationMonitoring() == false {
yamlConfig.ExternalTraceIntegrationDisabled = proto.Bool(true)
}

if c.EnabledIndicatorMonitoring() == false {
yamlConfig.ExternalMetricIntegrationDisabled = proto.Bool(true)
}

b, err := yaml.Marshal(yamlConfig)
if err != nil {
log.Error(err)
Expand All @@ -349,8 +390,8 @@ func (c *VTapCache) modifyVTapConfigByLicense(configure *VTapConfig) {
configure.YamlConfig = string(b)
}

func (c *VTapCache) EnabledApplicationMonitoring() bool {
return c.enabledApplicationMonitoring.IsSet()
func (c *VTapCache) EnabledCallMonitoring() bool {
return c.enabledCallMonitoring.IsSet()
}

func (c *VTapCache) EnabledNetworkMonitoring() bool {
Expand All @@ -361,6 +402,18 @@ func (c *VTapCache) EnabledTrafficDistribution() bool {
return c.enabledTrafficDistribution.IsSet()
}

func (c *VTapCache) EnabledFunctionMonitoring() bool {
return c.enabledFunctionMonitoring.IsSet()
}

func (c *VTapCache) EnabledApplicationMonitoring() bool {
return c.enabledApplicationMonitoring.IsSet()
}

func (c *VTapCache) EnabledIndicatorMonitoring() bool {
return c.enabledIndicatorMonitoring.IsSet()
}

func (c *VTapCache) updateLicenseFunctions(licenseFunctions string) {
c.licenseFunctions = proto.String(licenseFunctions)
c.convertLicenseFunctions()
Expand Down

0 comments on commit 5f8e8af

Please sign in to comment.