-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release health definition and events (#581)
- Create rules defining release health - Create release events for the production release if the health metrics fetched violate any rules or change the health status from a previous event
- Loading branch information
Showing
13 changed files
with
328 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module HealthAwareness | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
enum health_status: {healthy: "healthy", unhealthy: "unhealthy"} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# == Schema Information | ||
# | ||
# Table name: release_health_events | ||
# | ||
# id :uuid not null, primary key | ||
# action_triggered :boolean default(FALSE) | ||
# event_timestamp :datetime not null, indexed | ||
# health_status :string not null | ||
# notification_triggered :boolean default(FALSE) | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# deployment_run_id :uuid not null, indexed => [release_health_rule_id, release_health_metric_id], indexed | ||
# release_health_metric_id :uuid not null, indexed => [deployment_run_id, release_health_rule_id], indexed | ||
# release_health_rule_id :uuid not null, indexed => [deployment_run_id, release_health_metric_id], indexed | ||
# | ||
class ReleaseHealthEvent < ApplicationRecord | ||
include HealthAwareness | ||
self.implicit_order_column = :event_timestamp | ||
|
||
belongs_to :deployment_run | ||
belongs_to :release_health_rule | ||
belongs_to :release_health_metric | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# == Schema Information | ||
# | ||
# Table name: release_health_rules | ||
# | ||
# id :uuid not null, primary key | ||
# comparator :string not null | ||
# is_halting :boolean default(FALSE), not null | ||
# metric :string not null, indexed, indexed => [train_id] | ||
# threshold_value :float not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# train_id :uuid not null, indexed, indexed => [metric] | ||
# | ||
class ReleaseHealthRule < ApplicationRecord | ||
include HealthAwareness | ||
belongs_to :train | ||
|
||
enum metric: { | ||
session_stability: "session_stability", | ||
user_stability: "user_stability", | ||
errors: "errors", | ||
new_errors: "new_errors" | ||
} | ||
|
||
enum comparator: { | ||
lt: "lt", | ||
lte: "lte", | ||
gt: "gt", | ||
gte: "gte", | ||
eq: "eq" | ||
} | ||
|
||
COMPARATORS = { | ||
lt: ->(value, threshold) { value < threshold }, | ||
lte: ->(value, threshold) { value <= threshold }, | ||
gt: ->(value, threshold) { value > threshold }, | ||
gte: ->(value, threshold) { value >= threshold }, | ||
eq: ->(value, threshold) { value == threshold } | ||
} | ||
|
||
validates :metric, uniqueness: {scope: :train_id} | ||
|
||
def evaluate(value) | ||
comparator_proc = COMPARATORS[comparator.to_sym] | ||
raise ArgumentError, "Invalid comparator" unless comparator_proc | ||
|
||
return ReleaseHealthRule.health_statuses[:healthy] if comparator_proc.call(value, threshold_value) | ||
ReleaseHealthRule.health_statuses[:unhealthy] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class AddReleaseHealthRules < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :release_health_rules, id: :uuid do |t| | ||
t.belongs_to :train, null: false, index: true, foreign_key: true, type: :uuid | ||
|
||
t.string :metric, null: false, index: true | ||
t.string :comparator, null: false | ||
t.float :threshold_value, null: false | ||
t.boolean :is_halting, null: false, default: false | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :release_health_rules, [:train_id, :metric], unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class AddReleaseHealthEvents < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :release_health_events, id: :uuid do |t| | ||
t.belongs_to :deployment_run, null: false, foreign_key: true, type: :uuid | ||
t.belongs_to :release_health_rule, null: false, foreign_key: true, type: :uuid | ||
t.belongs_to :release_health_metric, null: false, foreign_key: true, type: :uuid | ||
|
||
t.string :health_status, null: false | ||
t.datetime :event_timestamp, null: false, index: true | ||
t.boolean :notification_triggered, default: false | ||
t.boolean :action_triggered, default: false | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :release_health_events, | ||
[:deployment_run_id, :release_health_rule_id, :release_health_metric_id], | ||
unique: true, | ||
name: "idx_events_on_deployment_and_rule_and_metric" | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FactoryBot.define do | ||
factory :release_health_metric do | ||
association :deployment_run | ||
|
||
daily_users { 100 } | ||
daily_users_with_errors { 10 } | ||
errors_count { 10 } | ||
new_errors_count { 1 } | ||
sessions { 1000 } | ||
sessions_in_last_day { 100 } | ||
sessions_with_errors { 10 } | ||
total_sessions_in_last_day { 5000 } | ||
fetched_at { Time.current } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FactoryBot.define do | ||
factory :release_health_rule do | ||
association :train | ||
|
||
comparator { "gte" } | ||
threshold_value { 90.0 } | ||
|
||
trait :session_stability do | ||
metric { "session_stability" } | ||
end | ||
|
||
trait :user_stability do | ||
metric { "user_stability" } | ||
end | ||
|
||
trait :errors do | ||
metric { "errors" } | ||
threshold_value { 90 } | ||
comparator { "lt" } | ||
end | ||
|
||
trait :new_errors do | ||
metric { "new_errors" } | ||
threshold_value { 10 } | ||
comparator { "lt" } | ||
end | ||
end | ||
end |
Oops, something went wrong.