Avvia i relay YouTube overflow dal Sidekiq home e passa STREAM/HCLOUD in produzione.

Così un CPX nuovo non richiede worker Docker a mano, l'agent è nel cloud-init e gli E2E restano non in elenco.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 08:57:56 +02:00
co-authored by Cursor
parent dd94bf7e66
commit 841a6a15be
10 changed files with 452 additions and 31 deletions
@@ -33,7 +33,15 @@ RSpec.describe Streams::YoutubeRelay do
end
let(:session_id) { SecureRandom.uuid }
let(:lab_node) { instance_double(StreamNode, slug: "ingest-lab-01") }
let(:lab_node) { instance_double(StreamNode, slug: "ingest-lab-01", role: "lab", relay_agent_url: nil) }
let(:cloud_node) do
instance_double(
StreamNode,
slug: "ingest-01",
role: "cloud",
relay_agent_url: "http://203.0.113.10:9100"
)
end
def session_double(stream_node: nil)
instance_double(
@@ -54,10 +62,14 @@ RSpec.describe Streams::YoutubeRelay do
expect(described_class.queue_for(session_double)).to eq("youtube_relay_home")
end
it "routes overflow sessions to the node slug queue" do
it "routes overflow lab sessions to the node slug queue" do
expect(described_class.queue_for(session_double(stream_node: lab_node))).to eq("youtube_relay_ingest-lab-01")
end
it "routes cloud overflow to youtube_relay_cloud for the home dispatcher" do
expect(described_class.queue_for(session_double(stream_node: cloud_node))).to eq("youtube_relay_cloud")
end
it "requeues ensure to the assigned node when the local worker does not match" do
with_env("STREAM_NODE_SLUG" => "home", "YOUTUBE_RELAY_WORKER" => "1") do
allow(described_class).to receive(:worker?).and_return(true)
@@ -67,6 +79,13 @@ RSpec.describe Streams::YoutubeRelay do
expect(described_class.ensure_on_worker!(session_double(stream_node: lab_node))).to eq(:wrong_host)
end
end
it "lets the home worker process cloud overflow instead of requeueing to a per-node queue" do
with_env("STREAM_NODE_SLUG" => "home", "YOUTUBE_RELAY_WORKER" => "1") do
expect(described_class.can_process?(session_double(stream_node: cloud_node))).to be true
expect(described_class.cloud_home_dispatch?(session_double(stream_node: cloud_node))).to be true
end
end
end
describe "multi-host sticky stop/capacity" do
@@ -125,7 +144,7 @@ RSpec.describe Streams::YoutubeRelay do
let(:session) do
instance_double(
StreamSession,
stream_node: instance_double(StreamNode, slug: "ingest-lab-01"),
stream_node: instance_double(StreamNode, slug: "ingest-lab-01", role: "lab", relay_agent_url: nil),
mediamtx_path_name: "live/match_abc",
mediamtx_internal_rtmp_url: "rtmp://10.0.0.9:1935",
mediamtx_internal_hls_url: "http://10.0.0.9:8888"
@@ -179,7 +198,8 @@ RSpec.describe Streams::YoutubeRelay do
expect(described_class).to receive(:agent_request).with(
Net::HTTP::Post,
"/relays",
hash_including("session_id" => "sess-1", "path" => "live/match_abc")
hash_including("session_id" => "sess-1", "path" => "live/match_abc"),
session: session
).and_return("pid" => 4242)
pid = with_env("STREAM_NODE_RELAY_AGENT_URL" => "http://203.0.113.10:9100") do
@@ -189,3 +209,27 @@ RSpec.describe Streams::YoutubeRelay do
end
end
end
RSpec.describe StreamNode do
describe "#relay_agent_url" do
it "uses metadata public_ip on cloud nodes" do
node = described_class.new(
slug: "ingest-01",
hostname: "ingest-01.mltv-stream.net",
role: "cloud",
status: "ready",
provider: "hetzner",
rtmp_base_url: "rtmp://x:1935",
hls_base_url: "https://x/hls",
api_base_url: "http://10.0.0.9:9997",
metadata: { "public_ip" => "203.0.113.9" }
)
expect(node.relay_agent_url).to eq("http://203.0.113.9:9100")
end
it "is nil for lab nodes" do
node = described_class.new(role: "lab", api_base_url: "http://10.0.0.9:9997", metadata: { "public_ip" => "1.2.3.4" })
expect(node.relay_agent_url).to be_nil
end
end
end