diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy index 41060526a..d3232c31c 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/PipelineService.groovy @@ -16,6 +16,9 @@ package com.netflix.spinnaker.gate.services +import com.netflix.spectator.api.Registry +import com.netflix.spectator.api.histogram.PercentileTimer +import com.netflix.spectator.api.patterns.IntervalCounter; import com.netflix.spinnaker.gate.services.internal.EchoService import com.netflix.spinnaker.gate.services.internal.Front50Service import com.netflix.spinnaker.gate.services.internal.OrcaServiceSelector @@ -27,6 +30,9 @@ import groovy.util.logging.Slf4j import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component +import javax.annotation.PostConstruct +import java.util.concurrent.TimeUnit + @Component @Slf4j class PipelineService { @@ -48,6 +54,27 @@ class PipelineService { private final RetrySupport retrySupport = new RetrySupport() + @Autowired + Registry registry + + // Echo Event Metrics + private IntervalCounter echoEventsIntervalCounter; + private PercentileTimer echoEventsPercentileTimer; + private IntervalCounter echoEventsErrorIntervalCounter; + + @PostConstruct + public void postConstruct() { + // Metrics for Echo Event handling. + final String idPrefix = "echo.events"; + + this.echoEventsIntervalCounter = + IntervalCounter.get(this.registry, this.registry.createId(idPrefix + ".count")); + this.echoEventsPercentileTimer = + PercentileTimer.get(this.registry, this.registry.createId(idPrefix + ".duration")); + this.echoEventsErrorIntervalCounter = + IntervalCounter.get(this.registry, this.registry.createId(idPrefix + ".error")); + } + void deleteForApplication(String applicationName, String pipelineName) { front50Service.deletePipelineConfig(applicationName, pipelineName) } @@ -112,7 +139,26 @@ class PipelineService { ], eventId: eventId ] - echoService.postEvent(eventMap) + + final long startTimeNanos = registry.clock().monotonicTime(); + + try { + echoService.postEvent(eventMap) + } catch (Exception e) { + echoEventsErrorIntervalCounter.increment(); + log.error("Event processing failure: eventId={}, event={}", eventId, eventMap, e); + throw(e) + } + + // Echo Event Metrics + final long durationInNanos = registry.clock().monotonicTime() - startTimeNanos; + echoEventsIntervalCounter.increment(); + echoEventsPercentileTimer.record(durationInNanos, TimeUnit.NANOSECONDS); + + log.debug( + "Event processing success: durationInNanos={}, eventId={}", + durationInNanos, eventId); + return [ eventId: eventId, ref : String.format("/pipelines/%s", executionId)