mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-19 08:31:01 +03:00

After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.
Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.
A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.
This commit was automatically created and can be verified using
nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
--argstr baseRev 0128fbb0a5
result/bin/apply-formatting $NIXPKGS_PATH
121 lines
3.1 KiB
Nix
121 lines
3.1 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
options,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.prometheus.exporters.sql;
|
|
inherit (lib)
|
|
mkOption
|
|
types
|
|
mapAttrs
|
|
mapAttrsToList
|
|
concatStringsSep
|
|
;
|
|
cfgOptions = {
|
|
options = with types; {
|
|
jobs = mkOption {
|
|
type = attrsOf (submodule jobOptions);
|
|
default = { };
|
|
description = "An attrset of metrics scraping jobs to run.";
|
|
};
|
|
};
|
|
};
|
|
jobOptions = {
|
|
options = with types; {
|
|
interval = mkOption {
|
|
type = str;
|
|
description = ''
|
|
How often to run this job, specified in
|
|
[Go duration](https://golang.org/pkg/time/#ParseDuration) format.
|
|
'';
|
|
};
|
|
connections = mkOption {
|
|
type = listOf str;
|
|
description = "A list of connection strings of the SQL servers to scrape metrics from";
|
|
};
|
|
startupSql = mkOption {
|
|
type = listOf str;
|
|
default = [ ];
|
|
description = "A list of SQL statements to execute once after making a connection.";
|
|
};
|
|
queries = mkOption {
|
|
type = attrsOf (submodule queryOptions);
|
|
description = "SQL queries to run.";
|
|
};
|
|
};
|
|
};
|
|
queryOptions = {
|
|
options = with types; {
|
|
help = mkOption {
|
|
type = nullOr str;
|
|
default = null;
|
|
description = "A human-readable description of this metric.";
|
|
};
|
|
labels = mkOption {
|
|
type = listOf str;
|
|
default = [ ];
|
|
description = "A set of columns that will be used as Prometheus labels.";
|
|
};
|
|
query = mkOption {
|
|
type = str;
|
|
description = "The SQL query to run.";
|
|
};
|
|
values = mkOption {
|
|
type = listOf str;
|
|
description = "A set of columns that will be used as values of this metric.";
|
|
};
|
|
};
|
|
};
|
|
|
|
configFile =
|
|
if cfg.configFile != null then
|
|
cfg.configFile
|
|
else
|
|
let
|
|
nameInline = mapAttrsToList (k: v: v // { name = k; });
|
|
renameStartupSql = j: removeAttrs (j // { startup_sql = j.startupSql; }) [ "startupSql" ];
|
|
configuration = {
|
|
jobs = map renameStartupSql (
|
|
nameInline (mapAttrs (k: v: (v // { queries = nameInline v.queries; })) cfg.configuration.jobs)
|
|
);
|
|
};
|
|
in
|
|
builtins.toFile "config.yaml" (builtins.toJSON configuration);
|
|
in
|
|
{
|
|
extraOpts = {
|
|
configFile = mkOption {
|
|
type = with types; nullOr path;
|
|
default = null;
|
|
description = ''
|
|
Path to configuration file.
|
|
'';
|
|
};
|
|
configuration = mkOption {
|
|
type = with types; nullOr (submodule cfgOptions);
|
|
default = null;
|
|
description = ''
|
|
Exporter configuration as nix attribute set. Mutually exclusive with 'configFile' option.
|
|
'';
|
|
};
|
|
};
|
|
|
|
port = 9237;
|
|
serviceOpts = {
|
|
serviceConfig = {
|
|
ExecStart = ''
|
|
${pkgs.prometheus-sql-exporter}/bin/sql_exporter \
|
|
-web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
|
|
-config.file ${configFile} \
|
|
${concatStringsSep " \\\n " cfg.extraFlags}
|
|
'';
|
|
RestrictAddressFamilies = [
|
|
# Need AF_UNIX to collect data
|
|
"AF_UNIX"
|
|
];
|
|
};
|
|
};
|
|
}
|