Skip to content

fix: env var decoding for bool config fields, redis sentinel multi-node support and change fs.FS path construction - #4545

Open
vsengar-79 wants to merge 6 commits into
openmeterio:mainfrom
vsengar-79:main
Open

vsengar-79 wants to merge 6 commits into
openmeterio:mainfrom
vsengar-79:main

Conversation

@vsengar-79

@vsengar-79 vsengar-79 commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Four small fixes for running OpenMeter in Kubernetes where config values arrive as environment variable strings rather than typed YAML values.

  1. app/config/viper.go — bool env var decoding

Added StringToBasicTypeHookFunc() to the global DecodeHook. When config values are set via env vars or ConfigMaps, they are always strings — "true", "false", "1". Without this hook, any bool config field panics on startup with:

expected type 'bool', got unconvertible type 'string', value: 'false'

This affects fields like DEDUPE_ENABLED, NOTIFICATION_ENABLED, and any other boolean config sourced from the environment.

  1. app/config/sink.go — consumer group ID key name typo

sink.kafka.consumerGroupId → sink.kafka.consumerGroupID (capital ID to match the struct field's mapstructure tag). Fixed a little typo.

  1. pkg/redis/client.go — Redis Sentinel multi-node support

The Address field now supports a comma-separated list of sentinel nodes (e.g. "sentinel1:26379,sentinel2:26379,sentinel3:26379"). Previously it was hardcoded to []string{o.Address}, which only ever used a single sentinel endpoint regardless of what was configured.

  1. tools/migrate/fs.go — use path.Join instead of filepath.Join for fs.FS path construction

filepath.Join uses the OS path separator (\ on Windows), which breaks fs.FS implementations that require forward-slash paths per the io/fs spec. Replace with path.Join which always uses /

Notes for reviewer

  • StringToBasicTypeHookFunc only activates when the target struct field is a basic type (bool, int, float64) — it has no effect on string fields or interface{} maps. Existing YAML-based configs are unaffected since YAML already deserialises native types correctly.
  • The sentinel change is backward compatible — strings.Split on a non-comma string returns a single-element slice, identical to the previous []string{o.Address} behaviour.
  • The consumer group typo fix has no migration concern — the field was silently broken before, so no existing deployment relied on the wrong default being applied.
  • The path package (always forward-slash) is used instead of filepath (OS-dependent separator) because fs.FS requires forward-slash paths on all platforms per the io/fs spec; the function parameter was renamed from path to dir to avoid shadowing the import.

Summary by CodeRabbit

  • New Features

    • Redis Sentinel configuration now supports multiple node addresses in a comma-separated list.
  • Improvements

    • Configuration processing now converts string values to basic data types automatically.
    • Migration tooling uses consistent slash-based path handling across environments.
  • Bug Fixes

    • Corrected the default Kafka sink consumer group setting so it applies to the intended configuration key.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no outstanding findings remain.

Summary

The PR converts string configuration values to basic types, corrects the Kafka consumer-group default key, supports multiple Redis Sentinel addresses, and uses slash-separated migration filesystem paths.

Reviews (5) · Last reviewed commit: "Improve sentinel address parsing in Redi..."

@vsengar-79
vsengar-79 requested a review from a team as a code owner June 21, 2026 11:26
@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 076cf942-21c1-460a-80cc-35c79b24747b

📥 Commits

Reviewing files that changed from the base of the PR and between f0ad76d and b325e2d.

📒 Files selected for processing (4)
  • app/config/sink.go
  • app/config/viper.go
  • pkg/redis/client.go
  • tools/migrate/fs.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • app/config/viper.go
  • tools/migrate/fs.go
  • app/config/sink.go
  • pkg/redis/client.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Four small fixes update a sink Kafka configuration key, extend decode-hook conversions, support multiple Redis Sentinel addresses, and use slash-based paths in migrate filesystem handling.

Changes

Misc Fixes

Layer / File(s) Summary
Viper key casing fix + decode hook
app/config/sink.go, app/config/viper.go
Changes the sink Kafka consumer group key to consumerGroupID and adds mapstructure.StringToBasicTypeHookFunc() to the DecodeHook chain.
Redis Sentinel multi-address support
pkg/redis/client.go
Splits o.Address on commas, trims whitespace, removes empty entries, validates the result, and passes the addresses to redis.FailoverOptions.SentinelAddrs.
Migrate fs cross-platform path fix
tools/migrate/fs.go
Replaces path/filepath with path, uses path.Join, and renames the ReadDir parameter from path to dir.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to b325e

This change corrects configuration decoding and keys, adds Redis Sentinel address parsing, and uses slash-based filesystem paths. No concrete merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: environment-variable decoding, Redis Sentinel multi-node support, and fs.FS path construction. It is specific and related to the changeset, although it d…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/redis/client.go`:
- Around line 61-68: The code splits and trims sentinel addresses but does not
filter out empty strings that can result from trailing, leading, or double
commas in the address string. After trimming each address in the sentinelAddrs
loop, filter out any entries that are empty strings. Additionally, add
validation after the loop to ensure the final sentinelAddrs slice is not empty,
and fail fast with an appropriate error message if no valid sentinel addresses
remain after filtering.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 28f3a5df-20d6-455d-bc7f-ff317c165a1e

📥 Commits

Reviewing files that changed from the base of the PR and between 5176487 and 658ad9d.

📒 Files selected for processing (4)
  • app/config/sink.go
  • app/config/viper.go
  • pkg/redis/client.go
  • tools/migrate/fs.go

Comment thread pkg/redis/client.go Resolved
@greptile-apps

greptile-apps Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Four small but meaningful bug-fixes for Kubernetes deployments where config arrives as env var strings. Covers bool coercion during viper decode, a Kafka consumer group ID key typo, Redis Sentinel multi-node address support, and cross-platform fs.FS path construction.

  • app/config/viper.go: Adds StringToBasicTypeHookFunc() to the decode hook chain so string values from env vars/ConfigMaps are automatically coerced to bool, int, and float64 target fields — preventing startup panics on fields like DEDUPE_ENABLED.
  • app/config/sink.go: Fixes the viper default key consumerGroupId → consumerGroupID to match the ConsumerGroupID struct field tag used throughout the rest of the Kafka config.
  • pkg/redis/client.go: Parses the Address string as a comma-separated list of sentinel nodes, filters empty entries, and returns a clear error if no valid addresses remain — all backward-compatible with the prior single-address behaviour.
  • tools/migrate/fs.go: Swaps filepath.Join (OS separator) for path.Join (always /) when building fs.FS paths, fixing a Windows breakage mandated by the io/fs spec.

Confidence Score: 5/5

All four changes are targeted, backward-compatible bug fixes with no new logic paths that could regress existing behaviour.

Each change is narrowly scoped: a one-line hook addition, a key-name typo fix, an address-parsing loop with an explicit guard, and an import swap. No new abstractions, no schema changes, and the sentinel parsing is explicitly backward-compatible with single-address strings.

No files require special attention.

Important Files Changed

Filename Overview
app/config/viper.go Appends StringToBasicTypeHookFunc() to the decode hook chain so string env vars are coerced to bool/int/float64 target types without panicking on startup.
app/config/sink.go Corrects the viper default key from consumerGroupId to consumerGroupID, matching the ConsumerGroupID struct field and the key used in ConfigureKafkaConfiguration.
pkg/redis/client.go Adds comma-separated sentinel address parsing with empty-entry filtering and an explicit error when no valid addresses are found; backward-compatible with single-address configs.
tools/migrate/fs.go Replaces filepath.Join with path.Join for fs.FS path construction, fixing Windows incompatibility per the io/fs spec requirement for forward-slash-only paths.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Env var / ConfigMap string] --> B{DecodeHook chain}
    B --> C[MapDecoderHookFunc]
    C --> D[TextUnmarshallerHookFunc]
    D --> E[StringToTimeDurationHookFunc]
    E --> F["StringToSliceHookFunc(',')"]
    F --> G[StringToBasicTypeHookFunc NEW]
    G --> H{Target type?}
    H -->|bool/int/float| I[Coerced native value]
    H -->|string / other| J[Unchanged value]
    I --> K[Struct field populated]
    J --> K

    subgraph Redis Sentinel init
        L[o.Address string] --> M["strings.Split(',')"]
        M --> N[TrimSpace + filter empty]
        N --> O{len == 0?}
        O -->|yes| P[Return error]
        O -->|no| Q[redis.NewFailoverClient with sentinelAddrs]
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Env var / ConfigMap string] --> B{DecodeHook chain}
    B --> C[MapDecoderHookFunc]
    C --> D[TextUnmarshallerHookFunc]
    D --> E[StringToTimeDurationHookFunc]
    E --> F["StringToSliceHookFunc(',')"]
    F --> G[StringToBasicTypeHookFunc NEW]
    G --> H{Target type?}
    H -->|bool/int/float| I[Coerced native value]
    H -->|string / other| J[Unchanged value]
    I --> K[Struct field populated]
    J --> K

    subgraph Redis Sentinel init
        L[o.Address string] --> M["strings.Split(',')"]
        M --> N[TrimSpace + filter empty]
        N --> O{len == 0?}
        O -->|yes| P[Return error]
        O -->|no| Q[redis.NewFailoverClient with sentinelAddrs]
    end
Loading

Reviews (2): Last reviewed commit: "Improve sentinel address parsing in Redi..." | Re-trigger Greptile

Comment thread pkg/redis/client.go Resolved
@vsengar-79 vsengar-79 changed the title fix: env var decoding for bool config fields and redis sentinel multi-node support and change fs.FS path construction fix: env var decoding for bool config fields, redis sentinel multi-node support and change fs.FS path construction Jun 27, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

This pull request has been inactive for 45 days. Push a commit or leave a comment describing the next step to remove the stale label. Maintainers can apply keep-open with a concrete reason when longer-lived work is intentional. This pull request will close automatically after another 15 days without activity.

@github-actions github-actions Bot added the stale Inactive pull request awaiting author or maintainer follow-up label Sep 9, 2026
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@turip turip added area/ingest release-note/bug-fix Release note: Bug Fixes labels Sep 9, 2026
@github-actions github-actions Bot removed the stale Inactive pull request awaiting author or maintainer follow-up label Sep 11, 2026
filepath.Join uses the OS path separator (\ on Windows), which breaks fs.FS implementations that require forward-slash paths per the io/fs spec. Replace with path.Join which always uses /.

Signed-off-by: vsengar-79 <[email protected]>
Refactor sentinel address handling to trim whitespace and validate addresses.

Signed-off-by: vsengar-79 <[email protected]>
@turip

turip commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

@vsengar-79 I love this PR but I think we are doing too much here. I am fine merging both the pkg/redis/client.go — Redis Sentinel multi-node support and the tools/migrate/fs.go — use path.Join instead of filepath.Join for fs.FS path construction

For the other two, I we need to do a deeper assessment of what they are doing in terms of our existing production systems, so that will take some time. If you split this into two PRs I can merge the first.

For example Viper currently treats "" as false, but the new hook calls strconv.ParseBool("") and returns an error first. Literal "false" still parses correctly.

@github-actions

Copy link
Copy Markdown

This pull request has been inactive for 45 days. Push a commit or leave a comment describing the next step to remove the stale label. Maintainers can apply keep-open with a concrete reason when longer-lived work is intentional. This pull request will close automatically after another 15 days without activity.

@github-actions github-actions Bot added the stale Inactive pull request awaiting author or maintainer follow-up label Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ingest release-note/bug-fix Release note: Bug Fixes stale Inactive pull request awaiting author or maintainer follow-up

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants