Module: InstJobsStatsd::Naming
- Defined in:
- lib/inst_jobs_statsd/naming.rb
Constant Summary collapse
- BASENAME =
"delayedjob"
Class Method Summary collapse
-
.basename ⇒ Object
The root prefix for all stat names TODO: Make this configurable.
- .dd_job_tags(job) ⇒ Object
- .dd_region_tags ⇒ Object
-
.job_tags(job) ⇒ Object
this converts Foo#bar“ or ”Foo.bar“ into ”Foo and “bar”, and makes sure the values are valid to be used for statsd names.
- .qualified_names(stat_name, job) ⇒ Object
-
.region_tags(stat_names) ⇒ Object
We are using all existing stat names here because we do not want to break existing dependencies on the non-regioned data.
- .split_to_tag(job) ⇒ Object
-
.tagged_stat(stat_name, job) ⇒ Object
Given a stat name, add a suffix to it to make it unique per job type – using the job’s class name and method name as appropriate.
Class Method Details
.basename ⇒ Object
The root prefix for all stat names TODO: Make this configurable
9 10 11 |
# File 'lib/inst_jobs_statsd/naming.rb', line 9 def self.basename BASENAME end |
.dd_job_tags(job) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inst_jobs_statsd/naming.rb', line 35 def self.(job) = return unless job [:cluster] = job.current_shard&.database_server&.id if job.respond_to?(:current_shard) [:priority] = job.priority .compact! return unless job.tag return if job.tag.include?("Class:0x") method_tag, obj_tag = split_to_tag(job) tag = obj_tag tag = [obj_tag, method_tag].join(".") if method_tag.present? [:tag] = tag end |
.dd_region_tags ⇒ Object
79 80 81 82 83 |
# File 'lib/inst_jobs_statsd/naming.rb', line 79 def self. return {} unless ENV["INST_JOBS_STATSD_NAMESPACE"] { namespace: ENV["INST_JOBS_STATSD_NAMESPACE"] } end |
.job_tags(job) ⇒ Object
this converts Foo#bar“ or ”Foo.bar“ into ”Foo and “bar”, and makes sure the values are valid to be used for statsd names
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/inst_jobs_statsd/naming.rb', line 55 def self.(job) return unless job return unless job.tag return if job.tag.include?("Class:0x") method_tag, obj_tag = split_to_tag(job) = [obj_tag] << method_tag if method_tag.present? end |
.qualified_names(stat_name, job) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/inst_jobs_statsd/naming.rb', line 13 def self.qualified_names(stat_name, job) names = ["#{basename}.#{stat_name}"] tagged = tagged_stat(names[0], job) names << tagged if tagged.present? names << (names) names.flatten.compact end |
.region_tags(stat_names) ⇒ Object
We are using all existing stat names here because we do not want to break existing dependencies on the non-regioned data
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/inst_jobs_statsd/naming.rb', line 68 def self.(stat_names) return unless ENV["INST_JOBS_STATSD_NAMESPACE"] stat_names.map do |name| name .split(".") .insert(2, ENV["INST_JOBS_STATSD_NAMESPACE"]) .join(".") end end |
.split_to_tag(job) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/inst_jobs_statsd/naming.rb', line 85 def self.split_to_tag(job) obj_tag, method_tag = job.tag.split(/[\.#]/, 2).map do |v| InstStatsd::Statsd.escape(v).gsub("::", "-") end [method_tag, obj_tag] end |
.tagged_stat(stat_name, job) ⇒ Object
Given a stat name, add a suffix to it to make it unique per job type – using the job’s class name and method name as appropriate
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/inst_jobs_statsd/naming.rb', line 24 def self.tagged_stat(stat_name, job) return unless job obj_tag, method_tag = (job) return if obj_tag.blank? tagged = "#{stat_name}.tag.#{obj_tag}" tagged += ".#{method_tag}" if method_tag.present? tagged end |