dawarich/spec/services/metrics/archives/verification_spec.rb
Evgenii Burmakin 6e9e02388b
Add immediate verification and count validation to raw data archiving (#2138)
* Add immediate verification and count validation to raw data archiving

* Remove verifying job

* Add archive metrics reporting

* Disable RailsPulse in Self-hosted Environments

* Remove user_id and points_count parameters from Metrics::Archives::Operation and related calls.
2026-01-10 00:39:48 +01:00

75 lines
2 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
require 'prometheus_exporter/client'
RSpec.describe Metrics::Archives::Verification do
describe '#call' do
subject(:verification) do
described_class.new(
duration_seconds: duration_seconds,
status: status,
check_name: check_name
).call
end
let(:duration_seconds) { 2.5 }
let(:status) { 'success' }
let(:check_name) { nil }
let(:prometheus_client) { instance_double(PrometheusExporter::Client) }
before do
allow(PrometheusExporter::Client).to receive(:default).and_return(prometheus_client)
allow(prometheus_client).to receive(:send_json)
allow(DawarichSettings).to receive(:prometheus_exporter_enabled?).and_return(true)
end
it 'sends verification duration histogram metric' do
expect(prometheus_client).to receive(:send_json).with(
{
type: 'histogram',
name: 'dawarich_archive_verification_duration_seconds',
value: duration_seconds,
labels: {
status: status
},
buckets: [0.1, 0.5, 1, 2, 5, 10, 30, 60]
}
)
verification
end
context 'when verification fails with check name' do
let(:status) { 'failure' }
let(:check_name) { 'count_mismatch' }
it 'sends verification failure counter metric' do
expect(prometheus_client).to receive(:send_json).with(
hash_including(
type: 'counter',
name: 'dawarich_archive_verification_failures_total',
value: 1,
labels: {
check: check_name
}
)
)
verification
end
end
context 'when prometheus exporter is disabled' do
before do
allow(DawarichSettings).to receive(:prometheus_exporter_enabled?).and_return(false)
end
it 'does not send metrics' do
expect(prometheus_client).not_to receive(:send_json)
verification
end
end
end
end