Skip to content

Commit

Permalink
Bug 1372581 - Better new relic reporting for resultset_loader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Cameron Dawson committed Jul 20, 2017
1 parent e5b9639 commit 0c4387f
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions treeherder/etl/resultset_loader.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0c4387f

Please sign in to comment.