2019-07-29 11:53:12 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module SidekiqMiddleware
|
2020-11-26 15:09:30 +00:00
|
|
|
module MetricsHelper
|
2019-11-22 18:06:00 +00:00
|
|
|
TRUE_LABEL = "yes"
|
|
|
|
FALSE_LABEL = "no"
|
|
|
|
|
2019-07-29 11:53:12 +00:00
|
|
|
private
|
|
|
|
|
2021-02-05 09:09:10 +00:00
|
|
|
def create_labels(worker_class, queue, job)
|
|
|
|
worker_name = (job['wrapped'].presence || worker_class).to_s
|
2021-03-16 12:11:31 +00:00
|
|
|
worker = find_worker(worker_name, worker_class)
|
2021-02-05 09:09:10 +00:00
|
|
|
|
2020-04-02 18:08:11 +00:00
|
|
|
labels = { queue: queue.to_s,
|
2021-02-05 09:09:10 +00:00
|
|
|
worker: worker_name,
|
2020-04-02 18:08:11 +00:00
|
|
|
urgency: "",
|
|
|
|
external_dependencies: FALSE_LABEL,
|
|
|
|
feature_category: "",
|
|
|
|
boundary: "" }
|
|
|
|
|
2021-03-16 12:11:31 +00:00
|
|
|
return labels unless worker.respond_to?(:get_urgency)
|
2019-11-22 18:06:00 +00:00
|
|
|
|
2021-03-16 12:11:31 +00:00
|
|
|
labels[:urgency] = worker.get_urgency.to_s
|
|
|
|
labels[:external_dependencies] = bool_as_label(worker.worker_has_external_dependencies?)
|
2019-11-22 18:06:00 +00:00
|
|
|
|
2021-03-16 12:11:31 +00:00
|
|
|
feature_category = worker.get_feature_category
|
2019-11-22 18:06:00 +00:00
|
|
|
labels[:feature_category] = feature_category.to_s
|
|
|
|
|
2021-03-16 12:11:31 +00:00
|
|
|
resource_boundary = worker.get_worker_resource_boundary
|
2019-11-22 18:06:00 +00:00
|
|
|
labels[:boundary] = resource_boundary == :unknown ? "" : resource_boundary.to_s
|
|
|
|
|
|
|
|
labels
|
|
|
|
end
|
|
|
|
|
|
|
|
def bool_as_label(value)
|
|
|
|
value ? TRUE_LABEL : FALSE_LABEL
|
2019-07-29 11:53:12 +00:00
|
|
|
end
|
2021-03-16 12:11:31 +00:00
|
|
|
|
|
|
|
def find_worker(worker_name, worker_class)
|
|
|
|
Gitlab::SidekiqConfig::DEFAULT_WORKERS.fetch(worker_name, worker_class)
|
|
|
|
end
|
2019-07-29 11:53:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|