Skip to content

fix(grok): apply the type converter declared in %{SYNTAX:semantic:type} - #116

Merged
jymaire merged 1 commit into
mainfrom
fix/108-grok-type-converters
Sep 1, 2026
Merged

fix(grok): apply the type converter declared in %{SYNTAX:semantic:type}#116
jymaire merged 1 commit into
mainfrom
fix/108-grok-type-converters

Conversation

@jymaire

@jymaire jymaire commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closes #108

Problem

%{NUMBER:n:int} returned the string "7" instead of the number 7, and the same applied to :float, :boolean and every other converter. %{NUMBER:n} gave an identical result, so the suffix had no effect at all.

Root cause

GrokMatcher indexed the compiled patterns by their syntax (NUMBER), but looked them up by the name of the regex capture group — which GrokPatternCompiler#compileRegex sets to the semantic (n) whenever one is defined. The lookup therefore missed for every named capture, pattern was null, and the type silently fell back to STRING.

Fix

Index the patterns by the capture-group name they actually produce (semantic when present, otherwise syntax).

Two follow-ons the fix exposed:

  • Empty captures are left unconverted. An unmatched optional group is captured as ""; running it through the converter turned it into a Jackson-coerced null, changing what keepEmptyCaptures: true returns. It now stays "", exactly as for untyped groups.
  • Conversion failures are reported properly. A value that cannot be converted (e.g. %{WORD:w:int} on kestra) now throws a GrokException naming the field and the target type, instead of surfacing a bare Jackson error.

Tests

5 new tests in GrokMatcherTest and 2 in TransformValueTest — all fail before the fix, except the untyped control:

  • the issue's exact case: %{NUMBER:n:int} on "7"7
  • all converters at once (short / int / long / float / double / boolean, plus an untyped field)
  • untyped %{NUMBER:n} still returns "7"
  • an unconvertible value throws GrokException
  • an empty optional typed capture stays ""

Full build green: 164 tests, 0 failures (1 pre-existing skip).

🤖 Generated with Claude Code

…pe}` (#108)

`GrokMatcher` indexed the compiled patterns by their *syntax*, but looked
them up by the name of the regex capture group, which is the *semantic*
whenever one is defined. The lookup therefore always missed for named
captures and the type silently fell back to `STRING`, so
`%{NUMBER:n:int}` returned `"7"` instead of `7`.

Index the patterns by the capture-group name they actually produce.

Also:
- leave empty captures (unmatched optional groups) unconverted, so they
  keep behaving as before with `keepEmptyCaptures`;
- report a conversion failure as a `GrokException` naming the field and
  the target type instead of a bare Jackson error.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jymaire jymaire self-assigned this Sep 1, 2026
@kestrabot kestrabot Bot added this to Pull Requests Sep 1, 2026
@github-project-automation github-project-automation Bot moved this to To review in Pull Requests Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

📦 Artifacts

Name Size Updated Expiration
jar 2.97 MB Sep 1, 26, 12:06:44 PM UTC Sep 8, 26, 12:06:43 PM UTC

🛡 Trivy

Vulnerability in: Java

Vulnerability Severity Package Installed Version Fixed Version
GHSA-r7wm-3cxj-wff9 HIGH com.fasterxml.jackson.core:jackson-core 2.21.1 2.18.8, 2.21.4
GHSA-r7wm-3cxj-wff9 HIGH com.fasterxml.jackson.core:jackson-core 2.21.1 2.18.8, 2.21.4
GHSA-r7wm-3cxj-wff9 HIGH com.fasterxml.jackson.core:jackson-core 2.21.1 2.18.8, 2.21.4
CVE-2026-54512 HIGH com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 3.1.4, 2.21.4
CVE-2026-54512 HIGH com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 3.1.4, 2.21.4
CVE-2026-54512 HIGH com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 3.1.4, 2.21.4
CVE-2026-54513 HIGH com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4, 3.1.4
CVE-2026-54513 HIGH com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4, 3.1.4
CVE-2026-54513 HIGH com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4, 3.1.4
CVE-2026-54514 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4, 3.1.4
CVE-2026-54514 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4, 3.1.4
CVE-2026-54514 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4, 3.1.4
CVE-2026-54515 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 3.1.4, 2.18.9, 2.21.5, 2.22.1
CVE-2026-54515 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 3.1.4, 2.18.9, 2.21.5, 2.22.1
CVE-2026-54515 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 3.1.4, 2.18.9, 2.21.5, 2.22.1
CVE-2026-54516 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4, 3.1.4
CVE-2026-54516 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4, 3.1.4
CVE-2026-54516 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4, 3.1.4
CVE-2026-54517 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4, 3.1.4
CVE-2026-54517 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4, 3.1.4
CVE-2026-54517 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4, 3.1.4
CVE-2026-54518 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4
CVE-2026-54518 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4
CVE-2026-54518 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.4
CVE-2026-59888 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4
CVE-2026-59888 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4
CVE-2026-59888 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.8, 2.21.4
CVE-2026-59889 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.5, 2.18.9, 2.22.1
CVE-2026-59889 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.5, 2.18.9, 2.22.1
CVE-2026-59889 MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.21.5, 2.18.9, 2.22.1
GHSA-mhm7-754m-9p8w MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.9, 2.21.5
GHSA-mhm7-754m-9p8w MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.9, 2.21.5
GHSA-mhm7-754m-9p8w MEDIUM com.fasterxml.jackson.core:jackson-databind 2.21.1 2.18.9, 2.21.5

🧪 Java Unit Tests

TestsPassed ✅Skipped ⚠️FailedTime ⏱
Java Tests Report164 ran163 ✅1 ⚠️0 ❌54s 74ms

🔁 Unreleased Commits

✅ No unreleased commits found.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Tests report quick summary:

success ✅ > tests: 164, success: 163, skipped: 1, failed: 0

unfold for details
Project Status Success Skipped Failed
plugin-transform-grok success ✅ 29 0 0
plugin-transform-json success ✅ 27 0 0
plugin-transform-records success ✅ 107 1 0

@jymaire
jymaire requested review from a team and Malaydewangan09 September 1, 2026 12:08
@jymaire
jymaire merged commit b9e91ec into main Sep 1, 2026
8 checks passed
@jymaire
jymaire deleted the fix/108-grok-type-converters branch September 1, 2026 13:00
@github-project-automation github-project-automation Bot moved this from To review to Done in Pull Requests Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bash2.0] grok type converters are ignored, %{NUMBER:n:int} returns a string

2 participants