Validate category/subcategory length matches varchar(63) DB constraint#4867
Conversation
Signed-off-by: Dejan Zele Pejchev <pejcev.dejan@gmail.com>
Greptile SummaryThis PR adds config-load-time length guards to Confidence Score: 5/5Safe to merge; only finding is a minor byte-vs-rune precision note with no practical impact on ASCII category names. All remaining findings are P2 style suggestions. The validation logic is correct and conservative — len() (bytes) can never pass a string that would violate the DB constraint, so no data-integrity risk exists. Tests are thorough and cover every new code path. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[NewClassifier called] --> B{len DefaultCategory > 63?}
B -- yes --> ERR1[return error]
B -- no --> C{len DefaultSubcategory > 63?}
C -- yes --> ERR2[return error]
C -- no --> D[iterate Categories]
D --> E{cfg.Name empty?}
E -- yes --> ERR3[return error]
E -- no --> F{len cfg.Name > 63?}
F -- yes --> ERR4[return error]
F -- no --> G{duplicate name?}
G -- yes --> ERR5[return error]
G -- no --> H[buildRule for each rule]
H --> I{len cfg.Subcategory > 63?}
I -- yes --> ERR6[return error]
I -- no --> J[compile regex / validate matchers]
J --> K[Classifier constructed successfully]
Reviews (1): Last reviewed commit: "Validate category/subcategory length mat..." | Re-trigger Greptile |
What type of PR is this?
bug-fix / follow-up
What this PR does / why we need it
Follow-up to #4863. PR #4863 added
failure_category varchar(63)andfailure_subcategory varchar(63)columns tojob_run(migration 032), butNewClassifieraccepted arbitrarily long values from config. An operator setting a category name longer than 63 chars would only discover the problem at the first failed pod, when the lookout ingester's batch UPDATE hitvalue too long for type character varying(63)and stalled the batch.This PR adds length guards at config-load time so the executor refuses to start with bad config rather than silently failing hours later. New constant
maxCategoryNameLen = 63documents the link to migration 032.NewClassifiervalidatesDefaultCategory,DefaultSubcategory, everycfg.Name, and every rule'sSubcategory.Which issue(s) this PR fixes
Fixes #
Special notes for your reviewer
Addresses a review follow-up on #4863. A second follow-up from that review (handling rejected jobs for categorization purposes) is intentionally out of scope here - it's a design discussion rather than a mechanical change and belongs in a separate issue/PR.