Skip to content

Commit

Permalink
Merge pull request #113 from tomaslin/traceability-improvements
Browse files Browse the repository at this point in the history
make polling more parallel
  • Loading branch information
tomaslin authored Jun 16, 2016
2 parents 2cbe72a + 29a904c commit bae7721
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class InfoController {

@RequestMapping(value = '/masters', method = RequestMethod.GET)
List<Object> listMasters(@RequestParam(value = "showUrl", defaultValue = "false") String showUrl) {
log.info('Getting list of masters')
if (showUrl == 'true') {
List<Object> masterList = jenkinsProperties?.masters.collect {
[
Expand All @@ -80,8 +79,6 @@ class InfoController {

@RequestMapping(value = '/jobs/{master}', method = RequestMethod.GET)
List<String> getJobs(@PathVariable String master) {
log.info('Getting list of jobs for master: {}', master)

def jenkinsService = buildMasters.filteredMap(BuildServiceProvider.JENKINS)[master]
if (jenkinsService) {
def jobList = []
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DockerMonitor implements PollingMonitor {
cache.remove(imageId)
}, {
log.error("Error: ${it.message}")
}, {} as Action0
}
)

Observable.from(images).subscribe( { TaggedImage image ->
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -150,12 +155,13 @@ 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(
Observable.from(builds)
.subscribeOn(scheduler)
.subscribe(
{ Project project ->
boolean addToCache = false
Map cachedBuild = null
Expand Down Expand Up @@ -216,9 +222,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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'() {
Expand Down

0 comments on commit bae7721

Please sign in to comment.