Tickets: track whatever ticket Tinker names, as Thor does (#66 item 6) #75
No files matched your search
@@ -519,7 +519,9 @@ key instead of guessing from title words. Gandalf's scheme (`ticket_text.dedup_k
|
|||||||
|
|
||||||
Names are lowercased, and anything outside `a-z 0-9 _ . : -` becomes `-`. Tinker's reopen window
|
Names are lowercased, and anything outside `a-z 0-9 _ . : -` becomes `-`. Tinker's reopen window
|
||||||
applies per key: a match on a ticket closed under 7 days ago reopens it; an older one gets a new,
|
applies per key: a match on a ticket closed under 7 days ago reopens it; an older one gets a new,
|
||||||
linked ticket (`new_recurrence`). `scripts/dedup_key_map.py` prints the key for each of Gandalf's open
|
linked ticket (`new_recurrence`). Gandalf tracks whatever ticket Tinker names, as Thor and hwmonDaemon do,
|
||||||
|
including `recurrence_noted` (a Closed ticket in a workflow set never to reopen, where Tinker adds one
|
||||||
|
note per closed period). `scripts/dedup_key_map.py` prints the key for each of Gandalf's open
|
||||||
tickets, for Tinker's `scripts/backfill_dedup_keys.php`, so switching to keys opens no duplicates.
|
tickets, for Tinker's `scripts/backfill_dedup_keys.php`, so switching to keys opens no duplicates.
|
||||||
|
|
||||||
**Thor first.** Thor correlates host health (crashes, OOM, fencing) across all three apps. Before
|
**Thor first.** Thor correlates host health (crashes, OOM, fencing) across all three apps. Before
|
||||||
|
|||||||
+8
-19
@@ -524,8 +524,6 @@ class TicketClient:
|
|||||||
self.comments_denied = False
|
self.comments_denied = False
|
||||||
self.read_url = cfg.get('read_url') or (
|
self.read_url = cfg.get('read_url') or (
|
||||||
urljoin(self.url, 'api/tickets_api.php') if self.url else '')
|
urljoin(self.url, 'api/tickets_api.php') if self.url else '')
|
||||||
# Titles whose create matched a Closed ticket Tinker couldn't reopen: {title: (ticket_id, when)}
|
|
||||||
self._closed_matches: Dict[str, tuple] = {}
|
|
||||||
|
|
||||||
def comment(self, ticket_id: str, text: str) -> bool:
|
def comment(self, ticket_id: str, text: str) -> bool:
|
||||||
"""Add a Markdown comment to a ticket. Never raises; False means try again later."""
|
"""Add a Markdown comment to a ticket. Never raises; False means try again later."""
|
||||||
@@ -593,26 +591,21 @@ class TicketClient:
|
|||||||
logger.error(f'Reading open tickets failed: {e}')
|
logger.error(f'Reading open tickets failed: {e}')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# How long to wait before asking again after a create matched an unreopenable Closed ticket.
|
|
||||||
# Each ask adds a "recurred" comment to that ticket, so once a poll would pile them up.
|
|
||||||
CLOSED_MATCH_RETRY_S = 24 * 3600
|
|
||||||
|
|
||||||
def create(self, title: str, description: str, priority: str = '2',
|
def create(self, title: str, description: str, priority: str = '2',
|
||||||
dedup_key: Optional[str] = None) -> Optional[str]:
|
dedup_key: Optional[str] = None) -> Optional[str]:
|
||||||
"""Open a ticket. Returns its ID, or None if there is no ticket to track.
|
"""Open a ticket. Returns its ID, or None if there is no ticket to track.
|
||||||
|
|
||||||
Tinker deduplicates, on dedup_key when one is sent (tinker_tickets#123), else on the
|
Tinker deduplicates, on dedup_key when one is sent (tinker_tickets#123), else on the
|
||||||
title: the response's `action` says what happened (new, deduplicated, updated,
|
title: the response's `action` says what happened (new, deduplicated, updated,
|
||||||
reopened, new_recurrence, recurrence_noted). recurrence_noted means it matched a Closed
|
reopened, new_recurrence, recurrence_noted). Every one names the ticket that now tracks
|
||||||
ticket it could not reopen unattended; that ticket isn't tracking this alert, so it
|
this problem, so Gandalf uses it, as Thor and hwmonDaemon do (gandalf#66 item 6):
|
||||||
isn't used.
|
reopened is a ticket closed under 7 days ago, new_recurrence a new ticket linked to an
|
||||||
|
older one, and recurrence_noted a Closed ticket in a workflow set never to reopen
|
||||||
|
(Tinker adds one note per closed period, so asking again adds nothing).
|
||||||
"""
|
"""
|
||||||
if not self.api_key or not self.url:
|
if not self.api_key or not self.url:
|
||||||
logger.warning('Ticket API not configured: skipping ticket creation')
|
logger.warning('Ticket API not configured: skipping ticket creation')
|
||||||
return None
|
return None
|
||||||
seen = self._closed_matches.get(title)
|
|
||||||
if seen and time.time() - seen[1] < self.CLOSED_MATCH_RETRY_S:
|
|
||||||
return None
|
|
||||||
payload = {
|
payload = {
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
@@ -639,13 +632,9 @@ class TicketClient:
|
|||||||
return None
|
return None
|
||||||
action = data.get('action') or 'created'
|
action = data.get('action') or 'created'
|
||||||
if action == 'recurrence_noted':
|
if action == 'recurrence_noted':
|
||||||
self._closed_matches[title] = (tid, time.time())
|
logger.warning(f'Ticket #{tid} is Closed and Tinker is set never to reopen it; it noted the '
|
||||||
logger.warning(
|
f'recurrence and Gandalf tracks it there. Reopen it in Tinker to work it: {title}')
|
||||||
f'Ticket API matched Closed ticket #{tid}, which it could not reopen; not using it '
|
else:
|
||||||
f'for this alert. Reopen #{tid} in Tinker to track it there. Retrying in 24 h: {title}'
|
|
||||||
)
|
|
||||||
return None
|
|
||||||
self._closed_matches.pop(title, None)
|
|
||||||
logger.info(f'Ticket #{tid} ({action}): {title}')
|
logger.info(f'Ticket #{tid} ({action}): {title}')
|
||||||
return tid
|
return tid
|
||||||
if data.get('existing_ticket_id'):
|
if data.get('existing_ticket_id'):
|
||||||
|
|||||||
+11
-14
@@ -1204,23 +1204,20 @@ class TestTicketClientCreate:
|
|||||||
with self._post({'success': True, 'ticket_id': '6'}):
|
with self._post({'success': True, 'ticket_id': '6'}):
|
||||||
assert c.create('u', 'd') == '6'
|
assert c.create('u', 'd') == '6'
|
||||||
|
|
||||||
def test_recurrence_on_a_closed_ticket_is_not_used_and_not_retried_each_poll(self):
|
def test_every_tinker_action_names_the_ticket_to_track(self):
|
||||||
|
"""gandalf#66 item 6: like Thor and hwmonDaemon, use whatever ticket Tinker names."""
|
||||||
|
c = self._client()
|
||||||
|
for action in ('reopened', 'new_recurrence', 'recurrence_noted', 'updated'):
|
||||||
|
with self._post({'success': True, 'ticket_id': '993', 'action': action}):
|
||||||
|
assert c.create('t', 'd') == '993', action
|
||||||
|
|
||||||
|
def test_recurrence_noted_is_not_throttled(self):
|
||||||
|
# Tinker adds one note per closed period itself, so asking again each poll adds nothing
|
||||||
c = self._client()
|
c = self._client()
|
||||||
with self._post({'success': True, 'ticket_id': '993', 'action': 'recurrence_noted'}) as post:
|
with self._post({'success': True, 'ticket_id': '993', 'action': 'recurrence_noted'}) as post:
|
||||||
assert c.create('t', 'd') is None
|
|
||||||
assert c.create('t', 'd') is None
|
|
||||||
assert post.call_count == 1 # the second poll doesn't add another comment to the closed ticket
|
|
||||||
with self._post({'success': True, 'ticket_id': '7', 'action': 'none'}) as post:
|
|
||||||
assert c.create('other', 'd') == '7' # other alerts are unaffected
|
|
||||||
|
|
||||||
def test_retry_after_a_day(self):
|
|
||||||
c = self._client()
|
|
||||||
with self._post({'success': True, 'ticket_id': '993', 'action': 'recurrence_noted'}):
|
|
||||||
c.create('t', 'd')
|
c.create('t', 'd')
|
||||||
c._closed_matches['t'] = ('993', time.time() - c.CLOSED_MATCH_RETRY_S - 1)
|
c.create('t', 'd')
|
||||||
with self._post({'success': True, 'ticket_id': '8', 'action': 'none'}):
|
assert post.call_count == 2
|
||||||
assert c.create('t', 'd') == '8'
|
|
||||||
assert 't' not in c._closed_matches
|
|
||||||
|
|
||||||
|
|
||||||
class TestTicketClientOpenTickets:
|
class TestTicketClientOpenTickets:
|
||||||
|
|||||||
Reference in new issue
Block a user