Skip to content

Commit

Permalink
added warning client api for updating job
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Aug 19, 2024
1 parent 02f7d23 commit 460a621
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
42 changes: 40 additions & 2 deletions updater/lib/dependabot/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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?
Expand Down
24 changes: 24 additions & 0 deletions updater/lib/dependabot/opentelemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions updater/lib/dependabot/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 460a621

Please sign in to comment.