Skip to content

feat(audit): audit page queries CU-17tkuw62pj3 - #3298

Merged
kanashenko merged 4 commits into
mainfrom
audit-page-queries
Dec 4, 2026
Merged

kanashenko merged 4 commits into
mainfrom
audit-page-queries

Conversation

@kanashenko

@kanashenko kanashenko commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Change-Set: audit-page-queries

Change set flamingo-stack/openframe-oss-lib#3298: these pull requests are one change, reviewed together.

Linked work

  • …and 1 linked item not shown here

Linked by the Depends-On / Change-Set lines in these descriptions; this block is maintained by the hub.

@kanashenko kanashenko added the build Run the PR builds and publish snapshots (Java, npm preview); stays on until removed label Dec 1, 2026
@flamingo

flamingo Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

🦩 flamingo Code Review

11 findings: 🔴 1 action required · 🟠 0 recommended · 🔵 10 informational

Advisory: findings do not block the merge.

Rules cited: OFJAVA-002, OFJAVA-004, OPENFRAM-001-6, OFJAVA-005 · 1 defect outside any rule

Files Lines 🔴 Action required 🟠 Recommended 🔵 Informational
55 +2886 / -491 1 0 10

🔴 Action required (1)

# Where Finding Flagged by
1 AuditEventViewMapper.java:42 AuditEventViewMapper.labelOfTargetType NPEs for events that carry no targetType Review

🔵 Informational (10)

# Where Finding Flagged by
2 AuditEventQueryService.java:60 countChildren passes two method calls directly as arguments to countChildren (Minor) OFJAVA-002
3 PinotClientAuditEventRepository.java:211 projectionMapper holds a 36-line inline lambda body (Minor) OFJAVA-004
4 PinotClientAuditEventRepository.java:150 filtered() passes getter results and countPerValueQuery passes filtered(filter) as arguments (Minor) OFJAVA-002
5 PinotQueryBuilder.java:273 isEqual/isIn nest quoted(value.strip()) and listOf(values) inside formatted(...) (Minor) OFJAVA-002
6 AuditEventProjection.java:9 New Pinot audit data carriers use @‍Value/@‍Builder instead of the required Lombok quad (Minor) OPENFRAM-001-6
7 AuditEventQueryFilterFactory.java:32 create() nests searchableFrom() and criteria.getSearch().strip() inside argument lists (Minor) OFJAVA-002
8 AuditEventQueryService.java:54 getEvent/countChildren nest tenantIdProvider.getTenantId() and filterFactory.searchableFrom() inside repository calls (Minor) OFJAVA-002
9 AuditEventDataFetcher.java:153 logView builds the audit details map with getters called inside put() arguments (Minor) OFJAVA-002
10 PinotClientAuditEventRepository.java:215 Column names used as inline string literals alongside the declared column constants (Minor) OFJAVA-005
11 AuditEventFilterInput.java:10 AuditEventFilterInput carries only @‍Data, missing @‍Builder/@‍NoArgsConstructor/@‍AllArgsConstructor (Minor) OPENFRAM-001-6

✅ What this change does well

  • AuditEventQueryFilterFactory clamps the requested occurredFrom to a stated 92-day searchable window, so every Pinot read in AuditEventQueryService carries a time bound, and AuditEventQueryFilterFactoryTest covers the boundary millisecond on both sides.
  • AuditEventFacetServiceTest verifies with verifyNoMoreInteractions that only the requested facet is queried and that each facet drops its own predicate, which pins the facet-counting semantics.
  • AuditEventCursorsTest exercises wrong sort field, wrong direction, null value and a bare ObjectId cursor, covering every refusal branch of AuditEventCursors.parse.
  • CustomMachineRepositoryImplTest adds a regression test proving the new findMachineIdsByName escapes regex metacharacters and stays tenant-scoped.
  • AuditTargetType centralises human-readable labels on the enum itself with an immutable LABELS map and a labelOf fallback, keeping one source for display names.

Inline comments: 11 new

18 possible problems checked and ruled out, 4 after reading more of the repository
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotQueryBuilder.java:224 whereNotIn builds invalid SQL (or NPEs) for a null/empty value list, unlike whereIn: whereNotIn (line 224-227) passes values to listOf without the CollectionUtils.isEmpty guard its sibling whereIn has; null NPEs and empty yields 'NOT IN ()'. Real but not reachable from current callers.
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotQueryBuilder.java:234 whereAny produces () when given an empty condition list: whereAny (line 234) with an empty list yields '()' which where() accepts (PinotQueryBuilder.java:136-141 only rejects blank); real but no current call site can pass empty.
  • openframe-audit/src/main/java/com/openframe/audit/AuditContext.java:24 AuditContext.withoutParent() is added with no caller and silently clears rootEventId: AuditContext.java:24-26 adds withoutParent() with no caller in the repo per the finder's search; dropping both parent and root is semantically coherent (no parent implies no chain root), so this is at most dead-API noise in a shared library.
  • openframe-api-lib/src/main/java/com/openframe/api/service/AuditEventQueryService.java:41 findEvents never passes the backward flag to the Pinot query, so last/before pagination returns the wrong page: audit-event.graphqls exposes only first/after (lines 5-10) and CursorPaginationCriteria.fromRest hard-codes backward=false (line 69), so no caller ever sets backward=true for this service: the mismatch is latent and not reachable today.
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotClientAuditEventRepository.java:118 countChildren/countFailedInChains scan the whole tenant window when the id list is empty: whereIn no-ops on an empty list, but the only callers are GraphQL DataLoaders which never batch an empty key set, and the cited rule OFJAVA-038 is about Mongo reads/in-memory grouping, not Pinot id lists; a hypothetical empty-list call is not worth a comment.
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotClientAuditEventRepository.java:213 projectionMapper NPEs on a missing occurredAt column instead of degrading like every other field: The occurredAt unboxing only NPEs if the Pinot schema lacks the column; the string helpers' tolerance is a defensive nicety, and the finder itself rates it 45, a hypothetical robustness wish, not a verified defect.
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotClientAuditEventRepository.java:167 Search filter NPEs on a search object whose text is null, and nests a call in the argument list: AuditEventQueryFilterFactory.create only builds AuditEventSearch when hasText(criteria.getSearch()) and passes strip()ed text (lines 35,47-49), so getText() is never null/blank; the remaining PMD nesting point duplicates the already-confirmed finding on filtered() at line 150.
  • openframe-api-service-core/src/main/java/com/openframe/api/mapper/GraphQLAuditEventMapper.java:28 GraphQLAuditEventMapper injects RelayIdCodec via @‍Autowired field: GraphQLAuditEventMapper.java:28-29 is an abstract MapStruct @‍Mapper, not a @‍Service/@‍Component/@‍DgsComponent class; field @‍Autowired is the standard MapStruct idiom for an abstract mapper (constructor injection is not available to the generated subclass), so the cited rule does not cover this kind of class and the point is not worth a comment.
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/AbstractPinotRepository.java:129 New readNullableString helper returns null for Pinot's "null" string: AbstractPinotRepository.java:26-27 and 118-119 document that PINOT_NULL is the sentinel for an absent column and that degrading one field to null is the intended behaviour; readNullableString (129-134) implements exactly that documented contract, so the null-never-returned rule is stretched to a low-level ResultSet reader.
  • openframe-api-lib/src/main/java/com/openframe/api/service/AuditEventQueryService.java:26 Tenant-scoped audit services gated only on the Pinot table property: The rule targets custom repository implementations extending TenantAwareRepositorySupport and tenant-data services; these are Pinot query services gated on the Pinot table property, and the rule's quoted scope does not clearly name them, a stretched citation.
  • openframe-api-service-core/src/main/java/com/openframe/api/mapper/GraphQLAuditEventMapper.java:69 toIdsOfAnyType returns null for a null input list: GraphQLAuditEventMapper.java:71 returns null for a null input list, which is deliberate MapStruct null-propagation (a null filter field must stay unset, not become an empty IN list); the cited rule targets service methods promising a real object, not mapper null-passthrough.
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/model/AuditEventQueryFilter.java:9 AuditEventQueryFilter uses @‍Value @‍Builder instead of the required Lombok quad: duplicate of candidate 4
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/model/AuditEventSearch.java:8 AuditEventSearch uses @‍Value @‍Builder instead of the required Lombok quad: duplicate of candidate 4
  • openframe-api-lib/src/main/java/com/openframe/api/service/AuditEventFacetService.java:53 AuditEventFacetService hand-writes its constructor instead of using @‍RequiredArgsConstructor: AuditEventFacetService.java:53-62 writes an explicit constructor because a parameter needs @‍Qualifier; the rule forbids @‍Autowired field injection and manual loggers, not an explicit constructor, and the fields are private final.
  • openframe-api-lib/src/main/java/com/openframe/api/service/AuditEventFacetService.java:86 Multi-line thenApply lambda assembles AuditEventFilters inline: AuditEventFacetService.java:86-94 is a single-expression builder lambda, not a multi-statement block body; purely stylistic reformatting request.
  • openframe-api-service-core/src/main/java/com/openframe/api/datafetcher/AuditEventDataFetcher.java:137 device() hardcodes the "machineDataLoader" loader name instead of a constant: An earlier review already posted the "machineDataLoader" literal vs NAME constants finding on AuditEventDataFetcher under OFJAVA-005.
  • openframe-api-service-core/src/main/java/com/openframe/api/datafetcher/AuditEventDataFetcher.java:141 filterCriteria passes Objects.requireNonNullElseGet(...) directly as an argument: Already posted: "filterCriteria passes Objects.requireNonNullElseGet(...) as an argument" under OFJAVA-002 at lines 132-134/141-143.
  • openframe-api-lib/src/main/java/com/openframe/api/dto/audit/AuditEventSummary.java:10 379 new or changed definitions have no test referencing them: Bulk 'no test references' list spanning 379 definitions, mostly DTO fields, enum constants and framework data fetchers, while the PR adds several test files; not actionable.
🤖 Prompt for AI agents: fix every finding
Address these code-review findings on pull request #3298 of flamingo-stack/openframe-oss-lib, most important first.
For each one, make the minimal change that resolves it and do not refactor unrelated code.
If you can show a finding is wrong, skip it and say why.

1. [Action required] openframe-api-lib/src/main/java/com/openframe/api/mapper/AuditEventViewMapper.java:42 AuditEventViewMapper.labelOfTargetType NPEs for events that carry no targetType
   `labelOfTargetType` forwards the projection value straight to `AuditTargetType.labelOf`, whose LABELS map is built with `Collectors.toUnmodifiableMap` (openframe-data-mongo-common/.../AuditTargetType.java:71-78). `getOrDefault(null, null)` on a `Map.ofEntries`-backed immutable map throws NPE (`ImmutableCollections.MapN.get` hashes the key). The projection's targetType is genuinely nullable: `PinotClientAuditEventRepository.projectionMapper` builds it with `readNullableString`, which maps Pinot's "null" sentinel to Java null (AbstractPinotRepository.java:129-134), and several actions legitimately have no target type (AuditAction.java:202 SCRIPT_OUTPUT_VIEW, 359-361 KB_ITEM_MOVE/LINK_CREATE with `null` targetType). MapStruct invokes a qualifiedByName method unconditionally, so a single such row in a page makes `toSummary`/`toDetails` throw and the whole audit list/detail query fails. The same hazard applies to `labelOfAction` if action is ever absent from the Pinot schema (readNullableString also returns null when the column is missing).
2. [Informational] openframe-api-lib/src/main/java/com/openframe/api/service/AuditEventQueryService.java:60 countChildren passes two method calls directly as arguments to countChildren
   OFJAVA-002 forbids calling a method inside another call's argument list; `tenantIdProvider.getTenantId()` and `filterFactory.searchableFrom()` are both invoked inside the `auditEventRepository.countChildren(...)` argument list. This is the PMD priority-1 NoMethodCallAsArgument rule, which fails the build. The same pattern appears at lines 55 and 65-66 of this file.
3. [Informational] openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotClientAuditEventRepository.java:211 projectionMapper holds a 36-line inline lambda body
   OFJAVA-004 requires lambdas to fit on one line and multi-line bodies to be extracted into named methods. The lambda returned by projectionMapper spans lines 211-246 and contains a nested lambda plus the entire row-to-projection mapping, so stack traces from a mapping failure name no method.
4. [Informational] openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotClientAuditEventRepository.java:150 filtered() passes getter results and countPerValueQuery passes filtered(filter) as arguments
   OFJAVA-002 (CI-enforced by PMD NoMethodCallAsArgument) forbids calling a method inside another call's argument list. In filtered() the shownToTenant(...) call takes three getter calls as arguments and the chained whereIn calls each take a getter call; the same pattern appears at line 118 (countEventsBy passes column.getColumnName() and filtered(filter)) and lines 213/225 (columnIndexes.get(OCCURRED_AT), valuesOf(text.apply(...))). Each needs a named local first.
5. [Informational] openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotQueryBuilder.java:273 isEqual/isIn nest quoted(value.strip()) and listOf(values) inside formatted(...)
   OFJAVA-002 forbids a method call in another call's argument list. The new static condition builders pass quoted(value.strip()) and listOf(values) directly as arguments to String.formatted, which is exactly the shape PMD's NoMethodCallAsArgument (priority 1) fails the build on.
6. [Informational] openframe-data-pinot/src/main/java/com/openframe/data/pinot/model/AuditEventProjection.java:9 New Pinot audit data carriers use @Value/@Builder instead of the required Lombok quad
   AuditEventProjection (and the sibling new carriers AuditEventQueryFilter and AuditEventSearch in the same package) are data-carrier classes annotated only with @Value and @Builder. OPENFRAM-001-6 requires @Data @Builder @NoArgsConstructor @AllArgsConstructor on every document, DTO and model class; @Value yields an immutable class with no no-args constructor and no setters, which breaks Jackson deserialization and the accessor/mutator shape every other model in the repository (e.g. AuditEvent in openframe-data-mongo-common, lines 15-19) follows.
7. [Informational] openframe-api-lib/src/main/java/com/openframe/api/service/AuditEventQueryFilterFactory.java:32 create() nests searchableFrom() and criteria.getSearch().strip() inside argument lists
   `latestOf(criteria.getOccurredFrom(), searchableFrom())` and `searchOf(tenantId, criteria.getSearch().strip())` call methods inside another call's argument list, which OFJAVA-002 forbids and which the priority-1 PMD rule NoMethodCallAsArgument fails the build on. `criteria.getSearch()` is also evaluated twice on the same line.
8. [Informational] openframe-api-lib/src/main/java/com/openframe/api/service/AuditEventQueryService.java:54 getEvent/countChildren nest tenantIdProvider.getTenantId() and filterFactory.searchableFrom() inside repository calls
   Each repository call in AuditEventQueryService passes the results of `tenantIdProvider.getTenantId()` and `filterFactory.searchableFrom()` directly as arguments, which OFJAVA-002 forbids (CI-enforced by PMD NoMethodCallAsArgument, priority 1). The same pattern repeats in countChildren (line 61) and findChainsWithFailures (lines 65-66), and `AuditEventCursors.encode(events.getFirst())` on lines 48-49.
9. [Informational] openframe-api-service-core/src/main/java/com/openframe/api/datafetcher/AuditEventDataFetcher.java:153 logView builds the audit details map with getters called inside put() arguments
   Every `details.put(...)` call in `logView` passes a `criteria.getX()` call as an argument, which is exactly what the CI-enforced PMD rule NoMethodCallAsArgument rejects (logger calls are the only exemption). The same pattern repeats a dozen times in one method.
10. [Informational] openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotClientAuditEventRepository.java:215 Column names used as inline string literals alongside the declared column constants
   OFJAVA-005 requires meaningful literals to be named constants. This class declares constants for most Pinot columns (ID, ACTION, TARGET_NAME...) but the same file still types "schemaVersion", "reason", "actorRoles", "onBehalfOfId", "approverId", "originTool", "sourceIp", "userAgent", "sessionId", "tenantId", "details", "changes" inline both in LIST_COLUMNS/DETAIL_COLUMNS (lines 55-60) and again in projectionMapper, so each column name has two or three unsearchable change points.
11. [Informational] openframe-api-service-core/src/main/java/com/openframe/api/dto/audit/AuditEventFilterInput.java:10 AuditEventFilterInput carries only @Data, missing @Builder/@NoArgsConstructor/@AllArgsConstructor
   OPENFRAM-001-6 requires every DTO/model data carrier to carry the full Lombok quad (@Data @Builder @NoArgsConstructor @AllArgsConstructor). This new input DTO declares only @Data. (OPENFRAM-003-3 tolerates @Data-only inputs for non-@Document classes, so the two rules disagree; flagging under the stricter one.)

Next: commit a suggestion, or hand a comment's prompt to your coding agent. React 👍 on a finding that helped and 👎 on one that is wrong: the reviewer learns from both.

Review again. New commits are not reviewed until you ask:

  • Review the new commits: only what was pushed since this review
  • Review the whole diff again: everything, including what was already reviewed

Or comment @flamingo-review (new commits) or @flamingo-review full (everything). Add the flamingo-review-always label to review every push.

Updated 2026-12-04 15:53 UTC · reviewed from Nick Kanashenko's machine

@kanashenko kanashenko added build Run the PR builds and publish snapshots (Java, npm preview); stays on until removed and removed build Run the PR builds and publish snapshots (Java, npm preview); stays on until removed labels Dec 2, 2026
@kanashenko
kanashenko marked this pull request as draft December 4, 2026 11:07
# Conflicts:
#	openframe-data-mongo-common/src/main/java/com/openframe/data/document/audit/AuditAction.java
@kanashenko
kanashenko marked this pull request as ready for review December 4, 2026 15:47
@flamingo

flamingo Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

🦩 flamingo Code Review / security

✅ No findings on the current head.

Advisory: findings do not block the merge.

Files Lines 🔴 Action required 🟠 Recommended 🔵 Informational
55 +2886 / -491 0 0 0

✅ What this change does well

  • AuditEventDataFetcherTest in openframe-api-service-core/src/test/java/com/openframe/api/datafetcher/AuditEventDataFetcherTest.java verifies that audit views are only stored for whole-log queries and not for paginated or filtered single-record lookups, reducing noise in the audit trail.
  • GraphQLAuditEventMapperTest in openframe-api-service-core/src/test/java/com/openframe/api/mapper/GraphQLAuditEventMapperTest.java checks that relay ids of the wrong node type are rejected with InvalidRelayIdException, guarding against type-confused id input.
  • AuditContext in openframe-audit/src/main/java/com/openframe/audit/AuditContext.java threads a rootEventId alongside parentEventId using firstNonNull, preserving audit lineage correctly across nested calls.
  • CustomMachineRepositoryImpl.findMachineIdsByName applies Pattern.quote to the user-supplied name before building the Mongo regex criteria, preventing regex injection, and the new test explicitly verifies special characters like "pc (1).*" are matched literally.
  • PinotQueryBuilderConditionsTest.java adds parameterized tests exercising quote-escaping and injection-shaped input ("x' OR tenantId != 'y") against PinotQueryBuilder.isEqual, verifying the single-quote doubling defense stays in place.
1 possible problem checked and ruled out
  • openframe-data-pinot/src/main/java/com/openframe/data/pinot/repository/PinotQueryBuilder.java:273 whereAny() joins caller-built SQL condition strings with no escaping of its own: This duplicates the already-posted comment on PinotQueryBuilder.java:273-279 about isEqual/isIn (and by extension isNull) formatting field names unescaped into SQL via formatted(). The posted comment already covers quoted(value.strip()) and listOf(values) being nested inside formatted() for isEqual/isIn at the same lines. This candidate raises the same root issue (field name interpolated…

Review again. New commits are not reviewed until you ask:

  • Security-check the new commits: only what was pushed since this security review
  • Security-check the whole diff again: everything, including what was already checked

Or comment @flamingo-review security (new commits) or @flamingo-review security full (everything). Add the flamingo-security-review-always label to security-review every push.

Started 2026-12-04 16:03 UTC · updated 2026-12-04 16:05 UTC · workflow run

@kanashenko
kanashenko enabled auto-merge December 4, 2026 15:56
@kanashenko

Copy link
Copy Markdown
Contributor Author

@flamingo-review security

@kanashenko
kanashenko added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit 2b4bd84 Dec 4, 2026
47 checks passed
@kanashenko
kanashenko deleted the audit-page-queries branch December 4, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Run the PR builds and publish snapshots (Java, npm preview); stays on until removed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants