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:
@@ -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
|
||||
|
||||
19
backend/spec/services/ops/up_latency_tracker_spec.rb
Normal file
19
backend/spec/services/ops/up_latency_tracker_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Ops::UpLatencyTracker do
|
||||
before do
|
||||
described_class.redis&.del(described_class::REDIS_KEY)
|
||||
end
|
||||
|
||||
it "calcola il p95 sui campioni registrati" do
|
||||
(1..20).each { |ms| described_class.record(ms * 10) }
|
||||
|
||||
expect(described_class.p95).to eq(190)
|
||||
end
|
||||
|
||||
it "restituisce nil senza campioni" do
|
||||
expect(described_class.p95).to be_nil
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user