Skip to content

Commit

Permalink
change _lantern_internal schema to _lantern_extras_internal, send onl…
Browse files Browse the repository at this point in the history
…y one alert if healthcheck is errored
  • Loading branch information
var77 committed Jul 17, 2024
1 parent 6dd442d commit 97f9f9a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
19 changes: 12 additions & 7 deletions prog/lantern/lantern_doctor_nexus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,30 @@ def before_run
all_output = []

if !logs["stdout"].empty?
# stdout will be [{ "db": string, "result": string }]
# stdout will be [{ "db": string, "result": string, "success": bool }]
begin
all_output = JSON.parse(logs["stdout"])
rescue
all_output = [{"db" => "*", "result" => logs["stdout"], "err" => logs["stderr"]}]
end
end

if status == "Failed"
all_output = [{"db" => "*", "result" => logs["stdout"][..200], "err" => logs["stderr"], "success" => false}] + all_output.select { _1["success"] }
else
# resolve errored page if exists
query.update_page_status("*", vm.name, true, nil, nil)
else
# this is the case when command errored for some reason
all_output = [{"db" => "*", "result" => "", "err" => logs["stderr"]}]
end

condition = "healthy"
all_output.each do |output|
query.update_page_status(output["db"], vm.name, status == "Succeeded", output["result"], output["err"])
if !output["success"]
condition = "failed"
end

query.update_page_status(output["db"], vm.name, output["success"], output["result"], output["err"])
end

query.update(condition: (status == "Failed") ? "failed" : "healthy", last_checked: Time.new)
query.update(condition: condition, last_checked: Time.new)
vm.sshable.cmd("common/bin/daemonizer --clean #{query.task_name}")
end
end
Expand Down
6 changes: 3 additions & 3 deletions rhizome/lantern/bin/doctor/run_query
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run_for_db(db)
err = e.message
end

[success, {db: db, result: output, err: err}]
[success, {db: db, result: output, err: err, success: success}]
end

class SystemQueries
Expand All @@ -61,7 +61,7 @@ class SystemQueries
SELECT EXISTS (
SELECT FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = '_lantern_internal'
WHERE n.nspname = '_lantern_extras_internal'
AND c.relname = 'embedding_generation_jobs'
AND c.relkind = 'r'
);
Expand All @@ -71,7 +71,7 @@ SQL
return []
end

jobs = exec_sql("SELECT \"schema\", \"table\", src_column, dst_column, pk FROM _lantern_internal.embedding_generation_jobs WHERE init_finished_at IS NOT NULL AND canceled_at IS NULL;")
jobs = exec_sql("SELECT \"schema\", \"table\", src_column, dst_column, pk FROM _lantern_extras_internal.embedding_generation_jobs WHERE init_finished_at IS NOT NULL AND canceled_at IS NULL;")

jobs.split("\n").map do |row|
values = row.split(",")
Expand Down
3 changes: 1 addition & 2 deletions spec/prog/lantern/lantern_doctor_nexus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
describe "#wait_queries" do
before do
allow(sshable).to receive(:cmd).with("common/bin/daemonizer --check test_query").and_return("Succeeded")
allow(sshable).to receive(:cmd).with("common/bin/daemonizer --logs test_query").and_return(JSON.generate({"stdout" => '[{"db": "test_db", "result": "success"}]', "stderr" => ""}))
allow(sshable).to receive(:cmd).with("common/bin/daemonizer --logs test_query").and_return(JSON.generate({"stdout" => '[{"db": "test_db", "result": "success", "success": true }]', "stderr" => ""}))
allow(sshable).to receive(:cmd).with("common/bin/daemonizer --clean test_query").and_return("cleaned")
end

Expand All @@ -200,7 +200,6 @@
allow(sshable).to receive(:cmd).with("common/bin/daemonizer --check test_query").and_return("Failed")
allow(sshable).to receive(:cmd).with("common/bin/daemonizer --logs test_query").and_return(JSON.generate({"stdout" => "error parse", "stderr" => "error"}))

expect(query).to receive(:update_page_status).with("*", vm.name, true, nil, nil)
expect(query).to receive(:update_page_status).with("*", vm.name, false, "error parse", "error")
expect(query).to receive(:update).with(condition: "failed", last_checked: instance_of(Time))

Expand Down

0 comments on commit 97f9f9a

Please sign in to comment.