Ticket contract for automated reporters: dedup_key, source, links, reopen window (#123)
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 44s
Lint / PHP requirements (version + extensions) (push) Successful in 42s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m15s
Lint / JS (eslint) (pull_request) Successful in 34s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 42s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (push) Successful in 4m13s
Security / PHP Security (semgrep) (pull_request) Successful in 3m25s
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 44s
Lint / PHP requirements (version + extensions) (push) Successful in 42s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m15s
Lint / JS (eslint) (pull_request) Successful in 34s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 42s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (push) Successful in 4m13s
Security / PHP Security (semgrep) (pull_request) Successful in 3m25s
From the thor#1 plan: each reporter (gandalf, hwmonDaemon, thor) decides
what "the same problem" is, and Tinker enforces it.
- dedup_key on create_ticket_api.php (scope:subject:kind, A-Za-z0-9_.:-,
case-sensitive). The hash becomes sha256("key:" + key) and the title is
not looked at; an invalid key is a 400. Keyless callers hash exactly as
before (checked over every prod title).
- Recurrence window for every reporter, keyed or not: a match on a ticket
closed under AUTO_REOPEN_WINDOW_DAYS (7) ago reopens it as before
(subject to the Workflow Designer); an older one gets a new ticket that
takes over the dedup slot (tickets.hash stays UNIQUE, the old ticket
gives it up), carries the key, records recurrence_of, is linked
relates_to, and gets a history comment. action: new_recurrence.
- GET api/tickets_api.php?dedup_key= returns the newest ticket with that
key plus its recurrence chain; ?source= filters the list.
- New api/ticket_link_api.php (link/unlink, read_write) through
DependencyService::link()/unlink(), now shared with MCP
link_tickets/unlink_tickets; audit rows record the key name.
- tickets.source records the API key name. Shown as the creator instead of
"System" on the dashboard and ticket page, a Source filter in the
sidebar, source in MCP results and a search_tickets filter. Comments the
create API writes name the reporter instead of a hard-coded
"hwmonDaemon", and system-linked comments display that name.
- Migration 008 (dedup_key, source, recurrence_of). Scripts:
backfill_ticket_source.php (pre-#123 tickets, where certain) and
backfill_dedup_keys.php (mapping file supplied by the app).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13ffc51cb7
commit
7061c40d4d
20 files changed
+1025
-206
No files matched your search
+37
-3
@@ -4,8 +4,9 @@
|
||||
* Dedup hash for tickets created through create_ticket_api.php.
|
||||
*
|
||||
* Two reports with the same hash land on the same ticket (updated while open,
|
||||
* reopened when closed), so the components below decide what counts as "the
|
||||
* same problem". Changing them re-keys existing tickets: see
|
||||
* reopened or followed by a linked new ticket when closed). A reporter can
|
||||
* send an explicit dedup_key and decide that itself (#123); otherwise the
|
||||
* components below decide what counts as "the same problem". Changing them re-keys existing tickets: see
|
||||
* scripts/rehash_network_tickets.php for how #116 handled that.
|
||||
*/
|
||||
class TicketHash
|
||||
@@ -178,9 +179,42 @@ class TicketHash
|
||||
return $stableComponents;
|
||||
}
|
||||
|
||||
/** SHA-256 dedup hash of the payload's stable components. */
|
||||
/**
|
||||
* Format of a reporter-supplied dedup_key: scope:subject:kind, e.g.
|
||||
* host:compute-storage-01:oom or cluster:ceph:BLUESTORE_SLOW_OP_ALERT.
|
||||
* Upper case is allowed for codes like Ceph's; keys are case-sensitive.
|
||||
*/
|
||||
public const KEY_PATTERN = '/^[A-Za-z0-9_.:-]{1,128}$/';
|
||||
|
||||
public static function isValidKey($key): bool
|
||||
{
|
||||
return is_string($key) && preg_match(self::KEY_PATTERN, $key) === 1;
|
||||
}
|
||||
|
||||
/** The request's dedup_key, or null when it sent none. Validate with isValidKey() first. */
|
||||
public static function key(array $data): ?string
|
||||
{
|
||||
$key = $data['dedup_key'] ?? null;
|
||||
return ($key === null || $key === '') ? null : (string)$key;
|
||||
}
|
||||
|
||||
/** Dedup hash for an explicit key. The "key:" prefix keeps it apart from every legacy hash. */
|
||||
public static function forKey(string $key): string
|
||||
{
|
||||
return hash('sha256', 'key:' . $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dedup hash for a create request. With a dedup_key the reporter decides
|
||||
* what "the same problem" is and the title is not looked at (#123);
|
||||
* without one, the stable components of the title decide, as before.
|
||||
*/
|
||||
public static function generate(array $data): string
|
||||
{
|
||||
$key = self::key($data);
|
||||
if ($key !== null) {
|
||||
return self::forKey($key);
|
||||
}
|
||||
return hash('sha256', json_encode(self::components($data), JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user