Repository navigation
Introduce StructuredLogKeys constants for SLF4J addKeyValue calls - #5093
Conversation
Centralize hardcoded log key strings used in addKeyValue() calls into a single StructuredLogKeys constants class. This prevents typos, enables IDE autocomplete and find-all-references, and provides a single source of truth for structured log key names used in search and alerting. Replaces ~100 hardcoded string literals across 17 files with references to constants in StructuredLogKeys. The 4 remaining dynamic expression-based keys (e.g., 'entity.getTableIdentifier()') are left as-is since they represent variable names rather than stable log keys. Fixes apache#5033
|
@dimas-b would appreciate a review when you get a chance. Thanks! |
dimas-b
left a comment
There was a problem hiding this comment.
LGTM 👍 Thanks, @ZephyrYWZhou !
|
@ZephyrYWZhou : Please fix conflicts |
|
Thanks @dimas-b! Conflicts resolved. Could you re-approve when you get a chance? 🙏 |
adutra
left a comment
There was a problem hiding this comment.
Thanks @ZephyrYWZhou for this change.
I confess I'm +0 on this kind of refactoring. Certain keys are indeed common and factorizing them to a common constant is useful, e.g. TABLE_IDENTIFIER.
But other keys are only used in one place, e.g. EFFECTIVE_BATCH_SIZE. In this case, the indirection is imho rather useless.
| .atError() | ||
| .addKeyValue("entity.getTableIdentifier()", entity.getTableIdentifier()) | ||
| .addKeyValue("identifier", identifier) | ||
| .addKeyValue(StructuredLogKeys.IDENTIFIER, identifier) |
There was a problem hiding this comment.
| .addKeyValue(StructuredLogKeys.IDENTIFIER, identifier) | |
| .addKeyValue(StructuredLogKeys.TABLE_IDENTIFIER, identifier) |
There was a problem hiding this comment.
Thanks @adutra. Good catch - IDENTIFIER is too generic here.
One nuance is that this call site is on the view path: it resolves ICEBERG_VIEW, and the log message is "Stored view identifier mismatches requested identifier". The matching table path a few hundred lines above already uses TABLE_IDENTIFIER with ICEBERG_TABLE, and just below this line the same method tags the value as EventAttributes.VIEW_IDENTIFIER.
So I think VIEW_IDENTIFIER is the more semantically correct constant here rather than TABLE_IDENTIFIER. I'm happy to switch it - does that sound good to you? I've left it as IDENTIFIER for now pending your thoughts.
There was a problem hiding this comment.
Hmm that's right, let's use VIEW_IDENTIFIER 👍
flyrain
left a comment
There was a problem hiding this comment.
Thanks @ZephyrYWZhou for the PR. LGTM overall. Just a minor concern: We introduced a convention here, not an enforced contract, nothing stops the next addKeyValue("newKey", ...) from bypassing it, so the "single source of truth" only holds if reviewers keep enforcing it. The PR is still net positive by eliminating any key inconsistency. +1.
Apply spotlessApply to fix import-ordering violations introduced when adding the StructuredLogKeys import. The import was placed after the org.slf4j.* imports instead of alphabetically among org.apache.polaris.core.*, causing :polaris-core:spotlessJavaCheck and :polaris-runtime-service:spotlessJavaCheck to fail in CI. Also wraps two .addKeyValue(...) calls that exceeded the 100-char line limit. No behavioral changes.
|
Thanks @flyrain! I pushed a follow-up commit to fix the Spotless import-ordering violations that were causing the Gradle Build Checks to fail (the new Since the new commit dismissed your previous approval, could you please re-approve and trigger the CI? Appreciated! |
|
Could you help merge the PR when you have a moment? @flyrain Looks like I don't have the merge permission yet. |
|
Or if @dimas-b or @nandorKollar could help merge this green CR? I'd really appreciate it. I don't have permission to merge it myself. |
This PR moved the last call site of StructuredLogKeys.IDENTIFIER to VIEW_IDENTIFIER, leaving IDENTIFIER with zero references. apache#5093 built StructuredLogKeys by extracting keys actually in use, so remove the now-orphaned generic constant to stay consistent (per review from @flyrain / @adutra).
…5093) (#5224) Follow-up to #5093. The view-path call site in LocalIcebergCatalog.doRefresh() (PolarisEntitySubType.ICEBERG_VIEW, "Stored view identifier mismatches requested identifier") used the generic StructuredLogKeys.IDENTIFIER. Per review discussion on #5093, switch it to the more semantically correct StructuredLogKeys.VIEW_IDENTIFIER, consistent with the matching table path (TABLE_IDENTIFIER) and the EventAttributes.VIEW_IDENTIFIER tag used just below. No behavior change beyond the emitted structured-log key name (identifier -> viewIdentifier). This PR moved the last call site of StructuredLogKeys.IDENTIFIER to VIEW_IDENTIFIER, leaving IDENTIFIER with zero references. #5093 built StructuredLogKeys by extracting keys actually in use, so remove the now-orphaned generic constant to stay consistent (per review from @flyrain / @adutra). --------- Co-authored-by: Yuewei Zhou <[email protected]>
Summary
Centralizes hardcoded log key strings used in
addKeyValue()calls into a singleStructuredLogKeysconstants class inpolaris-core.Fixes #5033.
Problem
Around 100
addKeyValue()calls across the codebase use hardcoded string literals for structured log key names (for example,"tableIdentifier"and"metadataLocation"). This makes typos difficult to catch, prevents IDE autocomplete and find-all-references, and leaves no single source of truth for log keys used in search, dashboards, and alerting.Changes
polaris-core/src/main/java/org/apache/polaris/core/StructuredLogKeys.javapolaris-coreandruntime/serviceStructuredLogKeys.*constants.Four expression-based keys (for example,
entity.getTableIdentifier()) are intentionally left unchanged because they represent dynamically generated field names rather than stable structured log keys.Testing
No behavioral changes. This is a refactoring only. Compilation succeeds, and the generated structured log output is identical before and after the change.
Checklist
StructuredLogKeys