From 170aeca7de9ca097420d55e3725aa351a816ee54 Mon Sep 17 00:00:00 2001 From: Varik Matevosyan Date: Mon, 8 Jul 2024 11:29:03 +0400 Subject: [PATCH] Set minimum memory limit for container to 500mb, show vm name in lantern view --- rhizome/lantern/lib/common.rb | 5 +++-- serializers/web/lantern.rb | 2 ++ spec/routes/web/project/location/lantern_spec.rb | 6 +++--- spec/serializers/web/lantern_spec.rb | 5 +++++ views/lantern/show.erb | 6 ++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/rhizome/lantern/lib/common.rb b/rhizome/lantern/lib/common.rb index bdaf869fb..ce101a071 100755 --- a/rhizome/lantern/lib/common.rb +++ b/rhizome/lantern/lib/common.rb @@ -106,8 +106,9 @@ def configure_tls(domain, email, dns_token, dns_zone_id, provider) def calculate_memory_sizes total_ram = (r "free -tk | awk 'NR == 2 {print $2}'") - # Calculate 95% of the total RAM in kilobytes - shared_buf_mb = (total_ram.to_i * 0.95 / 1024).round + # Calculate 95% of the total RAM in kilobytes, but reserve at least 500mb + # If the subtraction will underflow we will set the limit to 500mb + shared_buf_mb = [500, [(total_ram.to_i * 0.95 / 1024).round, total_ram.to_i / 1024 - 500].min].max # Calculate 50% of the total RAM in kilobytes shm_size_mb = (total_ram.to_i * 0.5 / 1024).round mem_limit_buf = "#{shared_buf_mb}MB" diff --git a/serializers/web/lantern.rb b/serializers/web/lantern.rb index 23655aad0..daf26a38b 100644 --- a/serializers/web/lantern.rb +++ b/serializers/web/lantern.rb @@ -9,6 +9,7 @@ def self.base(pg) name: pg.name, label: pg.label, state: pg.display_state, + vm_name: pg.representative_server&.vm&.name, primary?: pg.representative_server&.primary?, instance_type: pg.representative_server&.instance_type, location: pg.location, @@ -35,6 +36,7 @@ def self.base(pg) ubid: _1.ubid, state: _1.display_state, primary: _1.primary?, + vm_name: _1.vm.name, instance_type: _1.instance_type, lantern_version: _1.lantern_version, extras_version: _1.extras_version, diff --git a/spec/routes/web/project/location/lantern_spec.rb b/spec/routes/web/project/location/lantern_spec.rb index 10bcb2de9..091cd609f 100644 --- a/spec/routes/web/project/location/lantern_spec.rb +++ b/spec/routes/web/project/location/lantern_spec.rb @@ -218,7 +218,7 @@ allow(query_res).to receive(:where).and_return(query_res) expect(Project).to receive(:from_ubid).and_return(project).at_least(:once) allow(project).to receive(:lantern_resources_dataset).and_return(query_res) - replica = instance_double(LanternServer, primary?: false, display_state: "running", id: "pg2", ubid: "pg2", instance_type: "reader", lantern_version: "0.3.0", extras_version: "0.2.5", minor_version: "1", target_vm_size: "n1-standard-2", target_storage_size_gib: 50, connection_string: "pg://") + replica = instance_double(LanternServer, primary?: false, display_state: "running", id: "pg2", ubid: "pg2", instance_type: "reader", lantern_version: "0.3.0", extras_version: "0.2.5", minor_version: "1", target_vm_size: "n1-standard-2", target_storage_size_gib: 50, connection_string: "pg://", vm: instance_double(GcpVm, name: "test")) allow(pg).to receive(:servers).and_return([*pg.servers, replica]) expect(replica).to receive(:incr_take_over) @@ -234,7 +234,7 @@ allow(query_res).to receive(:where).and_return(query_res) expect(Project).to receive(:from_ubid).and_return(project).at_least(:once) allow(project).to receive(:lantern_resources_dataset).and_return(query_res) - replica = instance_double(LanternServer, primary?: false, display_state: "running", id: "pg2", ubid: "pg2", instance_type: "reader", lantern_version: "0.3.0", extras_version: "0.2.5", minor_version: "1", target_vm_size: "n1-standard-2", target_storage_size_gib: 50, connection_string: "pg://") + replica = instance_double(LanternServer, primary?: false, display_state: "running", id: "pg2", ubid: "pg2", instance_type: "reader", lantern_version: "0.3.0", extras_version: "0.2.5", minor_version: "1", target_vm_size: "n1-standard-2", target_storage_size_gib: 50, connection_string: "pg://", vm: instance_double(GcpVm, name: "test")) allow(pg).to receive(:servers).and_return([*pg.servers, replica]) expect(replica).to receive(:incr_destroy) @@ -250,7 +250,7 @@ allow(query_res).to receive(:where).and_return(query_res) expect(Project).to receive(:from_ubid).and_return(project).at_least(:once) allow(project).to receive(:lantern_resources_dataset).and_return(query_res) - serv = instance_double(LanternServer, display_state: "running", id: "pg2", ubid: "pg2", instance_type: "writer", lantern_version: "0.3.0", extras_version: "0.2.5", minor_version: "1", target_vm_size: "n1-standard-2", target_storage_size_gib: 50, connection_string: "pg://") + serv = instance_double(LanternServer, display_state: "running", id: "pg2", ubid: "pg2", instance_type: "writer", lantern_version: "0.3.0", extras_version: "0.2.5", minor_version: "1", target_vm_size: "n1-standard-2", target_storage_size_gib: 50, connection_string: "pg://", vm: instance_double(GcpVm, name: "test")) expect(serv).to receive(:primary?).and_return(false, false, true) allow(pg).to receive(:servers).and_return([*pg.servers, serv]) diff --git a/spec/serializers/web/lantern_spec.rb b/spec/serializers/web/lantern_spec.rb index 2ad3f4d7a..154ef240d 100644 --- a/spec/serializers/web/lantern_spec.rb +++ b/spec/serializers/web/lantern_spec.rb @@ -33,6 +33,7 @@ instance_type: "writer", hostname: "db.lantern.dev", primary?: true, + vm: instance_double(GcpVm, name: "test"), connection_string: "postgres://postgres:test123@db.lantern.dev:6432") expect(lantern).to receive(:representative_server).and_return(leader).at_least(:once) data = described_class.new(:default).serialize(lantern) @@ -54,6 +55,7 @@ instance_type: "writer", hostname: "db.lantern.dev", primary?: true, + vm: instance_double(GcpVm, name: "test"), connection_string: "postgres://postgres:test123@db.lantern.dev:6432") expect(lantern).to receive(:representative_server).and_return(nil).at_least(:once) data = described_class.new(:default).serialize(lantern) @@ -78,6 +80,7 @@ hostname: "db.lantern.dev", primary?: true, strand: instance_double(Strand, label: "wait"), + vm: instance_double(GcpVm, name: "test"), connection_string: "postgres://postgres:test123@db.lantern.dev:6432") expect(lantern).to receive(:representative_server).and_return(leader).at_least(:once) expect(lantern).to receive(:servers).and_return([leader]).at_least(:once) @@ -101,11 +104,13 @@ instance_type: "writer", hostname: "db.lantern.dev", primary?: true, + vm: instance_double(GcpVm, name: "test"), connection_string: "postgres://postgres:test123@db.lantern.dev:6432") expect(lantern).to receive(:representative_server).and_return(leader).at_least(:once) data = described_class.new(:default).serialize([lantern, lantern]) expect(data[0][:state]).to eq("running") + expect(data[0][:vm_name]).to eq("test") expect(data[1][:state]).to eq("running") expect(data[0][:connection_string]).to be_nil expect(data[1][:connection_string]).to be_nil diff --git a/views/lantern/show.erb b/views/lantern/show.erb index 544fabd2c..f882bb166 100644 --- a/views/lantern/show.erb +++ b/views/lantern/show.erb @@ -26,6 +26,7 @@ <% data = [ ["ID", @pg[:ubid]], ["Name", @pg[:name]], + ["VM", @pg[:vm_name]], ["Label", @pg[:label]], ["Org Id", @pg[:org_id]], ["Instance Type", @pg[:instance_type]], @@ -36,7 +37,7 @@ ["Compute", @pg[:vm_size]], ["Storage", "#{@pg[:storage_size_gib]} GB"] ] - + if @pg[:connection_string] == "" data.push(["Connection String", "Waiting for host to be ready..."]) else @@ -331,13 +332,14 @@ <% data = [ ["ID", server[:ubid]], + ["VM", server[:vm_name]], ["Lantern Version", server[:lantern_version]], ["Extras Version", server[:extras_version]], ["Minor Version", server[:minor_version]], ["Compute", server[:vm_size]], ["Storage", "#{server[:storage_size_gib]} GB"] ] - + if server[:connection_string] == "" data.push(["Connection String", "Waiting for host to be ready..."]) else