Skip to content

Commit

Permalink
Merge pull request #17325 from opf/bug/59346-folders-missing-in-log-l…
Browse files Browse the repository at this point in the history
…ines-for-unexpected-content-error

[#59346] add log warning to unexpected content
  • Loading branch information
Kharonus authored Dec 3, 2024
2 parents 939260a + a31ec45 commit 9933dae
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module Storages
module Peripherals
class NextcloudConnectionValidator
include TaggedLogging
include Dry::Monads[:maybe]

using ServiceResultRefinements
Expand All @@ -40,13 +41,15 @@ def initialize(storage:)
end

def validate
maybe_is_not_configured
.or { has_base_configuration_error? }
.or { has_ampf_configuration_error? }
.value_or(ConnectionValidation.new(type: :healthy,
error_code: :none,
timestamp: Time.current,
description: nil))
with_tagged_logger do
maybe_is_not_configured
.or { has_base_configuration_error? }
.or { has_ampf_configuration_error? }
.value_or(ConnectionValidation.new(type: :healthy,
error_code: :none,
timestamp: Time.current,
description: nil))
end
end

private
Expand Down Expand Up @@ -194,6 +197,11 @@ def with_unexpected_content
unexpected_files = files.result.files.reject { |file| expected_folder_ids.include?(file.id) }
return None() if unexpected_files.empty?

file_representation = unexpected_files.map do |file|
"Name: #{file.name}, ID: #{file.id}, Location: #{file.location}"
end
warn "Unexpected files/folder found in group folder:\n\t#{file_representation.join("\n\t")}"

Some(
ConnectionValidation.new(
type: :warning,
Expand All @@ -209,13 +217,11 @@ def with_unexpected_content
def capabilities_request_failed_with_unknown_error
return None() if capabilities.success?

Rails.logger.error(
"Connection validation failed with unknown error:\n\t" \
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"request: Nextcloud capabilities\n\t" \
"status: #{capabilities.result}\n\t" \
"response: #{capabilities.error_payload}"
)
error "Connection validation failed with unknown error:\n\t" \
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"request: Nextcloud capabilities\n\t" \
"status: #{capabilities.result}\n\t" \
"response: #{capabilities.error_payload}"

Some(ConnectionValidation.new(type: :error,
error_code: :err_unknown,
Expand All @@ -226,13 +232,11 @@ def capabilities_request_failed_with_unknown_error
def files_request_failed_with_unknown_error
return None() if files.success?

Rails.logger.error(
"Connection validation failed with unknown error:\n\t" \
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"request: Group folder content\n\t" \
"status: #{files.result}\n\t" \
"response: #{files.error_payload}"
)
error "Connection validation failed with unknown error:\n\t" \
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"request: Group folder content\n\t" \
"status: #{files.result}\n\t" \
"response: #{files.error_payload}"

Some(ConnectionValidation.new(type: :error,
error_code: :err_unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
module Storages
module Peripherals
class OneDriveConnectionValidator
include TaggedLogging
include Dry::Monads[:maybe]

using ServiceResultRefinements
Expand All @@ -40,17 +41,19 @@ def initialize(storage:)
end

def validate
maybe_is_not_configured
.or { tenant_id_wrong }
.or { client_id_wrong }
.or { client_secret_wrong }
.or { drive_id_wrong }
.or { request_failed_with_unknown_error }
.or { drive_with_unexpected_content }
.value_or(ConnectionValidation.new(type: :healthy,
error_code: :none,
timestamp: Time.current,
description: nil))
with_tagged_logger do
maybe_is_not_configured
.or { tenant_id_wrong }
.or { client_id_wrong }
.or { client_secret_wrong }
.or { drive_id_wrong }
.or { request_failed_with_unknown_error }
.or { drive_with_unexpected_content }
.value_or(ConnectionValidation.new(type: :healthy,
error_code: :none,
timestamp: Time.current,
description: nil))
end
end

private
Expand Down Expand Up @@ -146,6 +149,11 @@ def drive_with_unexpected_content
unexpected_files = query.result.files.reject { |file| expected_folder_ids.include?(file.id) }
return None() if unexpected_files.empty?

file_representation = unexpected_files.map do |file|
"Name: #{file.name}, ID: #{file.id}, Location: #{file.location}"
end
warn "Unexpected files/folder found in group folder:\n\t#{file_representation.join("\n\t")}"

Some(ConnectionValidation.new(type: :warning,
error_code: :wrn_unexpected_content,
timestamp: Time.current,
Expand All @@ -157,10 +165,10 @@ def drive_with_unexpected_content
def request_failed_with_unknown_error
return None() if query.success?

Rails.logger.error("Connection validation failed with unknown error:\n\t" \
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"status: #{query.result}\n\t" \
"response: #{query.error_payload}")
error "Connection validation failed with unknown error:\n\t" \
"storage: ##{@storage.id} #{@storage.name}\n\t" \
"status: #{query.result}\n\t" \
"response: #{query.error_payload}"

Some(ConnectionValidation.new(type: :error,
error_code: :err_unknown,
Expand Down
2 changes: 1 addition & 1 deletion modules/storages/app/common/storages/tagged_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

module Storages
module TaggedLogging
delegate :info, :error, to: :logger
delegate :info, :warn, :error, to: :logger

# @param tag [Class, String, Array<Class, String>] the tag or list of tags to annotate the logs with
# @yield [Logger]
Expand Down

0 comments on commit 9933dae

Please sign in to comment.