Trace Gitlab connection events

Change-Id: I75e27fd0c2efd79f817318b5cae8d76c1483d744
This commit is contained in:
Simon Westphahl 2022-09-26 12:35:47 +02:00
parent 35b6016df3
commit c2063cebea
No known key found for this signature in database
1 changed files with 21 additions and 5 deletions

View File

@ -29,10 +29,13 @@ import dateutil.parser
from urllib.parse import quote_plus
from typing import List, Optional
from opentelemetry import trace
from zuul.connection import (
BaseConnection, ZKChangeCacheMixin, ZKBranchCacheMixin
)
from zuul.web.handler import BaseWebController
from zuul.lib import tracing
from zuul.lib.http import ZuulHTTPAdapter
from zuul.lib.logutil import get_annotated_logger
from zuul.lib.config import any_to_bool
@ -65,6 +68,7 @@ class GitlabEventConnector(threading.Thread):
"""Move events from Gitlab into the scheduler"""
log = logging.getLogger("zuul.GitlabEventConnector")
tracer = trace.get_tracer("zuul")
def __init__(self, connection):
super(GitlabEventConnector, self).__init__()
@ -106,10 +110,17 @@ class GitlabEventConnector(threading.Thread):
def _run(self):
while not self._stopped:
for event in self.event_queue:
try:
self._handleEvent(event)
finally:
self.event_queue.ack(event)
event_span = tracing.restoreSpanContext(
event.get("span_context"))
attributes = {"rel": "GitlabEvent"}
link = trace.Link(event_span.get_span_context(),
attributes=attributes)
with self.tracer.start_as_current_span(
"GitlabEventProcessing", links=[link]):
try:
self._handleEvent(event)
finally:
self.event_queue.ack(event)
if self._stopped:
return
self._process_event.wait(10)
@ -763,6 +774,7 @@ class GitlabConnection(ZKChangeCacheMixin, ZKBranchCacheMixin, BaseConnection):
class GitlabWebController(BaseWebController):
log = logging.getLogger("zuul.GitlabWebController")
tracer = trace.get_tracer("zuul")
def __init__(self, zuul_web, connection):
self.connection = connection
@ -789,6 +801,7 @@ class GitlabWebController(BaseWebController):
@cherrypy.expose
@cherrypy.tools.json_out(content_type='application/json; charset=utf-8')
@tracer.start_as_current_span("GitlabEvent")
def payload(self):
headers = dict()
for key, value in cherrypy.request.headers.items():
@ -799,7 +812,10 @@ class GitlabWebController(BaseWebController):
self._validate_token(headers)
json_payload = json.loads(body.decode('utf-8'))
data = {'payload': json_payload}
data = {
'payload': json_payload,
'span_context': tracing.getSpanContext(trace.get_current_span()),
}
self.event_queue.put(data)
return data