From 0c4387f1570d611ca229597873690952df4701f4 Mon Sep 17 00:00:00 2001 From: Cameron Dawson Date: Thu, 20 Jul 2017 09:57:30 -0700 Subject: [PATCH] Bug 1372581 - Better new relic reporting for resultset_loader Add fields of ``url`` and ``repo`` in case exceptions happen. This was catching an exception that could happen in ``fetch_resultset`` for github pushes, but wasn't raising it, so we would get exceptions later due to a null object returned from that function. This allows the exception to raise and not try to do any more processing on that push. --- treeherder/etl/resultset_loader.py | 56 ++++++++++++++---------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/treeherder/etl/resultset_loader.py b/treeherder/etl/resultset_loader.py index 32ef1108058..1773978d938 100644 --- a/treeherder/etl/resultset_loader.py +++ b/treeherder/etl/resultset_loader.py @@ -19,9 +19,12 @@ class ResultsetLoader: def process(self, message_body, exchange): transformer = self.get_transformer_class(exchange)(message_body) try: + newrelic.agent.add_custom_parameter("url", transformer.repo_url) + newrelic.agent.add_custom_parameter("branch", transformer.branch) repo = Repository.objects.get(url=transformer.repo_url, branch=transformer.branch, active_status="active") + newrelic.agent.add_custom_parameter("repository", repo.name) except ObjectDoesNotExist: repo_info = transformer.get_info() @@ -86,34 +89,29 @@ def fetch_resultset(self, url, repository, sha=None): params.update(self.CREDENTIALS) logger.info("Fetching resultset details: {}".format(url)) - try: - commits = self.get_cleaned_commits(fetch_json(url, params)) - head_commit = commits[-1] - resultset = { - "revision": head_commit["sha"], - "push_timestamp": to_timestamp( - head_commit["commit"]["author"]["date"]), - "author": head_commit["commit"]["author"]["email"], - } - - revisions = [] - for commit in commits: - revisions.append({ - "comment": commit["commit"]["message"], - "author": "{} <{}>".format( - commit["commit"]["author"]["name"], - commit["commit"]["author"]["email"]), - "revision": commit["sha"] - }) - - resultset["revisions"] = revisions - return resultset - - except Exception as ex: - logger.exception("Error fetching commits", exc_info=ex) - newrelic.agent.record_exception(ex, params={ - "url": url, "repository": repository, "sha": sha - }) + newrelic.agent.add_custom_parameter("sha", sha) + + commits = self.get_cleaned_commits(fetch_json(url, params)) + head_commit = commits[-1] + resultset = { + "revision": head_commit["sha"], + "push_timestamp": to_timestamp( + head_commit["commit"]["author"]["date"]), + "author": head_commit["commit"]["author"]["email"], + } + + revisions = [] + for commit in commits: + revisions.append({ + "comment": commit["commit"]["message"], + "author": "{} <{}>".format( + commit["commit"]["author"]["name"], + commit["commit"]["author"]["email"]), + "revision": commit["sha"] + }) + + resultset["revisions"] = revisions + return resultset def get_cleaned_commits(self, commits): """Allow a subclass to change the order of the commits""" @@ -239,8 +237,6 @@ def transform(self, repository): return self.fetch_resultset(url, repository) def fetch_resultset(self, url, repository, sha=None): - newrelic.agent.add_custom_parameter("url", url) - newrelic.agent.add_custom_parameter("repository", repository) newrelic.agent.add_custom_parameter("sha", sha) logger.info("fetching for {} {}".format(repository, url))