From 5ab05f16aaa44042666c69065dc1c7576eb0de51 Mon Sep 17 00:00:00 2001 From: dklawren Date: Wed, 12 Sep 2018 19:56:20 -0400 Subject: Bug 1490687 - Stop setting r+s on Phabricator attachments --- extensions/PhabBugz/lib/Feed.pm | 134 ---------------------------------------- 1 file changed, 134 deletions(-) (limited to 'extensions/PhabBugz/lib/Feed.pm') diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm index f2a440bb1..2dbeef6a7 100644 --- a/extensions/PhabBugz/lib/Feed.pm +++ b/extensions/PhabBugz/lib/Feed.pm @@ -14,7 +14,6 @@ use IO::Async::Loop; use List::Util qw(first); use List::MoreUtils qw(any uniq); use Moo; -use Scalar::Util qw(blessed); use Try::Tiny; use Type::Params qw( compile ); use Type::Utils; @@ -501,105 +500,6 @@ sub process_revision_change { $attachment->update($timestamp); } - # REVIEWER STATUSES - - my (@accepted, @denied); - foreach my $review (@{ $revision->reviews }) { - push @accepted, $review->{user} if $review->{status} eq 'accepted'; - push @denied, $review->{user} if $review->{status} eq 'rejected'; - } - - my @accepted_user_ids = map { $_->bugzilla_user->id } grep { defined $_->bugzilla_user } @accepted; - my @denied_user_ids = map { $_->bugzilla_user->id } grep { defined $_->bugzilla_user } @denied; - my %reviewers_hash = map { $_->{user}->name => 1 } @{ $revision->reviews }; - - foreach my $attachment (@attachments) { - my ($attach_revision_id) = ($attachment->filename =~ PHAB_ATTACHMENT_PATTERN); - next if $revision->id != $attach_revision_id; - - # Clear old accepted review flags if no longer accepted - my (@denied_flags, @new_flags, @removed_flags, %accepted_done, $flag_type); - foreach my $flag (@{ $attachment->flags }) { - next if $flag->type->name ne 'review'; - $flag_type = $flag->type if $flag->type->is_active; - next if $flag->status ne '+'; - if (any { $flag->setter->id == $_ } @denied_user_ids) { - INFO('Denying review flag set by ' . $flag->setter->name); - push(@denied_flags, { id => $flag->id, setter => $flag->setter, status => 'X' }); - } - if (any { $flag->setter->id == $_ } @accepted_user_ids) { - INFO('Skipping as review+ already set by ' . $flag->setter->name); - $accepted_done{$flag->setter->id}++; - } - if (!any { $flag->setter->id == $_ } (@accepted_user_ids, @denied_user_ids)) { - INFO('Clearing review+ flag set by ' . $flag->setter->name); - push(@removed_flags, { id => $flag->id, setter => $flag->setter, status => 'X' }); - } - } - - $flag_type ||= first { $_->name eq 'review' && $_->is_active } @{ $attachment->flag_types }; - - die "Unable to find review flag!" unless $flag_type; - - # Create new flags - foreach my $user_id (@accepted_user_ids) { - next if $accepted_done{$user_id}; - my $user = Bugzilla::User->check({ id => $user_id, cache => 1 }); - INFO('Setting new review+ flag for ' . $user->name); - push(@new_flags, { type_id => $flag_type->id, setter => $user, status => '+' }); - } - - # Process each flag change by updating the flag and adding a comment - foreach my $flag_data (@new_flags) { - my $comment = $flag_data->{setter}->name . " has approved the revision."; - $self->add_flag_comment( - { - bug => $bug, - attachment => $attachment, - comment => $comment, - user => $flag_data->{setter}, - old_flags => [], - new_flags => [$flag_data], - timestamp => $timestamp - } - ); - } - foreach my $flag_data (@denied_flags) { - my $comment = $flag_data->{setter}->name . " has requested changes to the revision.\n"; - $self->add_flag_comment( - { - bug => $bug, - attachment => $attachment, - comment => $comment, - user => $flag_data->{setter}, - old_flags => [$flag_data], - new_flags => [], - timestamp => $timestamp - } - ); - } - foreach my $flag_data (@removed_flags) { - my $comment; - if ( exists $reviewers_hash{ $flag_data->{setter}->name } ) { - $comment = "Flag set by " . $flag_data->{setter}->name . " is no longer active.\n"; - } - else { - $comment = $flag_data->{setter}->name . " has been removed from the revision.\n"; - } - $self->add_flag_comment( - { - bug => $bug, - attachment => $attachment, - comment => $comment, - user => $flag_data->{setter}, - old_flags => [$flag_data], - new_flags => [], - timestamp => $timestamp - } - ); - } - } - # FINISH UP $bug->update($timestamp); @@ -839,38 +739,4 @@ sub get_group_members { ); } -sub add_flag_comment { - state $check = compile( - $Invocant, - Dict [ - bug => Bug, - attachment => Attachment, - comment => Str, - user => User, - old_flags => ArrayRef, - new_flags => ArrayRef, - timestamp => Str, - ], - ); - my ( $self, $params ) = $check->(@_); - my ( $bug, $attachment, $comment, $user, $old_flags, $new_flags, $timestamp ) - = @$params{qw(bug attachment comment user old_flags new_flags timestamp)}; - - # when this function returns, Bugzilla->user will return to its previous value. - my $restore_prev_user = Bugzilla->set_user($user, scope_guard => 1); - - INFO("Flag comment: $comment"); - $bug->add_comment( - $comment, - { - isprivate => $attachment->isprivate, - type => CMT_ATTACHMENT_UPDATED, - extra_data => $attachment->id - } - ); - - $attachment->set_flags( $old_flags, $new_flags ); - $attachment->update($timestamp); -} - 1; -- cgit v1.2.3-24-g4f1b From 33b395b5761d143de7c06fc159cdb491a1f1654b Mon Sep 17 00:00:00 2001 From: dklawren Date: Thu, 20 Sep 2018 16:05:56 -0400 Subject: Bug 1492511 - Code to updating subscriber values for current private bugs is throwing errors in the phabbugz log --- extensions/PhabBugz/lib/Feed.pm | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'extensions/PhabBugz/lib/Feed.pm') diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm index 2dbeef6a7..b338e9a72 100644 --- a/extensions/PhabBugz/lib/Feed.pm +++ b/extensions/PhabBugz/lib/Feed.pm @@ -636,6 +636,11 @@ sub process_new_user { foreach my $attachment (@attachments) { my ($revision_id) = ($attachment->filename =~ PHAB_ATTACHMENT_PATTERN); + if (!$revision_id) { + WARN("Skipping " . $attachment->filename . " on bug $bug_id. Filename should be fixed."); + next; + } + INFO("Processing revision D$revision_id"); my $revision = Bugzilla::Extension::PhabBugz::Revision->new_from_query( -- cgit v1.2.3-24-g4f1b From bc31fe722c04724cc4fea6e14e042eff0e3d10ed Mon Sep 17 00:00:00 2001 From: Mars Date: Fri, 5 Oct 2018 19:02:55 -0400 Subject: Bug 1496832 - Add monitoring for feed daemon becoming unresponsive Use Datadog to count the number of times that jobs are run by the phabbugz job scheduler. This should catch problems if the process responsible for running the jobs dies. --- extensions/PhabBugz/lib/Feed.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'extensions/PhabBugz/lib/Feed.pm') diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm index b338e9a72..d8d4d6921 100644 --- a/extensions/PhabBugz/lib/Feed.pm +++ b/extensions/PhabBugz/lib/Feed.pm @@ -220,6 +220,11 @@ sub feed_query { $delete_build_target->execute($target->{name}, $target->{value}); } + + if (Bugzilla->datadog) { + my $dd = Bugzilla->datadog(); + $dd->increment('bugzilla.phabbugz.feed_query_count'); + } } sub user_query { @@ -260,6 +265,11 @@ sub user_query { }; $self->save_last_id($user_id, 'user'); } + + if (Bugzilla->datadog) { + my $dd = Bugzilla->datadog(); + $dd->increment('bugzilla.phabbugz.user_query_count'); + } } sub group_query { @@ -358,6 +368,11 @@ sub group_query { INFO( "Project " . $project->name . " updated" ); } } + + if (Bugzilla->datadog) { + my $dd = Bugzilla->datadog(); + $dd->increment('bugzilla.phabbugz.group_query_count'); + } } sub process_revision_change { -- cgit v1.2.3-24-g4f1b From 34fd0c3db18f7f5da558d8a8294e7fea61224186 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Tue, 9 Oct 2018 17:01:35 -0400 Subject: Bug 1496832 - Add timeouts to prevent feed daemon from becoming unresponsive --- extensions/PhabBugz/lib/Feed.pm | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'extensions/PhabBugz/lib/Feed.pm') diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm index d8d4d6921..71e6aa827 100644 --- a/extensions/PhabBugz/lib/Feed.pm +++ b/extensions/PhabBugz/lib/Feed.pm @@ -11,6 +11,7 @@ use 5.10.1; use IO::Async::Timer::Periodic; use IO::Async::Loop; +use IO::Async::Signal; use List::Util qw(first); use List::MoreUtils qw(any uniq); use Moo; @@ -47,6 +48,13 @@ my $Invocant = class_type { class => __PACKAGE__ }; sub start { my ($self) = @_; + my $sig_alarm = IO::Async::Signal->new( + name => 'ALRM', + on_receipt => sub { + FATAL("Timeout reached"); + exit; + }, + ); # Query for new revisions or changes my $feed_timer = IO::Async::Timer::Periodic->new( first_interval => 0, @@ -55,13 +63,17 @@ sub start { on_tick => sub { try { with_writable_database { + alarm(PHAB_TIMEOUT); $self->feed_query(); }; } catch { FATAL($_); + } + finally { + alarm(0); + Bugzilla->_cleanup(); }; - Bugzilla->_cleanup(); }, ); @@ -73,13 +85,17 @@ sub start { on_tick => sub { try { with_writable_database { + alarm(PHAB_TIMEOUT); $self->user_query(); }; } catch { FATAL($_); + } + finally { + alarm(0); + Bugzilla->_cleanup(); }; - Bugzilla->_cleanup(); }, ); @@ -91,13 +107,18 @@ sub start { on_tick => sub { try { with_writable_database { + alarm(PHAB_TIMEOUT); $self->group_query(); }; } catch { FATAL($_); + } + finally { + alarm(0); + Bugzilla->_cleanup(); }; - Bugzilla->_cleanup(); + }, ); @@ -105,6 +126,7 @@ sub start { $loop->add($feed_timer); $loop->add($user_timer); $loop->add($group_timer); + $loop->add($sig_alarm); $feed_timer->start; $user_timer->start; $group_timer->start; -- cgit v1.2.3-24-g4f1b