Fix: service map component aware of agent config (#845)

* Fix: Service map component aware of mizu config
This commit is contained in:
Igor Gov 2022-02-23 09:35:05 +02:00 committed by GitHub
parent d2e91b4ffa
commit 97cce32e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 19 deletions

View File

@ -216,7 +216,7 @@ func enableExpFeatureIfNeeded() {
oas.GetOasGeneratorInstance().Start() oas.GetOasGeneratorInstance().Start()
} }
if config.Config.ServiceMap { if config.Config.ServiceMap {
servicemap.GetInstance().SetConfig(config.Config) servicemap.GetInstance().Enable()
} }
elastic.GetInstance().Configure(config.Config.Elastic) elastic.GetInstance().Configure(config.Config.Elastic)
} }

View File

@ -11,7 +11,6 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/up9inc/mizu/shared"
tapApi "github.com/up9inc/mizu/tap/api" tapApi "github.com/up9inc/mizu/tap/api"
) )
@ -59,9 +58,7 @@ type ServiceMapControllerSuite struct {
func (s *ServiceMapControllerSuite) SetupTest() { func (s *ServiceMapControllerSuite) SetupTest() {
s.c = NewServiceMapController() s.c = NewServiceMapController()
s.c.service.SetConfig(&shared.MizuAgentConfig{ s.c.service.Enable()
ServiceMap: true,
})
s.c.service.NewTCPEntry(TCPEntryA, TCPEntryB, ProtocolHttp) s.c.service.NewTCPEntry(TCPEntryA, TCPEntryB, ProtocolHttp)
s.w = httptest.NewRecorder() s.w = httptest.NewRecorder()

View File

@ -3,7 +3,6 @@ package servicemap
import ( import (
"sync" "sync"
"github.com/up9inc/mizu/shared"
"github.com/up9inc/mizu/shared/logger" "github.com/up9inc/mizu/shared/logger"
tapApi "github.com/up9inc/mizu/tap/api" tapApi "github.com/up9inc/mizu/tap/api"
) )
@ -26,13 +25,13 @@ func GetInstance() ServiceMap {
} }
type serviceMap struct { type serviceMap struct {
config *shared.MizuAgentConfig enabled bool
graph *graph graph *graph
entriesProcessed int entriesProcessed int
} }
type ServiceMap interface { type ServiceMap interface {
SetConfig(config *shared.MizuAgentConfig) Enable()
IsEnabled() bool IsEnabled() bool
NewTCPEntry(source *tapApi.TCP, destination *tapApi.TCP, protocol *tapApi.Protocol) NewTCPEntry(source *tapApi.TCP, destination *tapApi.TCP, protocol *tapApi.Protocol)
GetStatus() ServiceMapStatus GetStatus() ServiceMapStatus
@ -46,7 +45,7 @@ type ServiceMap interface {
func newServiceMap() *serviceMap { func newServiceMap() *serviceMap {
return &serviceMap{ return &serviceMap{
config: nil, enabled: false,
entriesProcessed: 0, entriesProcessed: 0,
graph: newDirectedGraph(), graph: newDirectedGraph(),
} }
@ -156,15 +155,12 @@ func (s *serviceMap) addEdge(u, v *entryData, p *tapApi.Protocol) {
s.entriesProcessed++ s.entriesProcessed++
} }
func (s *serviceMap) SetConfig(config *shared.MizuAgentConfig) { func (s *serviceMap) Enable() {
s.config = config s.enabled = true
} }
func (s *serviceMap) IsEnabled() bool { func (s *serviceMap) IsEnabled() bool {
if s.config != nil && s.config.ServiceMap { return s.enabled
return true
}
return false
} }
func (s *serviceMap) NewTCPEntry(src *tapApi.TCP, dst *tapApi.TCP, p *tapApi.Protocol) { func (s *serviceMap) NewTCPEntry(src *tapApi.TCP, dst *tapApi.TCP, p *tapApi.Protocol) {

View File

@ -6,7 +6,6 @@ import (
"testing" "testing"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/up9inc/mizu/shared"
tapApi "github.com/up9inc/mizu/tap/api" tapApi "github.com/up9inc/mizu/tap/api"
) )
@ -96,9 +95,7 @@ func (s *ServiceMapDisabledSuite) SetupTest() {
func (s *ServiceMapEnabledSuite) SetupTest() { func (s *ServiceMapEnabledSuite) SetupTest() {
s.instance = GetInstance() s.instance = GetInstance()
s.instance.SetConfig(&shared.MizuAgentConfig{ s.instance.Enable()
ServiceMap: true,
})
} }
func (s *ServiceMapDisabledSuite) TestServiceMapInstance() { func (s *ServiceMapDisabledSuite) TestServiceMapInstance() {