Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ gem 'faraday', '~> 0.9'
gem 'tilt', '~> 2'

gem 'yajl-ruby', '~> 1.3.1', :require => [ 'yajl', 'yajl/json_gem' ]
gem 'activesupport', '>= 3.2', :require => 'active_support'
gem 'activesupport', '~> 4.1.11', :require => 'active_support'

# service: mail
gem 'mail', '~> 2.2'
Expand Down
27 changes: 14 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
activesupport (4.1.16)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
tzinfo (~> 1.1)
addressable (2.4.0)
atomic (1.1.14)
aws-partitions (1.24.0)
aws-sdk-core (3.6.0)
aws-partitions (~> 1.0)
Expand All @@ -19,6 +18,7 @@ GEM
aws-sigv4 (~> 1.0)
aws-sigv4 (1.0.2)
builder (3.2.2)
concurrent-ruby (1.1.5)
descendants_tracker (0.0.3)
diff-lcs (1.2.5)
eventmachine (1.2.5)
Expand Down Expand Up @@ -46,7 +46,8 @@ GEM
httparty (0.12.0)
json (~> 1.8)
multi_xml (>= 0.5.2)
i18n (0.6.5)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jeweler (2.1.2)
builder
bundler (>= 1.0)
Expand All @@ -65,7 +66,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.25.1)
mini_portile2 (2.1.0)
minitest (4.7.5)
minitest (5.11.3)
multi_json (1.13.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
Expand Down Expand Up @@ -105,8 +106,7 @@ GEM
simple_oauth (0.1.9)
test-unit (3.2.7)
power_assert
thread_safe (0.1.3)
atomic
thread_safe (0.3.6)
tilt (2.0.7)
tinder (1.10.1)
eventmachine (~> 1.0)
Expand All @@ -124,15 +124,16 @@ GEM
eventmachine (>= 0.12.8)
http_parser.rb (~> 0.5.1)
simple_oauth (~> 0.1.4)
tzinfo (0.3.38)
tzinfo (1.2.5)
thread_safe (~> 0.1)
yajl-ruby (1.3.1)
yard (0.8.7.2)

PLATFORMS
ruby

DEPENDENCIES
activesupport (>= 3.2)
activesupport (~> 4.1.11)
aws-sdk-sns (~> 1)
faraday (~> 0.9)
flowdock (~> 0.3)
Expand All @@ -150,4 +151,4 @@ DEPENDENCIES
yard (~> 0.8)

BUNDLED WITH
1.17.2
1.17.3
1 change: 0 additions & 1 deletion lib/appoptics-services/numbers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ def self.number_decimal_places(number)
end
end
end

23 changes: 17 additions & 6 deletions lib/appoptics-services/output.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'redcarpet'
require 'active_support/core_ext/string/filters.rb'
require 'active_support/number_helper.rb'

require_relative 'helpers/alert_helpers'
require_relative 'numbers'
Expand All @@ -11,6 +12,7 @@ module AppOptics
module Services
class Output
include Helpers::AlertHelpers
include ActiveSupport::NumberHelper

attr_reader :violations, :conditions, :alert, :clear, :trigger_time, :alert_url
def initialize(payload, add_test_notice=true)
Expand Down Expand Up @@ -102,25 +104,28 @@ def generate_alert_cleared
lines.join("\n")
end

def format_measurement(measurement, source = nil)
def format_measurement(measurement, source = nil, service = nil)
condition = @conditions[measurement[:condition_violated]]
if source
metric = "`#{measurement[:metric]}` from `#{source}`"
else
metric = "`#{measurement[:metric]}`"
end
violation_time = measurement[:end] || measurement[:recorded_at]
"metric #{metric} was #{format_violation_type(condition, measurement)} recorded at #{format_time(violation_time)}"
"metric #{metric} was #{format_violation_type(condition, measurement, service)} recorded at #{format_time(violation_time)}"
end

def format_violation_type(condition, measurement)
def format_violation_type(condition, measurement, service)
if condition[:type] == "absent"
"absent for #{condition[:duration]} seconds"
else
threshold_value = condition[:threshold]
actual_value = measurement[:value]
formatted_value = AppOptics::Services::Numbers.format_for_threshold(threshold_value, actual_value)
"#{condition[:type]} threshold #{threshold(condition,measurement)} with value #{formatted_value}"
if service == AppOptics::Services::Service::Slack::SERVICE_NAME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that only Slack should benefit from this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the conversation right now but it was pointed out that change in webhooks, for example, might break something for the customers so it was decided that we should only change Slack output.

formatted_value = number_to_delimited(formatted_value)
end
"#{condition[:type]} threshold #{threshold(condition, measurement, service)} with value #{formatted_value}"
end
end

Expand All @@ -130,8 +135,14 @@ def format_time(time)
strftime("%a, %b %e %Y at %H:%M:%S UTC")
end

def threshold(condition, measurement)
thresh_str = condition[:threshold].to_s
def threshold(condition, measurement, service)
thresh_str = nil
threshold = condition[:threshold]
if service == AppOptics::Services::Service::Slack::SERVICE_NAME
thresh_str = number_to_delimited(threshold)
else
thresh_str = threshold.to_s
end
duration = calculate_duration(measurement)
if duration
thresh_str += " over #{duration} seconds"
Expand Down
2 changes: 0 additions & 2 deletions lib/appoptics-services/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,3 @@ class ConfigurationError < StandardError; end
Dir[File.join(File.dirname(__FILE__), '../../services/*.rb')].each { |service|
load service
}


3 changes: 2 additions & 1 deletion services/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
module AppOptics::Services
class Service::Slack < AppOptics::Services::Service
VERTICAL_LINE_COLOR = "#0880ad"
SERVICE_NAME = "slack"

def receive_validate(errors = {})
if settings[:url].blank?
Expand Down Expand Up @@ -70,7 +71,7 @@ def v2_alert_result
{
:title => source,
:value => measurements.inject([]) do |texts, measurement|
texts << data.format_measurement(measurement)
texts << data.format_measurement(measurement, nil, SERVICE_NAME)
end.join("\n")
}
end,
Expand Down