Skip to content

fix(reporter): handle binary metadata in v4 message logs#15779

Open
ErwinSupp wants to merge 56 commits into4.11.xfrom
issue/11220-fix-freemarker-binary-metadata
Open

fix(reporter): handle binary metadata in v4 message logs#15779
ErwinSupp wants to merge 56 commits into4.11.xfrom
issue/11220-fix-freemarker-binary-metadata

Conversation

@ErwinSupp
Copy link
Copy Markdown

@ErwinSupp ErwinSupp commented Mar 18, 2026

Issue

gravitee-io/issues#11220

Description

This PR fixes a FreeMarker template error in v4-message-log.ftl that occurred when processing binary metadata (e.g., from Kafka).

The issue was that byte[] metadata values were being treated as sequences by FreeMarker, causing the ?j_string and ?string built-ins to fail with UnexpectedTypeException.

Changes:

  • Updated v4-message-log.ftl in es7x, es8x, and es9x reporter configurations.
  • Refined the metadata iteration logic to first filter printable metadata (non-sequence values) into a temporary map, then render it using <#sep>. This approach is cleaner and more maintainable than manual comma handling.
  • Ensured metadata values are rendered as strings for backward compatibility.

Additional context

Refined Implementation

<#assign printable_metadata = {}>
<#list log.getMessage().getMetadata() as metadataKey, metadataValue>
    <#if metadataValue?? && !metadataValue?is_sequence>
        <#assign printable_metadata = printable_metadata + {metadataKey: metadataValue}>
    </#if>
</#list>
<#list printable_metadata as metadataKey, metadataValue>
  "${metadataKey}": "${metadataValue?string?j_string}"<#sep>,</#sep>
</#list>

All 99 tests in gravitee-apim-reporter-common passed.

phiz71 and others added 30 commits March 13, 2026 09:55
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

chore: make sed commands portable across macOS and Linux [skip ci]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

chore: improve auth comments to explain why, not what [skip ci]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

chore: use ALPHA_VERSION variable in helm push command [skip ci]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

chore: use ALPHA_VERSION variable in cloud-apim Chart.yaml [skip ci]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

chore: use awk to safely clear artifacthub changes block [skip ci]

Replace sed commands that could corrupt Chart.yaml if
artifacthub.io/changes is not the last section in the file.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

chore: split sed and rm cleanup onto separate lines [skip ci]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the external CDN script for Redoc with a locally bundled
copy served from assets. This is more secure, works in closed-circuit
environments, and does not require nginx CSP changes.

Made-with: Cursor
Okhelifi and others added 18 commits March 16, 2026 16:42
handle migration of tags, replacing the use of `id` with the `key` field and generating new UUIDs for tag IDs.
(cherry picked from commit 2f5b4b1)
Change the `v` column type from nvarchar(1000) to nclob to support
larger property values. nclob is suitable here since dictionary
property values are not indexed.

https://gravitee.atlassian.net/browse/APIM-12355
(cherry picked from commit 7220404)

# Conflicts:
#	gravitee-apim-repository/gravitee-apim-repository-jdbc/src/main/resources/liquibase/master.yml
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical FreeMarker template error that previously caused UnexpectedTypeException when the reporter processed binary metadata, such as byte[] from Kafka. By introducing robust conditional logic within the v4-message-log.ftl templates, the system now gracefully handles various metadata types, ensuring message logs are generated correctly without data loss or processing failures.

Highlights

  • FreeMarker Template Fix: Resolved an UnexpectedTypeException in v4-message-log.ftl that occurred when processing binary metadata, such as byte[] values.
  • Robust Metadata Handling: Implemented conditional logic to safely process various metadata types within the FreeMarker template, preventing errors.
  • Type-Specific Formatting: Ensured strings are JSON escaped, numbers and booleans are rendered as strings for backward compatibility, and sequences (including byte[]) are safely skipped.
  • Template Updates: Applied the necessary changes to v4-message-log.ftl across the es7x, es8x, and es9x reporter configurations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a FreeMarker template error that occurs when processing binary metadata by adding logic to skip sequence types like byte[]. The fix is applied consistently across all relevant Elasticsearch reporter configurations. I've added one suggestion to refactor the template logic for improved readability and maintainability, which applies to all three modified files.

Comment on lines 53 to 58
<#assign first = true>
<#list log.getMessage().getMetadata() as metadataKey, metadataValue>
"${metadataKey}": "${metadataValue?j_string}"
<#sep>,</#sep>
<#if metadataValue?? && !metadataValue?is_sequence>
<#if !first>,</#if>"${metadataKey}": "${metadataValue?string?j_string}"<#assign first = false>
</#if>
</#list>
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.

medium

While the current implementation with manual comma handling is correct, it can be simplified and made more readable by separating the filtering of metadata from the rendering. You could first build a new map containing only the printable metadata, and then iterate over that new map using <#sep> for cleaner comma separation. This approach is generally less error-prone and easier to maintain.

This comment also applies to the identical changes in es8x/index/v4-message-log.ftl and es9x/index/v4-message-log.ftl.

    <#assign printable_metadata = {}>
    <#list log.getMessage().getMetadata() as metadataKey, metadataValue>
        <#if metadataValue?? && !metadataValue?is_sequence>
            <#assign printable_metadata = printable_metadata + {metadataKey: metadataValue}>
        </#if>
    </#list>
    <#list printable_metadata as metadataKey, metadataValue>
      "${metadataKey}": "${metadataValue?string?j_string}"<#sep>,</#sep>
    </#list>

@ErwinSupp ErwinSupp closed this Mar 18, 2026
@ErwinSupp ErwinSupp reopened this Mar 18, 2026
@ErwinSupp ErwinSupp marked this pull request as ready for review March 18, 2026 11:57
@ErwinSupp ErwinSupp requested a review from a team as a code owner March 18, 2026 11:57
@sonarqubecloud
Copy link
Copy Markdown

@ErwinSupp ErwinSupp changed the base branch from master to 4.11.x March 18, 2026 12:33
@ErwinSupp ErwinSupp requested a review from a team as a code owner March 18, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.