discourse / prometheus_exporter

A framework for collecting and aggregating prometheus metrics
MIT License
525 stars 153 forks source link

Dynamic labels for sidekiq jobs #274

Open edenisn opened 1 year ago

edenisn commented 1 year ago

Hi, thanks for this beautiful gem. I see that we can added static labels in sidekiq job (on official page of a gem): Custom labels can be added for individual jobs by defining a class method on the job class. These labels will be added to all Sidekiq metrics written by the job:

  class WorkerWithCustomLabels
    def self.custom_labels
      { my_label: 'value-here', other_label: 'second-val' }
    end

    def perform; end
  end

but, what about dynamic labels? How we can add those labels?

SamSaffron commented 1 year ago

I think you would need to extend the class to support that. What exactly are you trying to achieve?

edenisn commented 1 year ago

So, for example above with static label when we start sidekiq job - WorkerWithCustomLabels it will add two labels - my_label = 'value-here' and other_label = 'second-val', those labels are static. But, in some cases we want to add dynamic labels, for example:

class SomeTestJob
  def perform(event_id)
    event = Event.find(event_id)
    label = event.type
  end  
end

and I want to set this label for this job with - label = event.type. Type of this label is not static - it's dynamic label. And my question: how can we add those type of labels to Sidekiq jobs? Thanks!

edenisn commented 1 year ago

It's seems to me that it should look something like this https://github.com/yabeda-rb/yabeda/issues/12