From 670d2e1df786bc672a66ffbeea839dd11005976b Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 10 Jan 2026 00:38:08 +0100 Subject: [PATCH] Remove user_id and points_count parameters from Metrics::Archives::Operation and related calls. --- app/services/metrics/archives/operation.rb | 6 ++---- app/services/points/raw_data/archiver.rb | 21 +++++++------------ app/services/points/raw_data/clearer.rb | 7 ++----- app/services/points/raw_data/restorer.rb | 7 ++----- app/services/points/raw_data/verifier.rb | 9 +++----- spec/factories/points_raw_data_archives.rb | 9 +++++++- .../metrics/archives/operation_spec.rb | 3 +-- 7 files changed, 26 insertions(+), 36 deletions(-) diff --git a/app/services/metrics/archives/operation.rb b/app/services/metrics/archives/operation.rb index fff86749..4afe347c 100644 --- a/app/services/metrics/archives/operation.rb +++ b/app/services/metrics/archives/operation.rb @@ -3,11 +3,9 @@ class Metrics::Archives::Operation OPERATIONS = %w[archive verify clear restore].freeze - def initialize(operation:, status:, user_id: nil, points_count: 0) + def initialize(operation:, status:) @operation = operation - @status = status # 'success' or 'failure' - @user_id = user_id - @points_count = points_count + @status = status # 'success' or 'failure' end def call diff --git a/app/services/points/raw_data/archiver.rb b/app/services/points/raw_data/archiver.rb index 29a96be3..968c8d02 100644 --- a/app/services/points/raw_data/archiver.rb +++ b/app/services/points/raw_data/archiver.rb @@ -26,13 +26,10 @@ module Points end def archive_specific_month(user_id, year, month) - month_data = { - 'user_id' => user_id, - 'year' => year, - 'month' => month - } - - process_month(month_data) + # Direct call without error handling - allows errors to propagate + # This is intended for use in tests and manual operations where + # we want to know immediately if something went wrong + archive_month(user_id, year, month) end private @@ -83,8 +80,7 @@ module Points # Report successful archive operation Metrics::Archives::Operation.new( operation: 'archive', - status: 'success', - user_id: user_id + status: 'success' ).call true @@ -99,8 +95,7 @@ module Points # Report failed archive operation Metrics::Archives::Operation.new( operation: 'archive', - status: 'failure', - user_id: user_id + status: 'failure' ).call end @@ -117,7 +112,7 @@ module Points verification_result = verify_archive_immediately(archive, point_ids) unless verification_result[:success] Rails.logger.error("Immediate verification failed: #{verification_result[:error]}") - archive.destroy # Cleanup failed archive + archive.destroy # Cleanup failed archive raise StandardError, "Archive verification failed: #{verification_result[:error]}" end @@ -206,7 +201,7 @@ module Points year: year, month: month, chunk_number: chunk_number, - point_count: actual_count, # Use actual count, not assumed + point_count: actual_count, # Use actual count, not assumed point_ids_checksum: calculate_checksum(point_ids), archived_at: Time.current, metadata: { diff --git a/app/services/points/raw_data/clearer.rb b/app/services/points/raw_data/clearer.rb index 444be714..57ee30c7 100644 --- a/app/services/points/raw_data/clearer.rb +++ b/app/services/points/raw_data/clearer.rb @@ -78,9 +78,7 @@ module Points # Report successful clear operation Metrics::Archives::Operation.new( operation: 'clear', - status: 'success', - user_id: archive.user_id, - points_count: cleared_count + status: 'success' ).call # Report points removed (cleared from database) @@ -95,8 +93,7 @@ module Points # Report failed clear operation Metrics::Archives::Operation.new( operation: 'clear', - status: 'failure', - user_id: archive.user_id + status: 'failure' ).call end diff --git a/app/services/points/raw_data/restorer.rb b/app/services/points/raw_data/restorer.rb index aba0da66..2029be04 100644 --- a/app/services/points/raw_data/restorer.rb +++ b/app/services/points/raw_data/restorer.rb @@ -21,9 +21,7 @@ module Points # Report successful restore operation Metrics::Archives::Operation.new( operation: 'restore', - status: 'success', - user_id: user_id, - points_count: total_points + status: 'success' ).call # Report points restored (removed from archived state) @@ -35,8 +33,7 @@ module Points # Report failed restore operation Metrics::Archives::Operation.new( operation: 'restore', - status: 'failure', - user_id: user_id + status: 'failure' ).call raise diff --git a/app/services/points/raw_data/verifier.rb b/app/services/points/raw_data/verifier.rb index 63474c93..813e5482 100644 --- a/app/services/points/raw_data/verifier.rb +++ b/app/services/points/raw_data/verifier.rb @@ -52,8 +52,7 @@ module Points # Report successful verification operation Metrics::Archives::Operation.new( operation: 'verify', - status: 'success', - user_id: archive.user_id + status: 'success' ).call # Report verification duration @@ -69,8 +68,7 @@ module Points # Report failed verification operation Metrics::Archives::Operation.new( operation: 'verify', - status: 'failure', - user_id: archive.user_id + status: 'failure' ).call # Report verification duration with check name @@ -85,8 +83,7 @@ module Points # Report failed verification operation Metrics::Archives::Operation.new( operation: 'verify', - status: 'failure', - user_id: archive.user_id + status: 'failure' ).call # Report verification duration diff --git a/spec/factories/points_raw_data_archives.rb b/spec/factories/points_raw_data_archives.rb index 12f576c0..af7e5254 100644 --- a/spec/factories/points_raw_data_archives.rb +++ b/spec/factories/points_raw_data_archives.rb @@ -9,7 +9,14 @@ FactoryBot.define do point_count { 100 } point_ids_checksum { Digest::SHA256.hexdigest('1,2,3') } archived_at { Time.current } - metadata { { format_version: 1, compression: 'gzip' } } + metadata do + { + format_version: 1, + compression: 'gzip', + expected_count: point_count, + actual_count: point_count + } + end after(:build) do |archive| # Attach a test file diff --git a/spec/services/metrics/archives/operation_spec.rb b/spec/services/metrics/archives/operation_spec.rb index 3e227d1a..ed47805f 100644 --- a/spec/services/metrics/archives/operation_spec.rb +++ b/spec/services/metrics/archives/operation_spec.rb @@ -5,9 +5,8 @@ require 'prometheus_exporter/client' RSpec.describe Metrics::Archives::Operation do describe '#call' do - subject(:operation) { described_class.new(operation: operation_type, status: status, user_id: user_id).call } + subject(:operation) { described_class.new(operation: operation_type, status: status).call } - let(:user_id) { 123 } let(:operation_type) { 'archive' } let(:status) { 'success' } let(:prometheus_client) { instance_double(PrometheusExporter::Client) }