Skip to content

Introduce StructuredLogKeys constants for SLF4J addKeyValue calls - #5093

Merged
adutra merged 3 commits into
apache:mainfrom
ZephyrYWZhou:structured-log-keys
Jul 30, 2026
Merged

adutra merged 3 commits into
apache:mainfrom
ZephyrYWZhou:structured-log-keys

Conversation

@ZephyrYWZhou

Copy link
Copy Markdown
Contributor

Summary

Centralizes hardcoded log key strings used in addKeyValue() calls into a single StructuredLogKeys constants class in polaris-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

  • Added: polaris-core/src/main/java/org/apache/polaris/core/StructuredLogKeys.java
    • Introduces a centralized constants class containing ~55 structured log key definitions.
    • Constants are grouped by domain (table, view, namespace, credential, task, error, etc.) for easier discovery and maintenance.
  • Updated: 17 files across polaris-core and runtime/service
    • Replaced hardcoded log key strings with StructuredLogKeys.* 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

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
@ZephyrYWZhou

Copy link
Copy Markdown
Contributor Author

@dimas-b would appreciate a review when you get a chance. Thanks!

dimas-b
dimas-b previously approved these changes Jul 27, 2026

@dimas-b dimas-b left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks, @ZephyrYWZhou !

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Jul 27, 2026
@dimas-b

dimas-b commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@ZephyrYWZhou : Please fix conflicts

@ZephyrYWZhou

Copy link
Copy Markdown
Contributor Author

Thanks @dimas-b! Conflicts resolved. Could you re-approve when you get a chance? 🙏

@ZephyrYWZhou
ZephyrYWZhou requested a review from dimas-b July 28, 2026 00:48

@adutra adutra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.addKeyValue(StructuredLogKeys.IDENTIFIER, identifier)
.addKeyValue(StructuredLogKeys.TABLE_IDENTIFIER, identifier)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's right, let's use VIEW_IDENTIFIER 👍

flyrain
flyrain previously approved these changes Jul 28, 2026

@flyrain flyrain left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@ZephyrYWZhou

Copy link
Copy Markdown
Contributor Author

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 StructuredLogKeys import wasn't in alphabetical order). There are no logic changes - this commit only applies Spotless formatting.

Since the new commit dismissed your previous approval, could you please re-approve and trigger the CI? Appreciated!

@ZephyrYWZhou

Copy link
Copy Markdown
Contributor Author

Could you help merge the PR when you have a moment? @flyrain Looks like I don't have the merge permission yet.

@ZephyrYWZhou

Copy link
Copy Markdown
Contributor Author

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.

@adutra
adutra merged commit a94bff0 into apache:main Jul 30, 2026
25 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board Jul 30, 2026
ZephyrYWZhou pushed a commit to ZephyrYWZhou/Apache-Polaris that referenced this pull request Aug 4, 2026
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).
adutra pushed a commit that referenced this pull request Aug 4, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce structured log key constants for SLF4J addKeyValue calls

5 participants