Skip to content

Commit

Permalink
Set minimum memory limit for container to 500mb, show vm name in lant…
Browse files Browse the repository at this point in the history
…ern view
  • Loading branch information
var77 committed Jul 8, 2024
1 parent d2ce167 commit 170aeca
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions rhizome/lantern/lib/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions serializers/web/lantern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions spec/routes/web/project/location/lantern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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])

Expand Down
5 changes: 5 additions & 0 deletions spec/serializers/web/lantern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions views/lantern/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand All @@ -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
Expand Down Expand Up @@ -331,13 +332,14 @@
<!-- Detail Card -->
<% 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
Expand Down

0 comments on commit 170aeca

Please sign in to comment.