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
|
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)
|
|
|
|
worker_name = (job['wrapped'].presence || worker_class).to_s
|
2021-04-29 21:17:54 +05:30
|
|
|
worker = find_worker(worker_name, worker_class)
|
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?)
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
feature_category = worker.get_feature_category
|
2020-01-01 13:55:28 +05:30
|
|
|
labels[:feature_category] = feature_category.to_s
|
|
|
|
|
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
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
def find_worker(worker_name, worker_class)
|
|
|
|
Gitlab::SidekiqConfig::DEFAULT_WORKERS.fetch(worker_name, worker_class)
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|