Method: NewRelic::Agent::Configuration::Manager#make_label_hash

Defined in:
lib/new_relic/agent/configuration/manager.rb

#make_label_hash(pairs, labels = nil) ⇒ Object

[View source]

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/new_relic/agent/configuration/manager.rb', line 328

def make_label_hash(pairs, labels = nil)
  # This can accept a hash, so force it down to an array of pairs first
  pairs = Array(pairs)

  unless valid_label_pairs?(pairs)
    NewRelic::Agent.logger.warn("#{MALFORMED_LABELS_WARNING}: #{labels || pairs}")
    return NewRelic::EMPTY_ARRAY
  end

  pairs = limit_number_of_labels(pairs)
  pairs = remove_duplicates(pairs)
  pairs.map do |key, value|
    {
      'label_type' => truncate(key),
      'label_value' => truncate(value.to_s, key)
    }
  end
end