Skip to content

Commit

Permalink
Merge pull request #1 from Peter-Searby/main
Browse files Browse the repository at this point in the history
Update client to be consistent with RFC
  • Loading branch information
avsej authored Dec 6, 2024
2 parents 8dfc093 + 1765cda commit f2d12ed
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions client-ruby/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def cancelled(service, bucket, host)
def record_latency(service, bucket, host, latency_sec)
metric =
if service == :kv
"sdk_#{service}_#{[:retrieval, :mutation_durable, :mutation_nondurable].sample}"
"sdk_#{service}_#{[:retrieval, :mutation_durable, :mutation_nondurable].sample}_duration_seconds"
else
"sdk_#{service}"
"sdk_#{service}_duration_seconds"
end
histogram = @histograms[bucket][host][metric]
histogram.each_key do |upper_bound|
Expand All @@ -57,7 +57,7 @@ def reset_metrics
@histograms = Hash.new do |level_1, bucket|
level_1[bucket] = Hash.new do |level_2, host|
level_2[host] = {
"sdk_kv_retrieval" => {
"sdk_kv_retrieval_duration_seconds" => {
0.001 => 0,
0.01 => 0,
0.1 => 0,
Expand All @@ -68,7 +68,7 @@ def reset_metrics
"sum" => 0,
"count" => 0,
},
"sdk_kv_mutation_nondurable" => {
"sdk_kv_mutation_nondurable_duration_seconds" => {
0.001 => 0,
0.01 => 0,
0.1 => 0,
Expand All @@ -79,7 +79,7 @@ def reset_metrics
"sum" => 0,
"count" => 0,
},
"sdk_kv_mutation_durable" => {
"sdk_kv_mutation_durable_duration_seconds" => {
0.01 => 0,
0.1 => 0,
1 => 0,
Expand All @@ -90,7 +90,7 @@ def reset_metrics
"sum" => 0,
"count" => 0,
},
"sdk_query" => {
"sdk_query_duration_seconds" => {
0.1 => 0,
1 => 0,
10 => 0,
Expand All @@ -100,7 +100,7 @@ def reset_metrics
"sum" => 0,
"count" => 0,
},
"sdk_search" => {
"sdk_search_duration_seconds" => {
0.1 => 0,
1 => 0,
10 => 0,
Expand All @@ -110,7 +110,7 @@ def reset_metrics
"sum" => 0,
"count" => 0,
},
"sdk_analytics" => {
"sdk_analytics_duration_seconds" => {
0.1 => 0,
1 => 0,
10 => 0,
Expand All @@ -128,7 +128,7 @@ def reset_metrics
def histogram_label(upper_bound)
return "+Inf" if upper_bound.infinite?

format("%0.3f", upper_bound).sub(/0+$/, "")
format("%0.3g", upper_bound).sub(/0+$/, "")
end

def export
Expand All @@ -141,7 +141,7 @@ def export
counters.each do |bucket, level_2|
level_2.each do |host, level_3|
level_3.each do |metric, value|
report << "#{metric}{agent=#{@agent.inspect},bucket=#{bucket.inspect},host=#{host.inspect}} #{value} #{scrapping_timestamp}"
report << "#{metric}{agent=#{@agent.inspect},bucket=#{bucket.inspect},node=#{host.inspect}} #{value.round} #{scrapping_timestamp}"
end
end
end
Expand All @@ -150,9 +150,9 @@ def export
level_3.each do |metric, histogram|
histogram.each do |label, value|
report << if label.is_a?(Numeric)
"#{metric}{le=#{histogram_label(label).inspect},agent=#{@agent.inspect},bucket=#{bucket.inspect},host=#{host.inspect}} #{value} #{scrapping_timestamp}"
"#{metric}_bucket{le=#{histogram_label(label).inspect},agent=#{@agent.inspect},bucket=#{bucket.inspect},node=#{host.inspect}} #{value.round} #{scrapping_timestamp}"
else
"#{metric}_#{label}{agent=#{@agent.inspect},bucket=#{bucket.inspect},host=#{host.inspect}} #{value}"
"#{metric}_#{label}{agent=#{@agent.inspect},bucket=#{bucket.inspect},node=#{host.inspect}} #{value.round}"
end
end
end
Expand Down

0 comments on commit f2d12ed

Please sign in to comment.