Log and collect stats for events consistently

Just happened to notice that the scheduler did a statsd call about
events with the gerrit name. That's not accurate anymore.

Pull that code into the connection so that we can use the driver name
and the connection name in the statsd calls and in the log message
emitted.

Change-Id: Ia5ed9458c0b28573392c576db7789b61f4d87f3b
This commit is contained in:
Monty Taylor 2017-05-27 12:25:05 -05:00
parent a457b47589
commit f138504169
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
5 changed files with 28 additions and 7 deletions

View File

@ -64,7 +64,11 @@ class TestScheduler(ZuulTestCase):
self.assertIsNone(self.getJobFromHistory('project-test2').node) self.assertIsNone(self.getJobFromHistory('project-test2').node)
# TODOv3(jeblair): we may want to report stats by tenant (also?). # TODOv3(jeblair): we may want to report stats by tenant (also?).
self.assertReportedStat('gerrit.event.comment-added', value='1|c') # Per-driver
self.assertReportedStat('zuul.event.gerrit.comment-added', value='1|c')
# Per-driver per-connection
self.assertReportedStat('zuul.event.gerrit.gerrit.comment-added',
value='1|c')
self.assertReportedStat('zuul.pipeline.gate.current_changes', self.assertReportedStat('zuul.pipeline.gate.current_changes',
value='1|g') value='1|g')
self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS', self.assertReportedStat('zuul.pipeline.gate.job.project-merge.SUCCESS',

View File

@ -14,6 +14,7 @@
import abc import abc
import extras
import six import six
@ -43,6 +44,26 @@ class BaseConnection(object):
self.driver = driver self.driver = driver
self.connection_name = connection_name self.connection_name = connection_name
self.connection_config = connection_config self.connection_config = connection_config
self.statsd = extras.try_import('statsd.statsd')
def logEvent(self, event):
self.log.debug(
'Scheduling {driver} event from {connection}: {event}'.format(
driver=self.driver.name,
connection=self.connection_name,
event=event.type))
try:
if self.statsd:
self.statsd.incr(
'zuul.event.{driver}.{event}'.format(
driver=self.driver.name, event=event.type))
self.statsd.incr(
'zuul.event.{driver}.{connection}.{event}'.format(
driver=self.driver.name,
connection=self.connection_name,
event=event.type))
except:
self.log.exception("Exception reporting event stats")
def onLoad(self): def onLoad(self):
pass pass

View File

@ -143,6 +143,7 @@ class GerritEventConnector(threading.Thread):
self.connection._getChange(event.change_number, self.connection._getChange(event.change_number,
event.patch_number, event.patch_number,
refresh=True) refresh=True)
self.connection.logEvent(event)
self.connection.sched.addEvent(event) self.connection.sched.addEvent(event)
def run(self): def run(self):

View File

@ -72,7 +72,7 @@ class GithubWebhookListener():
if event: if event:
event.project_hostname = self.connection.canonical_hostname event.project_hostname = self.connection.canonical_hostname
self.log.debug('Scheduling github event: {0}'.format(event.type)) self.connection.logEvent(event)
self.connection.sched.addEvent(event) self.connection.sched.addEvent(event)
def _event_push(self, request): def _event_push(self, request):

View File

@ -256,11 +256,6 @@ class Scheduler(threading.Thread):
def addEvent(self, event): def addEvent(self, event):
self.log.debug("Adding trigger event: %s" % event) self.log.debug("Adding trigger event: %s" % event)
try:
if self.statsd:
self.statsd.incr('gerrit.event.%s' % event.type)
except:
self.log.exception("Exception reporting event stats")
self.trigger_event_queue.put(event) self.trigger_event_queue.put(event)
self.wake_event.set() self.wake_event.set()
self.log.debug("Done adding trigger event: %s" % event) self.log.debug("Done adding trigger event: %s" % event)