Class: GitlabQuality::TestTooling::CodeCoverage::ClickHouse::TestHealthScoreSnapshotter
- Inherits:
-
Object
- Object
- GitlabQuality::TestTooling::CodeCoverage::ClickHouse::TestHealthScoreSnapshotter
- Includes:
- Client
- Defined in:
- lib/gitlab_quality/test_tooling/code_coverage/click_house/test_health_score_snapshotter.rb
Overview
Freezes the day’s per-pillar Test Health Index scores into ‘code_coverage.test_health_score_history`. Reads the per-pillar score views (the same views the dashboard reads, so the snapshot cannot diverge from the live score) and tags each row with the snapshot date and the pillar.
Runs right after TestHealthRiskAggregator in the daily job: the views read ‘test_health_risk_per_group`, which the aggregator has just refreshed, so the freeze captures the current day. The producer never holds the score formula; it copies whatever the views compute.
Constant Summary collapse
- SQL_FILE =
File.('test_health_score_snapshot.sql', __dir__)
- PILLARS =
One INSERT per pillar. The token names the view (test_health_scores_<pillar>) and tags the row’s ‘pillar` column. Flaky is excluded until it is scored live.
%w[quarantine slow].freeze
- DATE_PATTERN =
/\A\d{4}-\d{2}-\d{2}\z/
Instance Method Summary collapse
-
#initialize(url:, database:, username: nil, password: nil, logger: nil) ⇒ TestHealthScoreSnapshotter
constructor
A new instance of TestHealthScoreSnapshotter.
- #run(snapshot_date: Date.today) ⇒ void
Constructor Details
#initialize(url:, database:, username: nil, password: nil, logger: nil) ⇒ TestHealthScoreSnapshotter
Returns a new instance of TestHealthScoreSnapshotter.
32 33 34 35 36 37 38 |
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/test_health_score_snapshotter.rb', line 32 def initialize(url:, database:, username: nil, password: nil, logger: nil) @url = url @database = database @username = username @password = password @logger = logger || ::Logger.new($stdout, level: ::Logger::INFO) end |
Instance Method Details
#run(snapshot_date: Date.today) ⇒ void
This method returns an undefined value.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gitlab_quality/test_tooling/code_coverage/click_house/test_health_score_snapshotter.rb', line 42 def run(snapshot_date: Date.today) PILLARS.each do |pillar| logger.info("#{LOG_PREFIX} Snapshotting #{pillar} scores snapshot_date=#{snapshot_date}") client.query(build_sql(snapshot_date: snapshot_date, pillar: pillar), format: "TabSeparated") end inserted = fetch_row_count(snapshot_date) logger.info("#{LOG_PREFIX} Score snapshot wrote #{inserted} rows for snapshot_date=#{snapshot_date}") rescue StandardError => e logger.error("#{LOG_PREFIX} Score snapshot failed for #{snapshot_date}: #{e.}") raise end |