From 0e5f15be28330cf980d87cf0e2469f2147749add Mon Sep 17 00:00:00 2001 From: Bhumi Shah Date: Tue, 18 Apr 2023 11:20:53 -0500 Subject: [PATCH 1/5] calculate webhook delivery error rate percentage --- .../models/concerns/webhooks/outgoing/endpoint_support.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bullet_train-outgoing_webhooks/app/models/concerns/webhooks/outgoing/endpoint_support.rb b/bullet_train-outgoing_webhooks/app/models/concerns/webhooks/outgoing/endpoint_support.rb index 33c542f79..a11370b9e 100644 --- a/bullet_train-outgoing_webhooks/app/models/concerns/webhooks/outgoing/endpoint_support.rb +++ b/bullet_train-outgoing_webhooks/app/models/concerns/webhooks/outgoing/endpoint_support.rb @@ -40,4 +40,12 @@ def event_types def touch_parent send(BulletTrain::OutgoingWebhooks.parent_association).touch end + + def error_rate_percentage + total = deliveries.where(created_at: 30.days.ago..Time.now).count + failed = deliveries.where(created_at: 30.days.ago..Time.now).where(delivered_at: nil).count + + return 0 if total == 0 || failed == 0 + error_percentage = (failed.to_f / total.to_f) * 100 + end end From 00b29a1c9de4e99985a86a7a30190b20b3c53f97 Mon Sep 17 00:00:00 2001 From: Bhumi Shah Date: Tue, 18 Apr 2023 11:56:05 -0500 Subject: [PATCH 2/5] add error rate to the endpoint index view --- .../account/webhooks/outgoing/endpoints/_index.html.erb | 2 ++ .../config/locales/en/webhooks/outgoing/endpoints.en.yml | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/bullet_train-outgoing_webhooks/app/views/account/webhooks/outgoing/endpoints/_index.html.erb b/bullet_train-outgoing_webhooks/app/views/account/webhooks/outgoing/endpoints/_index.html.erb index e4a8f145c..3fbf68792 100644 --- a/bullet_train-outgoing_webhooks/app/views/account/webhooks/outgoing/endpoints/_index.html.erb +++ b/bullet_train-outgoing_webhooks/app/views/account/webhooks/outgoing/endpoints/_index.html.erb @@ -15,6 +15,7 @@ <%= t('.fields.name.heading') %> <%= t('.fields.url.heading') %> + <%= t('.fields.error_rate.heading') %> <%# 🚅 super scaffolding will insert new field headers above this line. %> @@ -25,6 +26,7 @@ <%= render 'shared/attributes/text', attribute: :name, url: [:account, endpoint] %> <%= render 'shared/attributes/code', attribute: :url %> + <%= number_to_percentage(endpoint.error_rate_percentage, precision: 1) %> <%# 🚅 super scaffolding will insert new fields above this line. %> <% unless hide_actions %> diff --git a/bullet_train-outgoing_webhooks/config/locales/en/webhooks/outgoing/endpoints.en.yml b/bullet_train-outgoing_webhooks/config/locales/en/webhooks/outgoing/endpoints.en.yml index 73a70d7d6..6b106e519 100644 --- a/bullet_train-outgoing_webhooks/config/locales/en/webhooks/outgoing/endpoints.en.yml +++ b/bullet_train-outgoing_webhooks/config/locales/en/webhooks/outgoing/endpoints.en.yml @@ -39,6 +39,11 @@ en: label: *url heading: *url + error_rate: + _: &error_rate ERROR RATE + label: *error_rate + heading: *error_rate + api_version: _: &api_version API Version label: *api_version From 80221b222f7a39e240e02effc32f0e934ed996a9 Mon Sep 17 00:00:00 2001 From: Bhumi Shah Date: Wed, 19 Apr 2023 10:09:55 -0500 Subject: [PATCH 3/5] little capsule component to render stylized error rate --- .../webhooks/outgoing/endpoints/_index.html.erb | 2 +- .../app/views/themes/light/_capsule_label.html.erb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb diff --git a/bullet_train-outgoing_webhooks/app/views/account/webhooks/outgoing/endpoints/_index.html.erb b/bullet_train-outgoing_webhooks/app/views/account/webhooks/outgoing/endpoints/_index.html.erb index 3fbf68792..6724c8519 100644 --- a/bullet_train-outgoing_webhooks/app/views/account/webhooks/outgoing/endpoints/_index.html.erb +++ b/bullet_train-outgoing_webhooks/app/views/account/webhooks/outgoing/endpoints/_index.html.erb @@ -26,7 +26,7 @@ <%= render 'shared/attributes/text', attribute: :name, url: [:account, endpoint] %> <%= render 'shared/attributes/code', attribute: :url %> - <%= number_to_percentage(endpoint.error_rate_percentage, precision: 1) %> + <%= render 'account/shared/capsule_label', value: number_to_percentage(endpoint.error_rate_percentage, precision: 1) %> <%# 🚅 super scaffolding will insert new fields above this line. %> <% unless hide_actions %> diff --git a/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb b/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb new file mode 100644 index 000000000..5ce0a4dd4 --- /dev/null +++ b/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb @@ -0,0 +1,11 @@ +<% value ||= "0.0%" %> + +<% +if value == "0.0%" + label_classes = "bg-green-200 text-green-600" +else + label_classes = "bg-red-100 text-red-900" +end +%> + +value From 6b55eef5fb5bb08a85e39c83b0289deea37afa10 Mon Sep 17 00:00:00 2001 From: Bhumi Shah Date: Wed, 19 Apr 2023 10:11:31 -0500 Subject: [PATCH 4/5] cleanup --- .../app/views/themes/light/_capsule_label.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb b/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb index 5ce0a4dd4..4468ab24e 100644 --- a/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb +++ b/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb @@ -8,4 +8,4 @@ else end %> -value +<%= value %> From 32f490b9ea2158976b8a61e9b3487d3bcf23397e Mon Sep 17 00:00:00 2001 From: Bhumi Shah Date: Wed, 19 Apr 2023 10:18:57 -0500 Subject: [PATCH 5/5] color fix --- .../app/views/themes/light/_capsule_label.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb b/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb index 4468ab24e..16a604667 100644 --- a/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb +++ b/bullet_train-themes-light/app/views/themes/light/_capsule_label.html.erb @@ -4,7 +4,7 @@ if value == "0.0%" label_classes = "bg-green-200 text-green-600" else - label_classes = "bg-red-100 text-red-900" + label_classes = "bg-red-200 text-red-900" end %>