You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @Envek,
I've started using the exporter and I'm trying to set it up to use dynamic tags. This is a continuation of yabeda-rb/yabeda#12.
Using the existing method def yabeda_tags(*params) works but it has one drawback.
If the job needs to retrieve the tag from a database or other external source, it may do repeated queries that would be executed on the perform method already.
Example of duplicated database calls below. It could get more complicated depending on the job.
Ideally, if the Yabeda.with_tags worked inside the job, it would solve all problems, but since Sidekiq uses a middleware chain, I'm not sure if it's possible.
I checked the Yabeda middlewares on this project and changed ServerMiddleware a little bit to work with Thread.current[:yabeda_temporary_tags], the same strategy as with_tags.
moduleTestingclassServerMiddleware# CODE FROM https://github.com/yabeda-rb/yabeda-sidekiq/blob/master/lib/yabeda/sidekiq/server_middleware.rbdefcall(worker,job,queue)start=Time.nowbeginlatency= ::Sidekiq::Job.new(job).latency# removed any calls to metrics from before the actual job execution.yieldlabels=Yabeda::Sidekiq.labelize(worker,job,queue)Yabeda.sidekiq_job_latency.measure(labels,latency)Yabeda.sidekiq_jobs_success_total.increment(labels)rescueException# rubocop: disable Lint/RescueExceptionYabeda.sidekiq_jobs_failed_total.increment(labels)raiseensureYabeda.sidekiq_job_runtime.measure(labels,elapsed(start))Yabeda.sidekiq_jobs_executed_total.increment(labels)Thread.current[:yabeda_temporary_tags]={}endendprivatedefelapsed(start)(Time.now - start).round(3)endendend
Sidekiq config to remove existing middleware and add the new one.
classMyJobs::JobNameincludeSidekiq::Workerdefperform(id)# make sure that discovering tags is at the beginning of the method.Thread.current[:yabeda_temporary_tags]={importance: 'super important'}# this could be simplified with a concern maybe?Customer.find(id).do_super_important_stuffendend
What do you think about this strategy? Any points that draw your attention?
Can you see alternatives to it?
Best,
The text was updated successfully, but these errors were encountered:
For now I think you should be able to use Yabeda.with_tags and memoization in yabeda_tags to achieve the same result without changes in middlewares. Something like this:
I'm not sure whether or not yabeda-sidekiq should use Yabeda.with_tags by default in server middleware. Inside Yabeda.with_tags these tags will be added to all metrics, not only to sidekiq-specific ones. And some users tracks app-specific things from code executed within sidekiq jobs. I just not sure which behavior is more expected.
Hey @Envek,
I've started using the exporter and I'm trying to set it up to use dynamic tags. This is a continuation of yabeda-rb/yabeda#12.
Using the existing method
def yabeda_tags(*params)
works but it has one drawback.If the job needs to retrieve the tag from a database or other external source, it may do repeated queries that would be executed on the
perform
method already.Example of duplicated database calls below. It could get more complicated depending on the job.
Ideally, if the
Yabeda.with_tags
worked inside the job, it would solve all problems, but since Sidekiq uses a middleware chain, I'm not sure if it's possible.I checked the Yabeda middlewares on this project and changed ServerMiddleware a little bit to work with
Thread.current[:yabeda_temporary_tags]
, the same strategy aswith_tags
.Sidekiq config to remove existing middleware and add the new one.
What do you think about this strategy? Any points that draw your attention?
Can you see alternatives to it?
Best,
The text was updated successfully, but these errors were encountered: