diff --git a/updater/lib/dependabot/api_client.rb b/updater/lib/dependabot/api_client.rb index 65be0c1d5e..facf54b158 100644 --- a/updater/lib/dependabot/api_client.rb +++ b/updater/lib/dependabot/api_client.rb @@ -102,8 +102,11 @@ def close_pull_request(dependency_names, reason) sig { params(error_type: T.any(String, Symbol), error_details: T.nilable(T::Hash[T.untyped, T.untyped])).void } def record_update_job_error(error_type:, error_details:) ::Dependabot::OpenTelemetry.tracer.in_span("record_update_job_error", kind: :internal) do |_span| - ::Dependabot::OpenTelemetry.record_update_job_error(job_id: job_id, error_type: error_type, - error_details: error_details) + ::Dependabot::OpenTelemetry.record_update_job_error( + job_id: job_id, + error_type: error_type, + error_details: error_details + ) api_url = "#{base_url}/update_jobs/#{job_id}/record_update_job_error" body = { data: { @@ -123,6 +126,41 @@ def record_update_job_error(error_type:, error_details:) end end + sig do + params( + warn_type: T.any(String, Symbol), + warn_title: T.any(String, Symbol), + warn_message: T.any(String, Symbol) + ).void + end + def record_update_job_warn(warn_type:, warn_title:, warn_message:) + ::Dependabot::OpenTelemetry.tracer.in_span("record_update_job_message", kind: :internal) do |_span| + ::Dependabot::OpenTelemetry.record_update_job_warn( + job_id: job_id, + warn_type: warn_type, + warn_title: warn_title, + warn_message: warn_message + ) + api_url = "#{base_url}/update_jobs/#{job_id}/record_update_job_warn" + body = { + data: { + "warn-type": warn_type, + "warn-title": warn_title, + "warn-message": warn_message + } + } + response = http_client.post(api_url, json: body) + raise ApiError, response.body if response.code >= 400 + rescue HTTP::ConnectionError, OpenSSL::SSL::SSLError + retry_count ||= 0 + retry_count += 1 + raise if retry_count > 3 + + sleep(rand(3.0..10.0)) + retry + end + end + sig { params(error_type: T.any(Symbol, String), error_details: T.nilable(T::Hash[T.untyped, T.untyped])).void } def record_update_job_unknown_error(error_type:, error_details:) error_type = "unknown_error" if error_type.nil? diff --git a/updater/lib/dependabot/opentelemetry.rb b/updater/lib/dependabot/opentelemetry.rb index 3d89b65462..150c32d965 100644 --- a/updater/lib/dependabot/opentelemetry.rb +++ b/updater/lib/dependabot/opentelemetry.rb @@ -10,6 +10,10 @@ module OpenTelemetry module Attributes JOB_ID = "dependabot.job.id" + WARN_TYPE = "dependabot.job.warn_type" + WARN_TITLE = "dependabot.job.warn_title" + WARN_MESSAGE = "dependabot.job.warn_message" + WARN_DETAILS = "dependabot.job.warn_details" ERROR_TYPE = "dependabot.job.error_type" ERROR_DETAILS = "dependabot.job.error_details" METRIC = "dependabot.metric" @@ -89,6 +93,26 @@ def self.record_update_job_error(job_id:, error_type:, error_details:) current_span.add_event(error_type, attributes: attributes) end + sig do + params( + job_id: T.any(String, Integer), + warn_type: T.any(String, Symbol), + warn_title: T.any(String, Symbol), + warn_message: T.any(String, Symbol) + ).void + end + def self.record_update_job_warn(job_id:, warn_type:, warn_title:, warn_message:) + current_span = ::OpenTelemetry::Trace.current_span + + attributes = { + Attributes::JOB_ID => job_id, + Attributes::WARN_TYPE => warn_type, + Attributes::WARN_TITLE => warn_title, + Attributes::WARN_MESSAGE => warn_message + } + current_span.add_event(warn_type, attributes: attributes) + end + sig do params( error: StandardError, diff --git a/updater/lib/dependabot/service.rb b/updater/lib/dependabot/service.rb index 5e69e3d27a..39a31c3aba 100644 --- a/updater/lib/dependabot/service.rb +++ b/updater/lib/dependabot/service.rb @@ -27,11 +27,15 @@ class Service sig { returns(T::Array[T::Array[T.untyped]]) } attr_reader :errors + sig { returns(T::Array[T::Array[T.untyped]]) } + attr_reader :warns + sig { params(client: Dependabot::ApiClient).void } def initialize(client:) @client = client @pull_requests = T.let([], T::Array[T.untyped]) @errors = T.let([], T::Array[T.untyped]) + @warns = T.let([], T::Array[T.untyped]) @threads = T.let([], T::Array[T.untyped]) end @@ -81,6 +85,22 @@ def record_update_job_error(error_type:, error_details:, dependency: nil) client.record_update_job_error(error_type: error_type, error_details: error_details) end + sig do + params( + warn_type: T.any(String, Symbol), + warn_title: T.any(String, Symbol), + warn_message: T.any(String, Symbol) + ).void + end + def record_update_job_message(warn_type:, warn_title:, warn_message:) + warns << [warn_type.to_s, warn_title, warn_message] + client.record_update_job_warn( + warn_type: warn_type, + warn_title: warn_title, + warn_message: warn_message + ) + end + sig { params(error_type: T.any(String, Symbol), error_details: T.nilable(T::Hash[T.untyped, T.untyped])).void } def record_update_job_unknown_error(error_type:, error_details:) client.record_update_job_unknown_error(error_type: error_type, error_details: error_details)