Files
ubicloud/prog/setup_grafana.rb
Jeremy Evans 15b91ff0c4 Absorb leaf into reap
Reviewing leaf usage in progs, it always occurs right after reap.
Combining leaf and reap methods avoids a redundant query for the
strand's children.

It's typical for nap or donate to be called after the leaf check
after reap.  Also build this into reap, by calling donate by default,
or nap if a nap keyword argument is given.

There are a few cases where reap was called without leaf/donate.
Add a fallthrough keyword argument to support this, so if there are
no children, it does not call either nap or donate

Vm::HostNexus#wait_prep and Kubernetes::UpgradeKubernetesNode#wait_new_node
both need the return value of the reapable child(ren). Add a reaper
keyword argument for this, which is called once for each child.

The most common pattern for using reap/leaf/donate was:

```ruby
reap
hop_download_lb_cert if leaf?
donate
```

This turns into:

```ruby
reap(:download_lb_cert)
```

The second most common pattern was:

```ruby
reap
donate unless leaf?
pop "upgrade cancelled" # or other code
```

This turns into:

```ruby
reap { pop "upgrade cancelled" }
```

In a few places, I changed operations on strand.children to
strand.children_dataset.  Now that we are no longer using
cached children by default, it's better to do these checks
in the database intead of in Ruby.  These places deserve careful
review:

* Prog::Minio::MinioServerNexus#unavailable
* Prog::Postgres::PostgresResourceNexus#wait
* Prog::Postgres::PostgresServerNexus#unavailable

For Prog::Vnet::LoadBalancerNexus#wait_update_vm_load_balancers,
I removed a check on the children completely. It was checking
for an exitval using children_dataset directly after reap,
which should only be true if there was still an active lease
for the child.  This also deserves careful review.

This broke many mocked tests.  This fixes the mocked tests
to use database-backed objects, ensuring that we are testing
observable behavior and not implementation details.
2025-06-26 03:49:53 +09:00

51 lines
1.4 KiB
Ruby

# frozen_string_literal: true
class Prog::SetupGrafana < Prog::Base
subject_is :sshable
def self.assemble(sshable_id, grafana_domain:, certificate_owner_email:)
grafana_domain = grafana_domain.strip
certificate_owner_email = certificate_owner_email.strip
if grafana_domain.empty? || certificate_owner_email.empty?
fail "grafana_domain and certificate_owner_email should not be empty"
end
unless (sshable = Sshable[sshable_id])
fail "Sshable does not exist"
end
Strand.create(prog: "SetupGrafana", label: "start", stack: [{subject_id: sshable.id, domain: grafana_domain, cert_email: certificate_owner_email}])
end
def domain
frame["domain"]
end
def cert_email
frame["cert_email"]
end
label def start
bud Prog::BootstrapRhizome, {"target_folder" => "host", "subject_id" => sshable.id, "user" => sshable.unix_user}
hop_wait_for_rhizome
end
label def wait_for_rhizome
reap(:install_grafana)
end
label def install_grafana
case sshable.d_check("install_grafana")
when "Succeeded"
sshable.d_clean("install_grafana")
pop "grafana was setup"
when "NotStarted"
sshable.d_run("install_grafana", "sudo", "host/bin/setup-grafana", domain, cert_email)
nap 10
when "InProgress"
nap 10
else
Clog.emit("Install grafana failed")
nap 65536
end
end
end