2019-07-29 07:53:12 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module SidekiqMiddleware
|
2020-11-26 10:09:30 -05:00
|
|
|
module MetricsHelper
|
2019-11-22 13:06:00 -05:00
|
|
|
TRUE_LABEL = "yes"
|
|
|
|
FALSE_LABEL = "no"
|
|
|
|
|
2019-07-29 07:53:12 -04:00
|
|
|
private
|
|
|
|
|
2021-02-05 04:09:10 -05:00
|
|
|
def create_labels(worker_class, queue, job)
|
|
|
|
worker_name = (job['wrapped'].presence || worker_class).to_s
|
|
|
|
|
2020-04-02 14:08:11 -04:00
|
|
|
labels = { queue: queue.to_s,
|
2021-02-05 04:09:10 -05:00
|
|
|
worker: worker_name,
|
2020-04-02 14:08:11 -04:00
|
|
|
urgency: "",
|
|
|
|
external_dependencies: FALSE_LABEL,
|
|
|
|
feature_category: "",
|
|
|
|
boundary: "" }
|
|
|
|
|
2020-01-23 10:08:46 -05:00
|
|
|
return labels unless worker_class && worker_class.include?(WorkerAttributes)
|
2019-11-22 13:06:00 -05:00
|
|
|
|
2020-03-02 13:07:42 -05:00
|
|
|
labels[:urgency] = worker_class.get_urgency.to_s
|
2019-11-22 13:06:00 -05:00
|
|
|
labels[:external_dependencies] = bool_as_label(worker_class.worker_has_external_dependencies?)
|
|
|
|
|
|
|
|
feature_category = worker_class.get_feature_category
|
|
|
|
labels[:feature_category] = feature_category.to_s
|
|
|
|
|
|
|
|
resource_boundary = worker_class.get_worker_resource_boundary
|
|
|
|
labels[:boundary] = resource_boundary == :unknown ? "" : resource_boundary.to_s
|
|
|
|
|
|
|
|
labels
|
|
|
|
end
|
|
|
|
|
|
|
|
def bool_as_label(value)
|
|
|
|
value ? TRUE_LABEL : FALSE_LABEL
|
2019-07-29 07:53:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|