Merge pull request #886 from grahamc/269
statsd: add a chance to set hostname and port in hydra.conf
This commit is contained in:
commit
a2717b3d7e
|
@ -187,6 +187,18 @@ following:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Statsd Configuration
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
By default, Hydra will send stats to statsd at `localhost:8125`. Point Hydra to a different server via:
|
||||||
|
|
||||||
|
```
|
||||||
|
<statsd>
|
||||||
|
host = alternative.host
|
||||||
|
port = 18125
|
||||||
|
</statsd>
|
||||||
|
```
|
||||||
|
|
||||||
Using LDAP as authentication backend (optional)
|
Using LDAP as authentication backend (optional)
|
||||||
-----------------------------------------------
|
-----------------------------------------------
|
||||||
|
|
||||||
|
@ -234,4 +246,4 @@ general any LDAP group of the form *hydra\_some\_role* (notice the
|
||||||
role_value: dn
|
role_value: dn
|
||||||
role_search_options:
|
role_search_options:
|
||||||
deref: always
|
deref: always
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use IPC::Run;
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT = qw(
|
our @EXPORT = qw(
|
||||||
getHydraHome getHydraConfig getBaseUrl
|
getHydraHome getHydraConfig getBaseUrl
|
||||||
getSCMCacheDir
|
getSCMCacheDir getStatsdConfig
|
||||||
registerRoot getGCRootsDir gcRootFor
|
registerRoot getGCRootsDir gcRootFor
|
||||||
jobsetOverview jobsetOverview_
|
jobsetOverview jobsetOverview_
|
||||||
getDrvLogPath findLog
|
getDrvLogPath findLog
|
||||||
|
@ -55,6 +55,23 @@ sub getHydraConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Return hash of statsd configuration of the following shape:
|
||||||
|
# (
|
||||||
|
# host => string,
|
||||||
|
# port => digit
|
||||||
|
# )
|
||||||
|
sub getStatsdConfig {
|
||||||
|
my ($config) = @_;
|
||||||
|
my $cfg = $config->{statsd};
|
||||||
|
my %statsd = defined $cfg ? ref $cfg eq "HASH" ? %$cfg : ($cfg) : ();
|
||||||
|
|
||||||
|
return {
|
||||||
|
"host" => %statsd{'host'} // 'localhost',
|
||||||
|
"port" => %statsd{'port'} // 8125,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sub getBaseUrl {
|
sub getBaseUrl {
|
||||||
my ($config) = @_;
|
my ($config) = @_;
|
||||||
return $config->{'base_uri'} // "http://" . hostname_long . ":3000";
|
return $config->{'base_uri'} // "http://" . hostname_long . ":3000";
|
||||||
|
|
|
@ -33,6 +33,10 @@ my $plugins = [Hydra::Plugin->instantiate(db => $db, config => $config)];
|
||||||
|
|
||||||
my $dryRun = defined $ENV{'HYDRA_DRY_RUN'};
|
my $dryRun = defined $ENV{'HYDRA_DRY_RUN'};
|
||||||
|
|
||||||
|
my $statsdConfig = Hydra::Helper::Nix::getStatsdConfig($config);
|
||||||
|
$Net::Statsd::HOST = $statsdConfig->{'host'};
|
||||||
|
$Net::Statsd::PORT = $statsdConfig->{'port'};
|
||||||
|
|
||||||
alarm 3600; # FIXME: make configurable
|
alarm 3600; # FIXME: make configurable
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,11 @@ use JSON;
|
||||||
STDERR->autoflush(1);
|
STDERR->autoflush(1);
|
||||||
binmode STDERR, ":encoding(utf8)";
|
binmode STDERR, ":encoding(utf8)";
|
||||||
|
|
||||||
|
my $config = getHydraConfig();
|
||||||
|
my $statsdConfig = Hydra::Helper::Nix::getStatsdConfig($config);
|
||||||
|
$Net::Statsd::HOST = $statsdConfig->{'host'};
|
||||||
|
$Net::Statsd::PORT = $statsdConfig->{'port'};
|
||||||
|
|
||||||
sub gauge {
|
sub gauge {
|
||||||
my ($name, $val) = @_;
|
my ($name, $val) = @_;
|
||||||
die unless defined $val;
|
die unless defined $val;
|
||||||
|
|
61
t/Config/statsd.t
Normal file
61
t/Config/statsd.t
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
use strict;
|
||||||
|
use Setup;
|
||||||
|
|
||||||
|
my %ctx = test_init(hydra_config => q|
|
||||||
|
<statsd>
|
||||||
|
host = foo.bar
|
||||||
|
port = 18125
|
||||||
|
</statsd>
|
||||||
|
|);
|
||||||
|
|
||||||
|
require Hydra::Helper::Nix;
|
||||||
|
use Test2::V0;
|
||||||
|
|
||||||
|
is(Hydra::Helper::Nix::getStatsdConfig(Hydra::Helper::Nix::getHydraConfig()), {
|
||||||
|
'host' => "foo.bar",
|
||||||
|
'port' => 18125
|
||||||
|
}, "Reading specific configuration from the hydra.conf works");
|
||||||
|
|
||||||
|
is(Hydra::Helper::Nix::getStatsdConfig(), {
|
||||||
|
'host' => "localhost",
|
||||||
|
'port' => 8125
|
||||||
|
}, "A totally empty configuration yields default options");
|
||||||
|
|
||||||
|
is(Hydra::Helper::Nix::getStatsdConfig({
|
||||||
|
"statsd" => {
|
||||||
|
|
||||||
|
}
|
||||||
|
}), {
|
||||||
|
'host' => "localhost",
|
||||||
|
'port' => 8125
|
||||||
|
}, "A empty statsd block yields default options");
|
||||||
|
|
||||||
|
is(Hydra::Helper::Nix::getStatsdConfig({
|
||||||
|
"statsd" => {
|
||||||
|
'host' => "statsdhost"
|
||||||
|
}
|
||||||
|
}), {
|
||||||
|
'host' => "statsdhost",
|
||||||
|
'port' => 8125
|
||||||
|
}, "An overridden statsd host propogates, but the other defaults are returned");
|
||||||
|
|
||||||
|
is(Hydra::Helper::Nix::getStatsdConfig({
|
||||||
|
"statsd" => {
|
||||||
|
'port' => 5218
|
||||||
|
}
|
||||||
|
}), {
|
||||||
|
'host' => "localhost",
|
||||||
|
'port' => 5218
|
||||||
|
}, "An overridden statsd port propogates, but the other defaults are returned");
|
||||||
|
|
||||||
|
is(Hydra::Helper::Nix::getStatsdConfig({
|
||||||
|
"statsd" => {
|
||||||
|
'host' => 'my.statsd.host',
|
||||||
|
'port' => 5218
|
||||||
|
}
|
||||||
|
}), {
|
||||||
|
'host' => "my.statsd.host",
|
||||||
|
'port' => 5218
|
||||||
|
}, "An overridden statsd port and host propogate");
|
||||||
|
|
||||||
|
done_testing;
|
Loading…
Reference in a new issue