Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#59346] add log warning to unexpected content #17325

Merged
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
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
Loading