Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Commit

Permalink
Record counts of status codes from Jenkins HTTP calls
Browse files Browse the repository at this point in the history
Summary:
Frequency of Jenkins API calls and their results are interesting to us, and
they're cheap and easy to track.

Test Plan: Unit; trying to do local integration.

Reviewers: jukka

Reviewed By: jukka

Subscribers: changesbot, wwu

Differential Revision: https://tails.corp.dropbox.com/D96649
  • Loading branch information
kylec1 committed Mar 19, 2015
1 parent af3487c commit e311914
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion changes/backends/jenkins/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from changes.artifacts.coverage import CoverageHandler
from changes.artifacts.xunit import XunitHandler
from changes.backends.base import BaseBackend, UnrecoverableException
from changes.config import db
from changes.config import db, statsreporter
from changes.constants import Result, Status
from changes.db.utils import create_or_update, get_or_create
from changes.jobs.sync_artifact import sync_artifact
Expand Down Expand Up @@ -77,6 +77,11 @@ def __init__(self, master_urls=None, diff_urls=None, job_name=None, token=None,
self.sync_file_artifacts = self.app.config.get('JENKINS_SYNC_FILE_ARTIFACTS', True)
self.http_session = requests.Session()

def report_response_status(r, *args, **kwargs):
statsreporter.stats().incr('jenkins_api_response_{}'.format(r.status_code))

self.http_session.hooks['response'].append(report_response_status)

def _get_raw_response(self, base_url, path, method='GET', params=None, **kwargs):
url = '{}/{}'.format(base_url, path.lstrip('/'))

Expand Down Expand Up @@ -107,6 +112,8 @@ def _get_json_response(self, base_url, path, *args, **kwargs):
path = '{}/api/json/'.format(path.strip('/'))

data = self._get_raw_response(base_url, path, *args, **kwargs)
# TODO(kylec): If we get back an empty string, we probably want
# to fail; this method should only return parsed JSON.
if not data:
return

Expand Down

0 comments on commit e311914

Please sign in to comment.