Ejemplo n.º 1
0
func (*multiplexerSuite) TestObserverFactoryMultiplexer_CallsAllFactories(c *gc.C) {
	callCount := 0
	factories := []observer.ObserverFactory{
		func() observer.Observer { callCount++; return nil },
		func() observer.Observer { callCount++; return nil },
	}

	newMultiplexObserver := observer.ObserverFactoryMultiplexer(factories...)
	c.Assert(callCount, gc.Equals, 0)

	multiplexedObserver := newMultiplexObserver()
	c.Check(multiplexedObserver, gc.NotNil)
	c.Check(callCount, gc.Equals, 2)
}
Ejemplo n.º 2
0
func newObserverFn(
	controllerConfig controller.Config,
	clock clock.Clock,
	jujuServerVersion version.Number,
	modelUUID string,
	persistAuditEntry audit.AuditEntrySinkFn,
	auditErrorHandler observer.ErrorHandler,
) observer.ObserverFactory {

	var observerFactories []observer.ObserverFactory

	// Common logging of RPC requests
	observerFactories = append(observerFactories, func() observer.Observer {
		logger := loggo.GetLogger("juju.apiserver")
		ctx := observer.RequestObserverContext{
			Clock:  clock,
			Logger: logger,
		}
		return observer.NewRequestObserver(ctx)
	})

	// Auditing observer
	// TODO(katco): Auditing needs feature tests (lp:1604551)
	if controllerConfig.AuditingEnabled() {
		observerFactories = append(observerFactories, func() observer.Observer {
			ctx := &observer.AuditContext{
				JujuServerVersion: jujuServerVersion,
				ModelUUID:         modelUUID,
			}
			return observer.NewAudit(ctx, persistAuditEntry, auditErrorHandler)
		})
	}

	return observer.ObserverFactoryMultiplexer(observerFactories...)

}