func Initialize(logger lager.Logger, config Configuration, clock clock.Clock) (executor.Client, grouper.Members, error) { gardenClient := GardenClient.New(GardenConnection.New(config.GardenNetwork, config.GardenAddr)) err := waitForGarden(logger, gardenClient, clock) if err != nil { return nil, nil, err } containersFetcher := &executorContainers{ gardenClient: gardenClient, owner: config.ContainerOwnerName, } destroyContainers(gardenClient, containersFetcher, logger) workDir := setupWorkDir(logger, config.TempDir) transformer := initializeTransformer( logger, config.CachePath, workDir, config.MaxCacheSizeInBytes, uint(config.MaxConcurrentDownloads), maxConcurrentUploads, config.SkipCertVerify, config.ExportNetworkEnvVars, clock, ) hub := event.NewHub() gardenStore, err := gardenstore.NewGardenStore( gardenClient, config.ContainerOwnerName, config.ContainerMaxCpuShares, config.ContainerInodeLimit, config.HealthyMonitoringInterval, config.UnhealthyMonitoringInterval, transformer, clock, hub, config.HealthCheckWorkPoolSize, ) if err != nil { return nil, grouper.Members{}, err } allocationStore := allocationstore.NewAllocationStore(clock, hub) workPoolSettings := executor.WorkPoolSettings{ CreateWorkPoolSize: config.CreateWorkPoolSize, DeleteWorkPoolSize: config.DeleteWorkPoolSize, ReadWorkPoolSize: config.ReadWorkPoolSize, MetricsWorkPoolSize: config.MetricsWorkPoolSize, } depotClientProvider, err := depot.NewClientProvider( fetchCapacity(logger, gardenClient, config), allocationStore, gardenStore, hub, keyed_lock.NewLockManager(), workPoolSettings, ) if err != nil { return nil, grouper.Members{}, err } metricsLogger := logger.Session("metrics-reporter") containerMetricsLogger := logger.Session("container-metrics-reporter") return depotClientProvider.WithLogger(logger), grouper.Members{ {"metrics-reporter", &metrics.Reporter{ ExecutorSource: depotClientProvider.WithLogger(metricsLogger), Interval: metricsReportInterval, Logger: metricsLogger, }}, {"hub-closer", closeHub(hub)}, {"registry-pruner", allocationStore.RegistryPruner(logger, config.RegistryPruningInterval)}, {"container-metrics-reporter", containermetrics.NewStatsReporter( containerMetricsLogger, containerMetricsReportInterval, clock, depotClientProvider.WithLogger(containerMetricsLogger), )}, }, nil }
fakeExecutorClient = new(efakes.FakeClient) fakeMetricSender = msfake.NewFakeMetricSender() dmetrics.Initialize(fakeMetricSender, nil) metricsResults = make(chan map[string]executor.Metrics, 10) fakeExecutorClient.GetAllMetricsStub = func(tags executor.Tags) (map[string]executor.Metrics, error) { result, ok := <-metricsResults if !ok || result == nil { return nil, errors.New("closed") } return result, nil } process = ifrit.Invoke(containermetrics.NewStatsReporter(logger, interval, fakeClock, fakeExecutorClient)) }) AfterEach(func() { close(metricsResults) ginkgomon.Interrupt(process) }) Context("when the interval elapses", func() { BeforeEach(func() { sendResults() fakeClock.Increment(interval) Eventually(fakeExecutorClient.GetAllMetricsCallCount).Should(Equal(1)) })