forked from lix-project/hydra
hydra-notify: initial scratch take of prometheus events
This commit is contained in:
parent
4aa6a7b6ee
commit
5d0ad5f649
|
@ -470,6 +470,7 @@
|
|||
NetPrometheus
|
||||
NetStatsd
|
||||
PadWalker
|
||||
ParallelForkManager
|
||||
PerlCriticCommunity
|
||||
PrometheusTinyShared
|
||||
Readonly
|
||||
|
|
|
@ -3,12 +3,29 @@
|
|||
use strict;
|
||||
use utf8;
|
||||
use Getopt::Long;
|
||||
use HTTP::Server::PSGI;
|
||||
use Hydra::Event;
|
||||
use Hydra::Event::BuildFinished;
|
||||
use Hydra::Helper::AddBuilds;
|
||||
use Hydra::Helper::Nix;
|
||||
use Hydra::Plugin;
|
||||
use Hydra::PostgresListener;
|
||||
use Parallel::ForkManager;
|
||||
use Prometheus::Tiny::Shared;
|
||||
use Time::HiRes qw( gettimeofday tv_interval );
|
||||
|
||||
my $prom = Prometheus::Tiny::Shared->new;
|
||||
|
||||
my $fork_manager = Parallel::ForkManager->new(1 );
|
||||
$fork_manager->start_child("metrics_exporter", sub {
|
||||
my $server = HTTP::Server::PSGI->new(
|
||||
host => "127.0.0.1",
|
||||
port => 9091,
|
||||
timeout => 5,
|
||||
);
|
||||
|
||||
$server->run($prom->psgi);
|
||||
});
|
||||
|
||||
STDERR->autoflush(1);
|
||||
STDOUT->autoflush(1);
|
||||
|
@ -36,11 +53,19 @@ $listener->subscribe("step_finished");
|
|||
sub runPluginsForEvent {
|
||||
my ($event) = @_;
|
||||
|
||||
my $channelName = $event->{'channel_name'};
|
||||
|
||||
foreach my $plugin (@plugins) {
|
||||
$prom->inc("notify_plugin_executions", { channel => $channelName, plugin => ref $plugin });
|
||||
eval {
|
||||
my $startTime = [gettimeofday()];
|
||||
$event->execute($db, $plugin);
|
||||
|
||||
$prom->histogram_observe("notify_plugin_runtime", tv_interval($startTime), { channel => $channelName, plugin => ref $plugin });
|
||||
$prom->inc("notify_plugin_success", { channel => $channelName, plugin => ref $plugin });
|
||||
1;
|
||||
} or do {
|
||||
$prom->inc("notify_plugin_error", { channel => $channelName, plugin => ref $plugin });
|
||||
print STDERR "error running $event->{'channel_name'} hooks: $@\n";
|
||||
}
|
||||
}
|
||||
|
@ -60,19 +85,23 @@ for my $build ($db->resultset('Builds')->search(
|
|||
|
||||
# Process incoming notifications.
|
||||
while (!$queued_only) {
|
||||
$prom->inc("event_loop_iterations");
|
||||
my $messages = $listener->block_for_messages();
|
||||
while (my $message = $messages->()) {
|
||||
|
||||
$prom->set("event_received", time());
|
||||
my $channelName = $message->{"channel"};
|
||||
my $pid = $message->{"pid"};
|
||||
my $payload = $message->{"payload"};
|
||||
|
||||
$prom->inc("notify_event", { channel => $channelName });
|
||||
|
||||
eval {
|
||||
my $event = Hydra::Event->new_event($channelName, $message->{"payload"});
|
||||
runPluginsForEvent($event);
|
||||
|
||||
1;
|
||||
} or do {
|
||||
$prom->inc("notify_event_error", { channel => $channelName });
|
||||
print STDERR "error processing message '$payload' on channel '$channelName': $@\n";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue