Compare commits

..

16 commits

Author SHA1 Message Date
emily 8d2a367e92 grafana-agent: make bagel.monitoring.grafana-agent.exporters an attrset
This allows us to use multiple jobs, one for each additional exporter,
and set their `job_name` accordingly.

`job_name` is exported as `job` label on the resulting metrics.
This allows us to quickly get an understanding what metrics of an
exporter are actually available by simply filtering all metrics by
`{job="$jobname"}`
2024-07-08 09:34:26 +03:00
emily db8c831c2f grafana-agent: set hostname label on all metrics
This is handy to quickly see all metrics exported by a node, without
having to mangle with the already existing `instance` label.

`hostname` is essentially a variant of `instance` but without ports.
2024-07-08 09:34:26 +03:00
Ilya K ba0d50624d Switch to push metrics with Grafana Agent 2024-07-08 09:34:24 +03:00
Ilya K 40ba3c4ae7 Prepare for remote push metrics 2024-07-08 09:33:59 +03:00
Ilya K 346a74eabc Wire up Grafana to Alertmanager 2024-07-08 09:33:59 +03:00
Ilya K e8e262c6a4 Enable Mimir Alertmanager, add example alert
Still TODO: actually connect it to Matrix
2024-07-08 09:33:59 +03:00
Pierre Bourdon 5ebd71e4d5
tf/hydra: change Hydra URL 2024-07-08 00:01:24 +02:00
Pierre Bourdon 2700ac5efc
tf/dns: fix hydra CNAME 2024-07-08 00:01:14 +02:00
Pierre Bourdon caa1fce74e
hydra: move to hydra.forkos.org 2024-07-07 23:53:21 +02:00
Pierre Bourdon 5f8228536c
bagel-box: switch to forkos.org DNS root 2024-07-07 23:52:40 +02:00
Pierre Bourdon 078f298b8c
tf/dns: add bagel-box and hydra 2024-07-07 23:48:23 +02:00
Pierre Bourdon 4b0a2cd7e5
tf: add DNS management via Gandi 2024-07-07 20:43:05 +02:00
Pierre Bourdon dcd5f68545
tf: store hydra credentials in state via numtide/secret 2024-07-07 19:18:30 +02:00
Pierre Bourdon 7c6780a2a3
gitignore: add terraform lock file 2024-07-07 19:18:30 +02:00
Pierre Bourdon dd72904bf1
flake: replace tf wrappers with a single '.#tf' command 2024-07-07 19:18:30 +02:00
Pierre Bourdon 2e9483936e
tf/hydra: fix project owner to use an automation account 2024-07-07 18:44:17 +02:00
8 changed files with 97 additions and 38 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ result
config.tf.json config.tf.json
.direnv .direnv
.terraform .terraform
.terraform.lock.hcl

View file

@ -34,6 +34,7 @@
modules = [ modules = [
./terraform ./terraform
{ {
bagel.gandi.enable = true;
bagel.hydra.enable = true; bagel.hydra.enable = true;
} }
]; ];
@ -41,38 +42,16 @@
in in
{ {
apps.${system} = { apps.${system} = {
apply = { tf = {
type = "app"; type = "app";
program = toString (pkgs.writers.writeBash "apply" '' program = toString (pkgs.writers.writeBash "tf" ''
set -eo pipefail set -eo pipefail
rm -f config.tf.json ln -snf ${terraformCfg} config.tf.json
cp ${terraformCfg} config.tf.json exec ${lib.getExe terraform} "$@"
${lib.getExe terraform} init
${lib.getExe terraform} apply
''); '');
}; };
plan = {
type = "app";
program = toString (pkgs.writers.writeBash "plan" ''
set -eo pipefail
rm -f config.tf.json
cp ${terraformCfg} config.tf.json
${lib.getExe terraform} init
${lib.getExe terraform} plan
'');
};
# nix run ".#destroy"
destroy = {
type = "app";
program = toString (pkgs.writers.writeBash "destroy" ''
set -eo pipefail
ln -snf ${terraformCfg} config.tf.json
${lib.getExe terraform} init
${lib.getExe terraform} destroy
'');
};
default = self.apps.${system}.apply; default = self.apps.${system}.tf;
}; };
devShells.${system}.default = pkgs.mkShell { devShells.${system}.default = pkgs.mkShell {

View file

@ -42,9 +42,9 @@
}; };
security.acme.acceptTerms = true; security.acme.acceptTerms = true;
security.acme.defaults.email = "bagel@delroth.net"; security.acme.defaults.email = "infra@forkos.org";
services.openssh.enable = true; services.openssh.enable = true;
deployment.targetHost = "bagel-box.delroth.net"; deployment.targetHost = "bagel-box.infra.forkos.org";
} }

View file

@ -42,10 +42,10 @@ in {
port = port; port = port;
dbi = cfg.dbi; dbi = cfg.dbi;
hydraURL = "https://hydra.bagel.delroth.net"; hydraURL = "https://hydra.forkos.org";
useSubstitutes = false; useSubstitutes = false;
notificationSender = "bagel@delroth.net"; notificationSender = "hydra@forkos.org";
# XXX: hydra overlay sets pkgs.hydra, but hydra's nixos module uses # XXX: hydra overlay sets pkgs.hydra, but hydra's nixos module uses
# pkgs.hydra_unstable... # pkgs.hydra_unstable...
@ -108,7 +108,7 @@ in {
worker_processes auto; worker_processes auto;
''; '';
virtualHosts."hydra.bagel.delroth.net" = { virtualHosts."hydra.forkos.org" = {
forceSSL = true; forceSSL = true;
enableACME = true; enableACME = true;

7
terraform/common.nix Normal file
View file

@ -0,0 +1,7 @@
{
# Until we get some kind of KMS operational, store secrets in the state file.
terraform.required_providers.secret = {
version = "~> 1.2.1";
source = "numtide/secret";
};
}

View file

@ -1,5 +1,7 @@
{ {
imports = [ imports = [
./common.nix
./gandi.nix
./hydra.nix ./hydra.nix
./state.nix ./state.nix
]; ];

67
terraform/gandi.nix Normal file
View file

@ -0,0 +1,67 @@
{ lib, config, ... }:
let
inherit (lib) mkEnableOption mkIf tf;
cfg = config.bagel.gandi;
in
{
options.bagel.gandi = {
enable = mkEnableOption "the Gandi DNS configuration";
};
config = mkIf cfg.enable {
terraform.required_providers.gandi = {
version = "~> 2.3.0";
source = "go-gandi/gandi";
};
resource.secret_resource.gandi_pat.lifecycle.prevent_destroy = true;
provider.gandi = {
personal_access_token = tf.ref "resource.secret_resource.gandi_pat.value";
};
resource.gandi_livedns_domain.forkos_org = {
name = "forkos.org";
};
resource.gandi_livedns_record = let
record = name: ttl: type: values: {
inherit name ttl type values;
};
# TODO: make less fragile and have actual unique and stable names
canonicalName = record: let
name = builtins.replaceStrings ["."] ["_"] record.name;
in
"forkos_org_${record.type}_${name}";
forkosRecords = records:
builtins.listToAttrs (map (record: {
name = canonicalName record;
value = record // {
zone = tf.ref "resource.gandi_livedns_domain.forkos_org.id";
};
}) records);
in forkosRecords [
(record "cl" 3600 "A" ["163.172.69.160"])
(record "cl" 3600 "AAAA" ["2001:bc8:38ee:100:1000::10"])
(record "fodwatch" 3600 "A" ["163.172.69.160"])
(record "fodwatch" 3600 "AAAA" ["2001:bc8:38ee:100:1000::30"])
(record "netbox" 3600 "A" ["163.172.69.160"])
(record "netbox" 3600 "AAAA" ["2001:bc8:38ee:100:1000::20"])
(record "bagel-box.infra" 3600 "AAAA" ["2001:bc8:38ee:100:100::1"])
(record "gerrit01.infra" 3600 "AAAA" ["2001:bc8:38ee:100:1000::10"])
(record "fodwatch.infra" 3600 "AAAA" ["2001:bc8:38ee:100:1000::30"])
(record "meta01.infra" 3600 "AAAA" ["2001:bc8:38ee:100:1000::20"])
(record "grafana" 3600 "CNAME" ["netbox"])
(record "hydra" 3600 "CNAME" ["bagel-box.infra"])
(record "loki" 3600 "CNAME" ["meta01.infra"])
(record "mimir" 3600 "CNAME" ["grafana"])
];
};
}

View file

@ -1,6 +1,6 @@
{ lib, config, ... }: { lib, config, ... }:
let let
inherit (lib) mkEnableOption mkIf types mkOption; inherit (lib) mkEnableOption mkIf types mkOption tf;
cfg = config.bagel.hydra; cfg = config.bagel.hydra;
in in
{ {
@ -14,9 +14,12 @@ in
source = "DeterminateSystems/hydra"; source = "DeterminateSystems/hydra";
}; };
resource.secret_resource.hydra_password.lifecycle.prevent_destroy = true;
provider.hydra = { provider.hydra = {
host = "https://hydra.bagel.delroth.net"; host = "https://hydra.forkos.org";
# username/password are provided via HYDRA_USERNAME/HYDRA_PASSWORD username = "terraform";
password = tf.ref "resource.secret_resource.hydra_password.value";
}; };
resource.hydra_project.forkos = { resource.hydra_project.forkos = {
@ -24,7 +27,7 @@ in
display_name = "ForkOS"; display_name = "ForkOS";
description = "ForkOS packages collection"; description = "ForkOS packages collection";
homepage = "https://cl.forkos.org"; homepage = "https://cl.forkos.org";
owner = "raito"; owner = "terraform";
enabled = true; enabled = true;
visible = true; visible = true;
}; };