Example #1
0
func New(host string, config *Config, logger *gosteno.Logger) *Loggregator {
	cfcomponent.Logger = logger
	keepAliveInterval := 30 * time.Second
	listener, incomingLogChan := agentlistener.NewAgentListener(fmt.Sprintf("%s:%d", host, config.IncomingPort), logger)
	unmarshaller, messageChan := unmarshaller.NewLogMessageUnmarshaller(config.SharedSecret, incomingLogChan)
	blacklist := blacklist.New(config.BlackListIps)
	sinkManager, appStoreInputChan := sinkmanager.NewSinkManager(config.MaxRetainedLogMessages, config.SkipCertVerify, blacklist, logger)
	workerPool := workerpool.NewWorkerPool(config.EtcdMaxConcurrentRequests)

	storeAdapter := etcdstoreadapter.NewETCDStoreAdapter(config.EtcdUrls, workerPool)
	appStoreCache := cache.NewAppServiceCache()
	appStoreWatcher, newAppServiceChan, deletedAppServiceChan := store.NewAppServiceStoreWatcher(storeAdapter, appStoreCache)
	appStore := store.NewAppServiceStore(storeAdapter, appStoreWatcher)
	return &Loggregator{
		Logger:                logger,
		listener:              listener,
		unmarshaller:          unmarshaller,
		sinkManager:           sinkManager,
		messageChan:           messageChan,
		appStoreInputChan:     appStoreInputChan,
		appStore:              appStore,
		messageRouter:         sinkserver.NewMessageRouter(sinkManager, logger),
		websocketServer:       websocketserver.New(fmt.Sprintf("%s:%d", host, config.OutgoingPort), sinkManager, keepAliveInterval, config.WSMessageBufferSize, logger),
		newAppServiceChan:     newAppServiceChan,
		deletedAppServiceChan: deletedAppServiceChan,
		appStoreWatcher:       appStoreWatcher,
		storeAdapter:          storeAdapter,
	}
}
Example #2
0
func init() {
	dataReadChannel = make(chan *logmessage.Message)

	logger := loggertesthelper.Logger()
	cfcomponent.Logger = logger

	newAppServiceChan := make(chan domain.AppService)
	deletedAppServiceChan := make(chan domain.AppService)

	emptyBlacklist := blacklist.New(nil)
	sinkManager, _ = sinkmanager.NewSinkManager(1024, false, emptyBlacklist, logger)
	go sinkManager.Start(newAppServiceChan, deletedAppServiceChan)

	TestMessageRouter = sinkserver.NewMessageRouter(sinkManager, logger)
	go TestMessageRouter.Start(dataReadChannel)

	apiEndpoint := "localhost:" + SERVER_PORT
	TestWebsocketServer = websocketserver.New(apiEndpoint, sinkManager, 10*time.Second, 100, loggertesthelper.Logger())
	go TestWebsocketServer.Start()

	timeoutApiEndpoint := "localhost:" + FAST_TIMEOUT_SERVER_PORT
	FastTimeoutTestWebsocketServer := websocketserver.New(timeoutApiEndpoint, sinkManager, 10*time.Millisecond, 100, loggertesthelper.Logger())
	go FastTimeoutTestWebsocketServer.Start()

	blackListDataReadChannel = make(chan *logmessage.Message)
	localhostBlacklist := blacklist.New([]iprange.IPRange{iprange.IPRange{Start: "127.0.0.0", End: "127.0.0.2"}})
	blacklistSinkManager, _ := sinkmanager.NewSinkManager(1024, false, localhostBlacklist, logger)
	go blacklistSinkManager.Start(newAppServiceChan, deletedAppServiceChan)

	blacklistTestMessageRouter := sinkserver.NewMessageRouter(blacklistSinkManager, logger)
	go blacklistTestMessageRouter.Start(blackListDataReadChannel)

	blacklistApiEndpoint := "localhost:" + BLACKLIST_SERVER_PORT
	blackListTestWebsocketServer = websocketserver.New(blacklistApiEndpoint, blacklistSinkManager, 10*time.Second, 100, loggertesthelper.Logger())
	go blackListTestWebsocketServer.Start()

	time.Sleep(5 * time.Millisecond)
}
Example #3
0
	"github.com/cloudfoundry/loggregatorlib/loggertesthelper"
	"github.com/cloudfoundry/loggregatorlib/logmessage"
	"github.com/gorilla/websocket"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"loggregator/sinkserver/blacklist"
	"loggregator/sinkserver/sinkmanager"
	"loggregator/sinkserver/websocketserver"
	"net/http"
	"time"
)

var _ = Describe("WebsocketServer", func() {

	var server *websocketserver.WebsocketServer
	var sinkManager, _ = sinkmanager.NewSinkManager(1024, false, blacklist.New(nil), loggertesthelper.Logger())
	var appId = "my-app"
	var wsReceivedChan = make(chan []byte)
	var connectionDropped <-chan struct{}
	var apiEndpoint = "127.0.0.1:9091"

	BeforeEach(func() {
		logger := loggertesthelper.Logger()
		cfcomponent.Logger = logger

		server = websocketserver.New(apiEndpoint, sinkManager, 100*time.Millisecond, 100, logger)
		go server.Start()
		serverUrl := fmt.Sprintf("ws://%s/tail/?app=%s", apiEndpoint, appId)
		Eventually(func() error { _, _, err := websocket.DefaultDialer.Dial(serverUrl, http.Header{}); return err }).ShouldNot(HaveOccurred())
	})
Example #4
0
func (e *easyReturn) NewTickerChannel(name string, d time.Duration) <-chan time.Time {
	completed := make(chan time.Time)
	close(completed)
	return completed
}

var _ = Describe("SinkManager", func() {
	var blackListManager = blacklist.New([]iprange.IPRange{iprange.IPRange{Start: "10.10.10.10", End: "10.10.10.20"}})
	var sinkManager *sinkmanager.SinkManager
	var appServicesChan <-chan domain.AppServices
	var sinkManagerDone chan struct{}
	var newAppServiceChan, deletedAppServiceChan chan domain.AppService

	BeforeEach(func() {
		sinkManager, appServicesChan = sinkmanager.NewSinkManager(1, true, blackListManager, loggertesthelper.Logger())

		newAppServiceChan = make(chan domain.AppService)
		deletedAppServiceChan = make(chan domain.AppService)

		sinkManagerDone = make(chan struct{})
		go func() {
			defer close(sinkManagerDone)
			sinkManager.Start(newAppServiceChan, deletedAppServiceChan)
		}()
	})

	AfterEach(func() {
		sinkManager.Stop()
		<-sinkManagerDone
	})