| 7 Dec 2024 |
hexa | [93980] WARNING: database "template1" has a collation version mismatch
[93980] DETAIL: The database was created using collation version 2.39, but the operating system provides version 2.40.
[93980] HINT: Rebuild all objects in this database that use the default collation and run ALTER DATABASE template1 REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.
| 23:00:16 |
hexa | rulerConfig = {
groups = [ {
name = "postgresql";
rules = [ {
alert = "PostgresqlCollationMismatch";
expr = ''
{unit="postgresql.service"}
|~ 'WARNING: database "[^"]+" has a collation version mismatch'
| regexp 'database "(?<database>[^"]+)"'
'';
labels.severity = "warning";
annotations.summary = "PostgreSQL database {{ $labels.database }} on {{ $labels.machine }}i reports database collation mismatch";
} ];
} ];
};
| 23:01:48 |
hexa | * rulerConfig = {
groups = [ {
name = "postgresql";
rules = [ {
alert = "PostgresqlCollationMismatch";
expr = ''
{unit="postgresql.service"}
|~ 'WARNING: database "[^"]+" has a collation version mismatch'
| regexp 'database "(?<database>[^"]+)"'
'';
labels.severity = "warning";
annotations.summary = "PostgreSQL database {{ $labels.database }} on {{ $labels.machine }}i reports database collation mismatch";
} ];
} ];
};
| 23:01:52 |
hexa | so for one it doesn't like single quotes 😄 | 23:03:24 |
hexa | and doesn't complain about it | 23:03:28 |
hexa | * rulerConfig = {
groups = [ {
name = "postgresql";
rules = [ {
alert = "PostgresqlCollationMismatch";
expr = ''
{unit="postgresql.service"}
|~ "WARNING: database \"[^\"]+\" has a collation version mismatch"
| regexp "database \"(?<database>[^\"]+)\""
'';
labels.severity = "warning";
annotations.summary = "PostgreSQL database {{ $labels.database }} on {{ $labels.machine }}i reports database collation mismatch";
} ];
} ];
};
| 23:04:17 |
| 8 Dec 2024 |
adamcstephens | My favorite, when something silently accepts invalid input | 00:22:52 |
hexa | the rules are just not as robust ans simple to test as promql | 00:49:26 |
hexa | # lokitool rules lint ruler.yml
ERRO[0000] unable parse rules file error="could not parse expression for alert 'PostgresqlCollationMismatch' in group 'postgresql': parse error at line 1, col 19: syntax error: unexpected IDENTIFIER" file=ruler.yml
lokitool: error: prepare operation unsuccessful, unable to parse rules files: file read error, try --help
| 00:50:15 |
hexa | I also love how builtins.toJSON puts everything on line 1 | 00:50:36 |
hexa | because that is totally for the benefit of dealing with such an error | 00:50:46 |
magic_rb | Kind of wish there was a way to make toJSON spew out pretty printed json | 00:56:06 |
hexa | the loki module should provide an option to accept rules directly and lint them | 01:22:20 |
hexa | {
"groups": [
{
"name": "postgresql",
"rules": [
{
"alert": "PostgresqlCollationMismatch",
"annotations": {
"summary": "PostgreSQL database on {{ $labels.machine }} reports database collations mismatches"
},
"expr": "sum by (machine) (counter_over_time({unit=\"postgresql.service\"} |~ \"REFRESH COLLATION VERSION\" [5m])) > 0\n",
"for": "1m",
"labels": {
"severity": "warning"
}
}
]
}
]
}
| 01:39:44 |
hexa | ERRO[0000] unable parse rules file error="could not parse expression for alert 'PostgresqlCollationMismatch' in group 'postgresql': parse error at line 1, col 19: syntax error: unexpected IDENTIFIER" file=/tmp/rules.yml
| 01:39:48 |
hexa | really, line 1 again? | 01:39:52 |
hexa | also line 1 when remarshalled to yaml | 01:40:37 |
hexa |
| 01:41:18 |
hexa | * groups:
- name: postgresql
rules:
- alert: PostgresqlCollationMismatch
annotations:
summary: PostgreSQL database on {{ $labels.machine }} reports database collations
mismatches
expr: "sum by (machine) (counter_over_time({unit=\"postgresql.service\"} |~ \"\
REFRESH COLLATION VERSION\" [5m])) > 0\n"
for: 1m
labels:
severity: warning
| 01:41:23 |
hexa | that yaml is also the shit | 01:41:28 |
hexa | awwh gross | 01:42:15 |
hexa | the tmpfiles created symlink is just never updated | 01:42:22 |
hexa | what the actual fuck | 01:42:27 |
hexa | nix just fails at yaml | 01:43:25 |
hexa | * nix just fails hard at yaml | 01:43:32 |
hexa | (╯°□°)╯︵ ┻━┻ | 01:43:42 |
hexa | so after fixing the expression and running the linter it reformats the file to | 01:45:17 |
hexa | namespace: rules
groups:
- name: postgresql
rules:
- alert: PostgresqlCollationMismatch
expr: |-
{unit="postgresql.service"} |~ "WARNING: database \"[^\"]+\" has a collation version mismatch" | regexp "database \"(?<database>[^\"]+)\""
for: 1m
labels:
severity: warning
annotations:
summary: PostgreSQL database on {{ $labels.machine }} reports database collations mismatches
| 01:45:28 |
hexa | and of course the loki module has a configFile escape | 02:31:49 |
hexa | yaml = pkgs.formats.yaml { };
rulesFile = pkgs.runCommand "rules.yaml" {
preferLocalBuild = true;
} ''
install -m0700 ${yaml.generate "rules.tmp" rulerConfig} $out
${lib.getExe' config.services.loki.package "lokitool"} rules lint $out
'';
| 02:41:49 |