debian-mirror-gitlab/lib/gitlab/sidekiq_middleware/metrics_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
module Gitlab
module SidekiqMiddleware
2021-02-22 17:27:13 +05:30
module MetricsHelper
2021-11-18 22:05:49 +05:30
include ::Gitlab::SidekiqMiddleware::WorkerContext
2020-01-01 13:55:28 +05:30
TRUE_LABEL = "yes"
FALSE_LABEL = "no"
2019-10-12 21:52:04 +05:30
private
2021-03-11 19:13:27 +05:30
def create_labels(worker_class, queue, job)
2021-11-18 22:05:49 +05:30
worker = find_worker(worker_class, job)
# This should never happen: we should always be able to find a
# worker class for a given Sidekiq job. But if we can't, we
# shouldn't blow up here, because we want to record this in our
# metrics.
worker_name = worker.try(:name) || worker.class.name
2021-03-11 19:13:27 +05:30
2020-04-22 19:07:51 +05:30
labels = { queue: queue.to_s,
2021-03-11 19:13:27 +05:30
worker: worker_name,
2020-04-22 19:07:51 +05:30
urgency: "",
external_dependencies: FALSE_LABEL,
feature_category: "",
boundary: "" }
2021-04-29 21:17:54 +05:30
return labels unless worker.respond_to?(:get_urgency)
2020-01-01 13:55:28 +05:30
2021-04-29 21:17:54 +05:30
labels[:urgency] = worker.get_urgency.to_s
labels[:external_dependencies] = bool_as_label(worker.worker_has_external_dependencies?)
2021-11-18 22:05:49 +05:30
labels[:feature_category] = worker.get_feature_category.to_s
2020-01-01 13:55:28 +05:30
2021-04-29 21:17:54 +05:30
resource_boundary = worker.get_worker_resource_boundary
2020-01-01 13:55:28 +05:30
labels[:boundary] = resource_boundary == :unknown ? "" : resource_boundary.to_s
labels
end
def bool_as_label(value)
value ? TRUE_LABEL : FALSE_LABEL
2019-10-12 21:52:04 +05:30
end
end
end
end