HLS su edge e monitoraggio ops con latenza p95.

Evita di saturare Puma in diretta, separa i check Rails/pubblico e traccia la latenza /up per alert più affidabili.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-14 21:19:32 +02:00
parent 13390d8a3c
commit a44d9fbadd
11 changed files with 290 additions and 52 deletions

View File

@@ -24,7 +24,7 @@ RSpec.describe Ops::HealthChecks do
)
%i[
check_recordings_size check_postgres check_redis check_mediamtx check_garage
check_sidekiq_heartbeat check_sidekiq_dead check_http_public
check_sidekiq_heartbeat check_sidekiq_dead check_http_rails check_rails_latency
].each do |method|
allow_any_instance_of(described_class).to receive(method).and_return(
described_class::Finding.new(
@@ -33,6 +33,7 @@ RSpec.describe Ops::HealthChecks do
)
)
end
allow_any_instance_of(described_class).to receive(:public_check_due?).and_return(false)
described_class.new.call
@@ -50,7 +51,7 @@ RSpec.describe Ops::HealthChecks do
)
%i[
check_recordings_size check_postgres check_redis check_mediamtx check_garage
check_sidekiq_heartbeat check_sidekiq_dead check_http_public
check_sidekiq_heartbeat check_sidekiq_dead check_http_rails check_rails_latency
].each do |method|
allow_any_instance_of(described_class).to receive(method).and_return(
described_class::Finding.new(
@@ -59,11 +60,40 @@ RSpec.describe Ops::HealthChecks do
)
)
end
allow_any_instance_of(described_class).to receive(:public_check_due?).and_return(false)
summary = described_class.new.summary
expect(summary[:status]).to eq("ok")
expect(summary[:checks].size).to eq(9)
expect(summary[:checks].size).to eq(10)
end
it "degraded quando la latenza p95 supera la soglia warning" do
allow_any_instance_of(described_class).to receive(:build_findings).and_return([
described_class::Finding.new(
kind: "rails_latency", severity: "warning", healthy: false,
title: "Latenza elevata", message: "p95 2500ms", metadata: {}, fingerprint: "rails_latency:p95"
)
])
expect(described_class.new.summary[:status]).to eq("degraded")
end
end
describe "#check_http_public" do
it "è warning, non critical" do
allow(Rails.env).to receive(:test?).and_return(false)
allow(MatchLiveTv).to receive(:app_public_url).and_return("https://www.matchlivetv.it")
checks = described_class.new
response = instance_double(Faraday::Response, status: 200)
allow(Faraday).to receive(:get).and_return(response)
finding = checks.send(:check_http_public)
expect(finding.severity).to eq("warning")
expect(finding.kind).to eq("http_public")
expect(finding.healthy).to be(true)
end
end
end