From 1ae3ae6d6c0b376d1ba06c7f5d6a5f8b639e89cd Mon Sep 17 00:00:00 2001 From: tomaslin Date: Thu, 16 Jun 2016 09:06:55 -0700 Subject: [PATCH 1/4] removed noisy info message --- .../com/netflix/spinnaker/igor/build/InfoController.groovy | 5 ----- 1 file changed, 5 deletions(-) diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/InfoController.groovy b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/InfoController.groovy index 5a61ce3c8..671cdec8a 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/InfoController.groovy +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/build/InfoController.groovy @@ -56,7 +56,6 @@ class InfoController { @RequestMapping(value = '/masters', method = RequestMethod.GET) List listMasters(@RequestParam(value = "showUrl", defaultValue = "false") String showUrl) { - log.info('Getting list of masters') if (showUrl == 'true') { List masterList = jenkinsProperties?.masters.collect { [ @@ -80,8 +79,6 @@ class InfoController { @RequestMapping(value = '/jobs/{master}', method = RequestMethod.GET) List getJobs(@PathVariable String master) { - log.info('Getting list of jobs for master: {}', master) - def jenkinsService = buildMasters.filteredMap(BuildServiceProvider.JENKINS)[master] if (jenkinsService) { def jobList = [] @@ -113,8 +110,6 @@ class InfoController { Object getJobConfig(@PathVariable String master, HttpServletRequest request) { def job = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE).split('/').drop(3).join('/') - - log.info('Getting the job config for {} at {}', job, master) def service = buildMasters.map[master] if (!service) { throw new MasterNotFoundException("Master '${master}' does not exist") From cecd44a8a637600629bb2f2d913b808e74a90b98 Mon Sep 17 00:00:00 2001 From: tomaslin Date: Thu, 16 Jun 2016 09:07:15 -0700 Subject: [PATCH 2/4] removed unnessary {} as Action0 blocks from subscribe --- .../netflix/spinnaker/igor/docker/DockerMonitor.groovy | 6 ++---- .../spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy | 10 ++++------ .../spinnaker/igor/travis/TravisBuildMonitor.groovy | 3 +-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/docker/DockerMonitor.groovy b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/docker/DockerMonitor.groovy index 232771625..945f4dc4b 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/docker/DockerMonitor.groovy +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/docker/DockerMonitor.groovy @@ -90,7 +90,7 @@ class DockerMonitor implements PollingMonitor { cache.remove(imageId) }, { log.error("Error: ${it.message}") - }, {} as Action0 + } ) Observable.from(images).subscribe( { TaggedImage image -> @@ -126,9 +126,7 @@ class DockerMonitor implements PollingMonitor { } }, { log.error("Error: ${it.message} (${account})") - }, { - } as Action0 - + } ) } catch (Exception e) { log.error "Failed to update account $account", e diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy index 335dc09b1..8ea790fb8 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy @@ -150,9 +150,8 @@ class JenkinsBuildMonitor implements PollingMonitor { { String jobName -> log.info "Removing ${master}:${jobName}" cache.remove(master, jobName) - }, { - log.error("Error: ${it.message}") - }, {} as Action0 + }, + { log.error("Error: ${it.message}") } ) Observable.from(builds).subscribe( @@ -216,9 +215,8 @@ class JenkinsBuildMonitor implements PollingMonitor { results << [previous: cachedBuild, current: project] } }, { - log.error("Error: ${it.message} (${master})") - }, { - } as Action0 + log.error("Error: ${it.message} (${master})") + } ) } catch (e) { log.error("failed to update master $master", e) diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/travis/TravisBuildMonitor.groovy b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/travis/TravisBuildMonitor.groovy index 1d16e4b49..a443e9263 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/travis/TravisBuildMonitor.groovy +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/travis/TravisBuildMonitor.groovy @@ -173,8 +173,7 @@ class TravisBuildMonitor implements PollingMonitor{ } }, { log.error("Error: ${it.message} (${master})") - }, { - } as Action0 + } ) log.info("Last poll took ${System.currentTimeMillis() - lastPoll}ms (master: ${master})") if (repositorySyncEnabled) { From 142ae4a011cbcb04cfe3cd5b4073b51973272a99 Mon Sep 17 00:00:00 2001 From: tomaslin Date: Thu, 16 Jun 2016 09:34:14 -0700 Subject: [PATCH 3/4] give the polling monitor a little bit more time --- .../netflix/spinnaker/igor/health/PollingMonitorHealth.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/health/PollingMonitorHealth.groovy b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/health/PollingMonitorHealth.groovy index 09233e25d..afd023778 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/health/PollingMonitorHealth.groovy +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/health/PollingMonitorHealth.groovy @@ -43,7 +43,7 @@ public class PollingMonitorHealth implements HealthIndicator { healths << Health.unknown().withDetail("${poller.name}.status", 'not polling yet').build() } else { // Check if twice the polling interval has elapsed. - if (System.currentTimeMillis() - poller.lastPoll > (poller.pollInterval * 2 * DateTimeConstants.MILLIS_PER_SECOND)) { + if (System.currentTimeMillis() - poller.lastPoll > (poller.pollInterval * 5 * DateTimeConstants.MILLIS_PER_SECOND)) { healths << Health.down().withDetail("${poller.name}.status", 'stopped').withDetail("${poller.name}.lastPoll", poller.lastPoll.toString()).build() } else { healths << Health.up().withDetail("${poller.name}.status", 'running').withDetail("${poller.name}.lastPoll", poller.lastPoll.toString()).build() From 29a904c534554379f8b739958257a00b1144e87a Mon Sep 17 00:00:00 2001 From: tomaslin Date: Thu, 16 Jun 2016 09:41:05 -0700 Subject: [PATCH 4/4] made polling a little bit more parallel --- .../igor/jenkins/JenkinsBuildMonitor.groovy | 17 ++++++++++++----- .../igor/jenkins/JenkinsBuildMonitorSpec.groovy | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy index 8ea790fb8..259033235 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitor.groovy @@ -33,6 +33,7 @@ import org.springframework.context.event.ContextRefreshedEvent import org.springframework.core.env.Environment import org.springframework.stereotype.Service import rx.Observable +import rx.Scheduler import rx.Scheduler.Worker import rx.functions.Action0 import rx.schedulers.Schedulers @@ -52,7 +53,8 @@ class JenkinsBuildMonitor implements PollingMonitor { @Autowired Environment environment - Worker worker = Schedulers.io().createWorker() + Scheduler scheduler = Schedulers.newThread() + Worker worker = scheduler.createWorker() @Autowired JenkinsCache cache @@ -107,9 +109,12 @@ class JenkinsBuildMonitor implements PollingMonitor { worker.schedulePeriodically( { if (isInService()) { - buildMasters.filteredMap(BuildServiceProvider.JENKINS).keySet().each { master -> - changedBuilds(master) - } + Observable.from( buildMasters.filteredMap(BuildServiceProvider.JENKINS).keySet() ) + .subscribe( + { master -> + changedBuilds(master) + }, { log.error("Error: ${it.message}") } + ) } else { log.info("not in service (lastPoll: ${lastPoll ?: 'n/a'})") lastPoll = null @@ -154,7 +159,9 @@ class JenkinsBuildMonitor implements PollingMonitor { { log.error("Error: ${it.message}") } ) - Observable.from(builds).subscribe( + Observable.from(builds) + .subscribeOn(scheduler) + .subscribe( { Project project -> boolean addToCache = false Map cachedBuild = null diff --git a/igor-web/src/test/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitorSpec.groovy b/igor-web/src/test/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitorSpec.groovy index 971cba608..a455a1851 100644 --- a/igor-web/src/test/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitorSpec.groovy +++ b/igor-web/src/test/groovy/com/netflix/spinnaker/igor/jenkins/JenkinsBuildMonitorSpec.groovy @@ -23,6 +23,9 @@ import com.netflix.spinnaker.igor.jenkins.client.model.Project import com.netflix.spinnaker.igor.jenkins.client.model.ProjectsList import com.netflix.spinnaker.igor.jenkins.service.JenkinsService import com.netflix.spinnaker.igor.service.BuildMasters +import rx.Scheduler +import rx.schedulers.Schedulers +import rx.schedulers.TestScheduler import spock.lang.Specification /** @@ -39,6 +42,7 @@ class JenkinsBuildMonitorSpec extends Specification { void setup() { monitor = new JenkinsBuildMonitor(cache: cache, buildMasters: new BuildMasters(map: [MASTER: jenkinsService])) + monitor.scheduler = Schedulers.immediate() } void 'flag a new build not found in the cache'() {