Skip to content

feat: add api-product-id to ES FTL write and mapping templates#16398

Merged
carlos-andres-osorio merged 1 commit intomasterfrom
apim-13546
Apr 15, 2026
Merged

feat: add api-product-id to ES FTL write and mapping templates#16398
carlos-andres-osorio merged 1 commit intomasterfrom
apim-13546

Conversation

@carlos-andres-osorio
Copy link
Copy Markdown
Contributor

@carlos-andres-osorio carlos-andres-osorio commented Apr 14, 2026

Issue

APIM-13546

Why

API Products analytics requires api-product-id to be a first-class dimension in Elasticsearch. The field was added to the Metrics and Log models in gravitee-reporter-api 2.2.0, but without template changes it would never appear in indexed documents and the index mapping would not declare it as a filterable keyword.

What changed

  • FTL write templates (reporter-common) — added a conditional api-product-id block after api-name in v4-metrics.ftl and v4-log.ftl for all three ES variants (es7x, es8x, es9x). The field is emitted only when non-null, using ?j_string for safe JSON escaping.
  • Index mapping templates (reporter-elasticsearch) — declared api-product-id as "type": "keyword" after api-name in both index-template-v4-metrics.ftl and index-template-v4-log.ftl for all four variants (es7x, es8x, es9x, opensearch). No explicit "index": true — consistent with all peer ID fields (plan-id, application-id, subscription-id), which are indexed by default.
  • reporter-api version bumpgravitee-reporter-api bumped from 2.1.0 to 2.2.0 in root pom.xml to make getApiProductId() available at compile and test time.
  • Test fixtures — updated given/ and expected/ JSON fixtures in reporter-common to exercise the new field through ElasticsearchFormatterTest and JsonFormatterTest.

How to test

mvn test -pl gravitee-apim-reporter/gravitee-apim-reporter-common

All 99 tests pass. To verify the field appears in ES documents, send a request through a gateway with an API Product attached and inspect the indexed document — api-product-id should appear after api-name.

For manual testing details, see description in #16394

Gotchas / Follow-up

  • Streaming API templates (v4-message-log.ftl, message metrics) are out of scope for this story.

Why: Propagates the apiProductId field introduced in reporter-api 2.2.0
into the Elasticsearch document write templates and index mapping, so
api-product-id is indexed and filterable in analytics and access logs.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@sonarqubecloud
Copy link
Copy Markdown

@carlos-andres-osorio carlos-andres-osorio marked this pull request as ready for review April 14, 2026 20:34
@carlos-andres-osorio carlos-andres-osorio requested a review from a team as a code owner April 14, 2026 20:34
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@carlos-andres-osorio carlos-andres-osorio merged commit eca7eab into master Apr 15, 2026
48 checks passed
@carlos-andres-osorio carlos-andres-osorio deleted the apim-13546 branch April 15, 2026 13:18
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.

2 participants