mirror of https://github.com/codevalet/canary
Add the remainder of the Sentry DAO calls needed
This commit is contained in:
parent
d67a9086c1
commit
6e1a1ef172
|
@ -6,6 +6,7 @@ require 'sinatra/base'
|
||||||
require 'sentry-api'
|
require 'sentry-api'
|
||||||
|
|
||||||
require 'canary/dao/jenkins'
|
require 'canary/dao/jenkins'
|
||||||
|
require 'canary/dao/sentry'
|
||||||
|
|
||||||
module CodeValet
|
module CodeValet
|
||||||
module Canary
|
module Canary
|
||||||
|
@ -34,7 +35,7 @@ module CodeValet
|
||||||
haml :index,
|
haml :index,
|
||||||
:layout => :_base,
|
:layout => :_base,
|
||||||
:locals => {
|
:locals => {
|
||||||
:projects => projects,
|
:sentry => DAO::Sentry.new,
|
||||||
:jenkins => DAO::Jenkins.new,
|
:jenkins => DAO::Jenkins.new,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -42,18 +43,14 @@ module CodeValet
|
||||||
get '/issue/:id' do
|
get '/issue/:id' do
|
||||||
issue = nil
|
issue = nil
|
||||||
events = []
|
events = []
|
||||||
begin
|
issue_id = params['id']
|
||||||
issue = SentryApi.issue(params['id'])
|
sentry = DAO::Sentry.new
|
||||||
events = SentryApi.issue_events(params['id'])
|
|
||||||
rescue StandardError => exc
|
|
||||||
Raven.capture_exception(exc)
|
|
||||||
end
|
|
||||||
|
|
||||||
haml :issue,
|
haml :issue,
|
||||||
:layout => :_base,
|
:layout => :_base,
|
||||||
:locals => {
|
:locals => {
|
||||||
:issue => issue,
|
:issue => sentry.issue_by(issue_id),
|
||||||
:events => events,
|
:events => sentry.events_for_issue(issue_id),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,6 @@ module CodeValet::Canary::DAO
|
||||||
def issues_for(project_key)
|
def issues_for(project_key)
|
||||||
return cache.get_or_set("SentryApi#project_issues(#{project_key})",
|
return cache.get_or_set("SentryApi#project_issues(#{project_key})",
|
||||||
:expires_in => CACHE_SECONDS) do
|
:expires_in => CACHE_SECONDS) do
|
||||||
|
|
||||||
SentryApi.project_issues(project_key)
|
SentryApi.project_issues(project_key)
|
||||||
end
|
end
|
||||||
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
|
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
|
||||||
|
@ -56,6 +55,41 @@ module CodeValet::Canary::DAO
|
||||||
return []
|
return []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# Return the issue by the given Sentry issue ID
|
||||||
|
#
|
||||||
|
# This response will be cached
|
||||||
|
#
|
||||||
|
# @return [Struct]
|
||||||
|
# @return [nil] in case of error
|
||||||
|
def issue_by(id)
|
||||||
|
return cache.get_or_set("SentryApi#issue(#{id})",
|
||||||
|
:expires_in => 5 * CACHE_SECONDS) do
|
||||||
|
SentryApi.issue(id)
|
||||||
|
end
|
||||||
|
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
|
||||||
|
@error = e
|
||||||
|
return nil
|
||||||
|
rescue StandardError => e
|
||||||
|
@error = e
|
||||||
|
Raven.capture_exception(e)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def events_for_issue(id)
|
||||||
|
return cache.get_or_set("SentryApi#issue_events(#{id})",
|
||||||
|
:expires_in => CACHE_SECONDS) do
|
||||||
|
SentryApi.issue_events(id)
|
||||||
|
end
|
||||||
|
rescue *CodeValet::Canary::DAO::NET_ERRORS => e
|
||||||
|
@error = e
|
||||||
|
return nil
|
||||||
|
rescue StandardError => e
|
||||||
|
@error = e
|
||||||
|
Raven.capture_exception(e)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def cache
|
def cache
|
||||||
|
|
|
@ -72,11 +72,77 @@ describe CodeValet::Canary::DAO::Sentry do
|
||||||
expect(dao).to be_errored
|
expect(dao).to be_errored
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should cache the response from SentryApi#projects' do
|
it 'should cache the response from SentryApi#project_issues' do
|
||||||
expect(SentryApi).to receive(:project_issues).and_return(response)
|
expect(SentryApi).to receive(:project_issues).and_return(response)
|
||||||
3.times do
|
3.times do
|
||||||
expect(dao.issues_for('rspec')).to eql(response)
|
expect(dao.issues_for('rspec')).to eql(response)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it { should respond_to :issue_by }
|
||||||
|
describe '#issue_by' do
|
||||||
|
let(:dao) { described_class.new }
|
||||||
|
subject(:issue) { dao.issue_by('fake-id') }
|
||||||
|
let(:response) { Hash.new }
|
||||||
|
|
||||||
|
it 'should return SentryApi#issue' do
|
||||||
|
expect(SentryApi).to receive(:issue).and_return(response)
|
||||||
|
expect(issue).to eql(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should gracefully handle network errors' do
|
||||||
|
expect(SentryApi).to receive(:issue).and_raise(Errno::ECONNRESET)
|
||||||
|
expect(issue).to be_nil
|
||||||
|
expect(dao).to be_errored
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should gracefully handle and record unknown errors' do
|
||||||
|
expect(SentryApi).to receive(:issue).and_raise(JSON::ParserError)
|
||||||
|
expect(Raven).to receive(:capture_exception)
|
||||||
|
|
||||||
|
expect(issue).to be_nil
|
||||||
|
expect(dao).to be_errored
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should cache the response from SentryApi#issue' do
|
||||||
|
expect(SentryApi).to receive(:issue).and_return(response)
|
||||||
|
3.times do
|
||||||
|
expect(dao.issue_by('fake-id')).to eql(response)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it { should respond_to :events_for_issue }
|
||||||
|
describe '#events_for_issue' do
|
||||||
|
let(:dao) { described_class.new }
|
||||||
|
subject(:issue) { dao.events_for_issue('fake-id') }
|
||||||
|
let(:response) { Hash.new }
|
||||||
|
|
||||||
|
it 'should return SentryApi#issue' do
|
||||||
|
expect(SentryApi).to receive(:issue_events).and_return(response)
|
||||||
|
expect(issue).to eql(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should gracefully handle network errors' do
|
||||||
|
expect(SentryApi).to receive(:issue_events).and_raise(Errno::ECONNRESET)
|
||||||
|
expect(issue).to be_nil
|
||||||
|
expect(dao).to be_errored
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should gracefully handle and record unknown errors' do
|
||||||
|
expect(SentryApi).to receive(:issue_events).and_raise(JSON::ParserError)
|
||||||
|
expect(Raven).to receive(:capture_exception)
|
||||||
|
|
||||||
|
expect(issue).to be_nil
|
||||||
|
expect(dao).to be_errored
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should cache the response from SentryApi#issue' do
|
||||||
|
expect(SentryApi).to receive(:issue_events).and_return(response)
|
||||||
|
3.times do
|
||||||
|
expect(dao.events_for_issue('fake-id')).to eql(response)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,15 +38,16 @@
|
||||||
%h3
|
%h3
|
||||||
Recent issues
|
Recent issues
|
||||||
.container
|
.container
|
||||||
- if projects.size == 0
|
- projects = sentry.projects
|
||||||
|
- if sentry.errored?
|
||||||
|
|
||||||
Something went wrong when querying the error service!
|
Something went wrong when querying the error service!
|
||||||
|
|
||||||
- else
|
- else
|
||||||
- projects.auto_paginate do |project|
|
- projects.each do |project|
|
||||||
%h4= project.name
|
%h4= project.name
|
||||||
%p
|
%p
|
||||||
- events = SentryApi.project_issues(project.slug)
|
- events = sentry.issues_for(project.slug)
|
||||||
- unless events.size > 0
|
- unless events.size > 0
|
||||||
No recent events (yay).
|
No recent events (yay).
|
||||||
- else
|
- else
|
||||||
|
|
Loading…
Reference in New Issue