Files
ubicloud/model/victoria_metrics_resource.rb
shikharbhardwaj 895499939c Create VictoriaMetrics resource
This is the initial commit for the Victoriametrics resource. This is a
basic version which supports creating a single-node Victoriametrics
instance backed by a VM, creating and managing appropriate certs and
authentication configuration. This version:
- Installs victoriametrics and vmauth binaries on the VM
- Configures the systemd services for these two services
- Sets up the certificates and http basic authentication credentials

This implementation only supports a single-node version for simplicity,
as current read/write benchmarks show VictoriaMetrics can support
upto 4k write targets (PG instnaces, for eg.) and around 2k concurrent
read users on a single standard-8 VM.  In the future, we can add support
for cluster mode, migrations, backup etc as needed.

Here is an example command to create a VictoriaMetrics resource:
st = Prog::VictoriaMetrics::VictoriaMetricsResourceNexus.assemble(
Config.victoria_metrics_service_project_id,
"victoriametrics-test", Location::HETZNER_FSN1_ID, "vmuser",
"standard-8", 20)
2025-05-01 21:55:32 +05:30

70 lines
2.9 KiB
Ruby

# frozen_string_literal: true
require_relative "../model"
class VictoriaMetricsResource < Sequel::Model
one_to_one :strand, key: :id
many_to_one :project
many_to_one :location, key: :location_id
one_to_many :servers, class: :VictoriaMetricsServer, key: :victoria_metrics_resource_id
many_to_one :private_subnet
include ResourceMethods
include SemaphoreMethods
semaphore :destroy, :reconfigure
plugin :column_encryption do |enc|
enc.column :admin_password
enc.column :root_cert_key_1
enc.column :root_cert_key_2
end
def hostname
"#{name}.#{Config.victoria_metrics_host_name}"
end
def root_certs
[root_cert_1, root_cert_2].join("\n") if root_cert_1 && root_cert_2
end
def set_firewall_rules
vm_firewall_rules = []
vm_firewall_rules.push({cidr: "0.0.0.0/0", port_range: Sequel.pg_range(22..22)})
vm_firewall_rules.push({cidr: "::/0", port_range: Sequel.pg_range(22..22)})
vm_firewall_rules.push({cidr: "0.0.0.0/0", port_range: Sequel.pg_range(8427..8427)})
vm_firewall_rules.push({cidr: "::/0", port_range: Sequel.pg_range(8427..8427)})
private_subnet.firewalls.first.replace_firewall_rules(vm_firewall_rules)
end
def self.redacted_columns
super + [:admin_password, :root_cert_1, :root_cert_2]
end
end
# Table: victoria_metrics_resource
# Columns:
# id | uuid | PRIMARY KEY
# name | text | NOT NULL
# created_at | timestamp with time zone | NOT NULL DEFAULT now()
# admin_user | text | NOT NULL
# admin_password | text | NOT NULL
# target_vm_size | text | NOT NULL
# target_storage_size_gib | bigint | NOT NULL
# root_cert_1 | text |
# root_cert_key_1 | text |
# root_cert_2 | text |
# root_cert_key_2 | text |
# certificate_last_checked_at | timestamp with time zone | NOT NULL DEFAULT now()
# project_id | uuid | NOT NULL
# location_id | uuid | NOT NULL
# private_subnet_id | uuid |
# Indexes:
# victoria_metrics_resource_pkey | PRIMARY KEY btree (id)
# Foreign key constraints:
# victoria_metrics_resource_location_id_fkey | (location_id) REFERENCES location(id)
# victoria_metrics_resource_private_subnet_id_fkey | (private_subnet_id) REFERENCES private_subnet(id)
# victoria_metrics_resource_project_id_fkey | (project_id) REFERENCES project(id)
# Referenced By:
# victoria_metrics_server | victoria_metrics_server_victoria_metrics_resource_id_fkey | (victoria_metrics_resource_id) REFERENCES victoria_metrics_resource(id)