-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1610 from Skumring/Add-partition-remove-hook-logg…
…ing-and-metrics Add partition_remove_hook logging and metrics
- Loading branch information
Showing
8 changed files
with
372 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
class PartitionRemoveHookCollector < PrometheusExporter::Server::TypeCollector | ||
MAX_METRIC_AGE = 30 | ||
|
||
def initialize | ||
@data = [] | ||
@observers = { | ||
'executions' => PrometheusExporter::Metric::Counter.new('ruby_yeti_partition_removing_hook_executions', 'Sum of Yeti Partition Remove Hook execution runs'), | ||
'errors' => PrometheusExporter::Metric::Counter.new('ruby_yeti_partition_removing_hook_errors', 'Sum of Yeti Partition Remove Hook execution fails'), | ||
'duration' => PrometheusExporter::Metric::Counter.new('ruby_yeti_partition_removing_hook_duration', 'Sum of Yeti Partition Remove Hook execution duration in seconds') | ||
} | ||
end | ||
|
||
def type | ||
'ruby_yeti_partition_removing_hook' | ||
end | ||
|
||
def metrics | ||
return [] if @data.empty? | ||
|
||
metrics = {} | ||
@data.each do |obj| | ||
labels = {} | ||
# labels are passed by processor | ||
labels.merge!(obj['metric_labels']) if obj['metric_labels'] | ||
# custom_labels are passed by PrometheusExporter::Client | ||
labels.merge!(obj['custom_labels']) if obj['custom_labels'] | ||
|
||
@observers.each do |name, observer| | ||
value = obj[name] | ||
if value | ||
observer.observe(value, labels) | ||
metrics[name] = observer | ||
end | ||
end | ||
end | ||
|
||
metrics.values | ||
end | ||
|
||
def collect(obj) | ||
now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) | ||
|
||
obj['created_at'] = now | ||
@data.delete_if { |m| m['created_at'] + MAX_METRIC_AGE < now } | ||
@data << obj | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative './base_processor' | ||
|
||
class PartitionRemoveHookProcessor < BaseProcessor | ||
self.logger = Rails.logger | ||
self.type = 'ruby_yeti_partition_removing_hook' | ||
|
||
def collect(metric) | ||
format_metric(metric) | ||
end | ||
|
||
def self.collect_executions_metric | ||
collect(executions: 1) | ||
end | ||
|
||
def self.collect_errors_metric | ||
collect(errors: 1) | ||
end | ||
|
||
def self.collect_duration_metric(duration) | ||
collect(duration:) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.