Commit c76dff8
[OPIK-7402] [BE] Add audit (shadow / log-only) mode to UUIDv7 ingestion validation (#7573)
* [OPIK-7402] [BE] Add audit (shadow / log-only) mode to UUIDv7 ingestion validation
Adds a third `auditOnly` state to uuidValidation on top of the `enabled`
kill-switch. When enabled=true and auditOnly=true, out-of-window UUIDv7 ids
are counted and logged but NOT rejected, so clients emitting them surface in
real time without breaking ingestion. Effective mode:
enabled=false -> disabled; enabled=true & auditOnly=true -> audit;
enabled=true & auditOnly=false -> reject (HTTP 400, unchanged).
- New UuidValidationMetrics records opik.ingestion.uuid_v7.rejected in audit
mode, tagged mode=audit + reason + resource + workspace_id (shares the
instrument with InvalidUUIDExceptionMapper's reject-path counter).
- Validator gains resource/workspaceId params; audit branch emits + logs
instead of throwing. Scope is the window check; the always-on NOT_V7
version check is unchanged.
- workspaceId is read from the reactive context on the async paths and
threaded through the batch bind on the sync path.
- Unit test covers disabled/reject/audit.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* [OPIK-7402] [BE] Tag the reject path with mode=reject on the shared counter
Address review: InvalidUUIDExceptionMapper recorded opik.ingestion.uuid_v7.rejected
without a mode label, so the shared counter had series with and without mode and a
`mode=reject` query would miss enforced rejections. Add mode=reject on the reject
path (workspace_id stays audit-only, as the mapper has no threaded workspace), and
align the UuidValidationMetrics contract javadoc: mode is always present; workspace_id
is audit-only; the reject path additionally carries http_route.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* [OPIK-7402] [BE] Address review: async test coverage, log prefix, trimmed javadoc
- Add IdGeneratorAsyncValidationTest covering validateIdAsync /
validateIdForUpdateAsync reject+audit behavior, with and without
RequestContext.WORKSPACE_ID in the reactive context (the deferContextual
workspace lookup + UNKNOWN fallback).
- Keep a fixed, searchable prefix on the audit log line and move the variable
fields to the end.
- Trim the IdGenerator#validateId javadoc to validation semantics +
InvalidUUIDException; keep workspaceId threading (the sync/batch path is the
primary ingestion route where per-workspace attribution is the goal).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* [OPIK-7402] [BE] Reconcile audit mode with merged OPIK-7352 foreign-id validation
Resolve the semantic overlap after merging main (#7553): unify IdGenerator on
the merged API — implement validateIdNotInFuture / validateIdNotInFutureAsync
(and the IfPresent variants) and drop the superseded validateIdForUpdate*.
Own-id validateId stays workspace-tagged for the audit metric; referenced-id
validateIdNotInFuture falls back to UNKNOWN on the sync path and resolves the
workspace from the reactive context on the async path.
Keep #7553's fail-fast (validate before side effects) for span batches, now run
inside deferContextual so the batch's own ids attribute to the request workspace;
bindSpanToProjectAndId no longer re-validates. Trace batches keep validating in
bindTraceToProjectAndId with the workspace threaded through.
Update the async test to the renamed methods.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* [OPIK-7402] [BE] Make trace batch validation symmetric with spans
bindTraceToProjectAndId validated own ids only after deleteAutoStrippedAttachments
and project getOrCreate, so a bad trace id in a batch still mutated state before
failing (unlike spans, which #7553 validates fail-fast). Hoist trace own-id
validation into a leading deferContextual that runs before any side effect and
attributes the audit metric to the request workspace, and stop re-validating in
bindTraceToProjectAndId — mirroring create(SpanBatch).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* [OPIK-7402] [BE] Address review: centralize counter, simplify async, tidy nits
- Centralize the opik.ingestion.uuid_v7.rejected counter and its label constants
in UuidValidationMetrics; InvalidUUIDExceptionMapper now injects it and delegates
via recordReject(reason, httpRoute), dropping its duplicate counter/constants.
- Drop the redundant nested Mono.fromCallable inside deferContextual on the async
validation paths (validate has no blocking work and there is no subscribeOn, so
it ran on the subscribing thread either way; deferContextual already maps a thrown
exception to onError).
- Let resource fall back to unknown like workspaceId (relax @nonnull); the metric
recorder defaults blank values.
- Test: make the id generators static final and rename to constant case.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* [OPIK-7402] [BE] Review: centralize IdGenerator + workspace overloads; factor metric assembly
- IdGenerator: single core validateIdNotInFuture(id, resource, workspaceId); the
2-arg form and the async form delegate to it (no more duplicated version+window
logic), and a workspace-parameterized overload is offered for callers that carry
the request workspace. Same for validateIdNotInFutureIfPresent. The many
config-entity callers keep the 2-arg form, defaulting to unknown by choice.
- UuidValidationMetrics: factor the shared counter/mode/reason assembly into a
private record(...) helper; recordAudit/recordReject only supply their
path-specific tags.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 1d6f99b commit c76dff8
12 files changed
Lines changed: 487 additions & 60 deletions
File tree
- apps/opik-backend
- src
- main/java/com/comet/opik
- api/error
- domain
- infrastructure
- db
- metrics
- test
- java/com/comet/opik
- domain
- infrastructure/db
- resources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
148 | 155 | | |
149 | 156 | | |
150 | 157 | | |
| |||
Lines changed: 7 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | 5 | | |
9 | 6 | | |
10 | 7 | | |
| |||
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
24 | | - | |
25 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
36 | 34 | | |
37 | 35 | | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 36 | | |
| 37 | + | |
47 | 38 | | |
48 | 39 | | |
49 | 40 | | |
50 | 41 | | |
51 | 42 | | |
52 | 43 | | |
53 | | - | |
54 | | - | |
| 44 | + | |
55 | 45 | | |
56 | 46 | | |
57 | 47 | | |
| |||
Lines changed: 49 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | | - | |
29 | | - | |
30 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | | - | |
| 36 | + | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| |||
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
| |||
54 | 65 | | |
55 | 66 | | |
56 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
57 | 71 | | |
58 | 72 | | |
59 | 73 | | |
| |||
93 | 107 | | |
94 | 108 | | |
95 | 109 | | |
96 | | - | |
| 110 | + | |
97 | 111 | | |
98 | | - | |
| 112 | + | |
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
102 | 116 | | |
103 | | - | |
104 | | - | |
105 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
106 | 120 | | |
107 | 121 | | |
108 | 122 | | |
109 | 123 | | |
110 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
111 | 131 | | |
112 | | - | |
| 132 | + | |
113 | 133 | | |
114 | 134 | | |
115 | 135 | | |
116 | 136 | | |
117 | | - | |
118 | | - | |
119 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
120 | 140 | | |
121 | 141 | | |
122 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
123 | 152 | | |
124 | 153 | | |
125 | 154 | | |
126 | 155 | | |
127 | 156 | | |
128 | 157 | | |
129 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
130 | 166 | | |
131 | 167 | | |
132 | 168 | | |
| |||
Lines changed: 14 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | 396 | | |
406 | 397 | | |
407 | 398 | | |
| |||
419 | 410 | | |
420 | 411 | | |
421 | 412 | | |
422 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
423 | 426 | | |
424 | 427 | | |
425 | 428 | | |
| |||
500 | 503 | | |
501 | 504 | | |
502 | 505 | | |
| 506 | + | |
503 | 507 | | |
504 | | - | |
505 | | - | |
506 | 508 | | |
507 | 509 | | |
508 | 510 | | |
| |||
Lines changed: 13 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
195 | 206 | | |
196 | 207 | | |
197 | 208 | | |
| |||
251 | 262 | | |
252 | 263 | | |
253 | 264 | | |
| 265 | + | |
254 | 266 | | |
255 | | - | |
256 | 267 | | |
257 | 268 | | |
258 | 269 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
20 | 27 | | |
| 28 | + | |
21 | 29 | | |
22 | 30 | | |
0 commit comments