OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#51423] Display since when a failure state is occurring
Dominic Bräunlein4095d075240e
diff --git a/modules/storages/app/components/storages/admin/health_status_component.html.erb b/modules/storages/app/components/storages/admin/health_status_component.html.erbindex 362dff286c8..5812416e0a0 100644--- a/modules/storages/app/components/storages/admin/health_status_component.html.erb+++ b/modules/storages/app/components/storages/admin/health_status_component.html.erb@@ -2,7 +2,9 @@<%= render(Primer::Beta::Heading.new(tag: :h4, mb: 2)) { I18n.t('storages.health.title') } %><%= render(Primer::Box.new(py: 1)) do %>- <%= render(Primer::Beta::Text.new(test_selector: "storage-health-changed-at")) { I18n.t('storages.health.checked', datetime: helpers.format_time(storage.health_changed_at)) } %>+ <%= render(Primer::Beta::Text.new(test_selector: "storage-health-changed-at")) {+ I18n.t('storages.health.checked', datetime: helpers.format_time(storage.health_changed_at))+ } %><% if storage.health_healthy? %><%= render(Primer::Beta::Label.new(scheme: :success, test_selector: "storage-health-label-healthy")) {I18n.t('storages.health.label_healthy')@@ -19,6 +21,8 @@<% end %><% if storage.health_unhealthy? %>- <%= render(Primer::Beta::Text.new(tag: :div, color: :muted, py: 1, test_selector: "storage-health-reason")) { storage.formatted_health_reason } %>+ <%= render(Primer::Beta::Text.new(tag: :div, color: :muted, py: 1, test_selector: "storage-health-reason")) {+ formatted_health_reason+ } %><% end %><% end %>diff --git a/modules/storages/app/components/storages/admin/health_status_component.rb b/modules/storages/app/components/storages/admin/health_status_component.rbindex efd92ea08cf..e3e68f3d919 100644--- a/modules/storages/app/components/storages/admin/health_status_component.rb+++ b/modules/storages/app/components/storages/admin/health_status_component.rb@@ -31,5 +31,16 @@module Storages::Adminclass HealthStatusComponent < ApplicationComponentalias_method :storage, :model++ # This method returns the health identifier, description and optionally the time since when the error occurs in a+ # formatted manner. e.g. "Not found: Outbound request destination not found since 12/07/2023 03:45 PM"+ def formatted_health_reason+ reason = "#{storage.health_reason_identifier.tr('_', ' ').strip.capitalize}: #{storage.health_reason_description}"++ unless storage.health_reason_since_time.nil?+ reason += " #{I18n.t('storages.health.since', datetime: helpers.format_time(storage.health_reason_since_time))}"+ end+ reason+ endendenddiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 1a607462b2f..a785ee8627e 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -100,7 +100,17 @@ module Storages!EnterpriseToken.allows_to?(:one_drive_sharepoint_file_storage)end+ def self.extract_part_from_piped_string(text, index)+ return if text.nil?++ split_reason = text.split('|')+ if split_reason.length > index+ split_reason[index].strip+ end+ end+def mark_as_unhealthy(reason: nil)+ reason = forward_or_add_health_reason_since_time(reason.to_s) unless reason.nil?update(health_status: 'unhealthy', health_changed_at: Time.now.utc, health_reason: reason)end@@ -142,15 +152,29 @@ module Storagesprovider_type == ::Storages::Storage::PROVIDER_TYPE_ONE_DRIVEend- # Currently the error messages saved look like:+ def health_reason_identifier+ @health_reason_identifier ||= self.class.extract_part_from_piped_string(health_reason, 0)+ end++ def health_reason_description+ @health_reason_description ||= self.class.extract_part_from_piped_string(health_reason, 1)+ end++ def health_reason_since_time+ @health_reason_since_time ||= self.class.extract_part_from_piped_string(health_reason, 3)+ end++ private++ # The error messages from the ServiceResult look like:# "unauthorized | Outbound request not authorized | #<Storages::StorageErrorData:0x0000ffff646ac570>"- # This method returns the first two parts of the error message.- def formatted_health_reason- split_reason = health_reason.split('|')- if split_reason.length === 3- "#{split_reason[0].strip.capitalize}: #{split_reason[1]}"+ # This method adds the Time.now.utc when the error occurs the first time and forwards it subsequently till the+ # error identifier changes.+ def forward_or_add_health_reason_since_time(new_health_reason)+ if health_reason_since_time && health_reason_identifier == self.class.extract_part_from_piped_string(new_health_reason, 0)+ "#{new_health_reason} | #{ health_reason_since_time }"else- health_reason+ "#{new_health_reason} | #{ Time.now.utc }"endendenddiff --git a/modules/storages/app/workers/storages/manage_nextcloud_integration_job_mixin.rb b/modules/storages/app/workers/storages/manage_nextcloud_integration_job_mixin.rbindex 2e590626783..01e8fd4025a 100644--- a/modules/storages/app/workers/storages/manage_nextcloud_integration_job_mixin.rb+++ b/modules/storages/app/workers/storages/manage_nextcloud_integration_job_mixin.rb@@ -43,12 +43,10 @@ module Storagesresult = GroupFolderPropertiesSyncService.call(storage)result.match(on_success: ->(_) do- storage.mark_as_healthy unless storage.health_healthy?+ storage.mark_as_healthyend,on_failure: ->(errors) do- if !storage.health_unhealthy? || storage.health_reason != errors.to_s- storage.mark_as_unhealthy(reason: errors.to_s)- end+ storage.mark_as_unhealthy(reason: errors.to_s)end)enddiff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 1cbb864865e..076a00e39d7 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -271,7 +271,8 @@ en:label_pending: "Pending"label_error: "Error"label_healthy: "Healthy"- checked: "Checked %{datetime}"+ checked: "Last checked %{datetime}"+ since: "since %{datetime}"upsale:title: "OneDrive/SharePoint integration"description: 'Integrate your OneDrive/SharePoint as a file storage with OpenProject. Upload files and link them directly to work packages in a project.'