Skip to content

feat(common): abstract service-discovery topology in serviceDiscovery.envFlat - #1746

Closed
guimoreirar wants to merge 1 commit into
mainfrom
feat/lerian-common-sd-topology
Closed

feat(common): abstract service-discovery topology in serviceDiscovery.envFlat#1746
guimoreirar wants to merge 1 commit into
mainfrom
feat/lerian-common-sd-topology

Conversation

@guimoreirar

Copy link
Copy Markdown
Member

Evolves lerian-common.serviceDiscovery.envFlat to abstract the lib-service-discovery topology, so every productized chart gets a consistent SD contract instead of hand-wiring 17 raw SD_* keys.

What changed

New OPTIONAL topology inputs → derived defaults:

Input Derives
serviceName + namespace SD_INTERNAL_ADDRESS = <serviceName>.<namespace>.svc.cluster.local
servicePort SD_INTERNAL_PORT
ingressHost SD_EXTERNAL_ADDRESS

Platform-standard baked defaults: SD_PREFER_VIEW=internal, SD_INTERNAL_SCHEME=http, SD_EXTERNAL_PORT=443, SD_TLS_SKIP_VERIFY=true, SD_TLS=false (Consul SD_ADDRESS stays localhost:8500, SD_ENABLED=false).

Precedence unchanged: configmap.SD_<KEY> (legacy, WINS) > caller/grouped param (defaults) > derived/opinionated default > "".

Verified (scratch render)

  • Topology inputs → SD_INTERNAL_ADDRESS: "ledger.midaz-ns.svc.cluster.local", SD_INTERNAL_PORT: "3000", SD_EXTERNAL_ADDRESS: "ledger.stg.lerian.net", SD_EXTERNAL_PORT: "443", SD_PREFER_VIEW: "internal", SD_TLS_SKIP_VERIFY: "true".
  • configmap.SD_INTERNAL_ADDRESS override → wins over derived.
  • grouped defaults → wins over derived, loses to configmap.
  • No topology inputs → addresses "" (graceful), scalar defaults applied.
  • strict: 0 violations.

Backward-safe: the helper landed in #1742 and has no merged consumer yet, so evolving its defaults is safe. Consumers (midaz, then fees/access-manager/...) pass serviceName/namespace/servicePort/ingressHost to opt in.

Scope: only _service_discovery.tpl + README.md.

….envFlat

Evolve the helper to derive the SD external/internal endpoints from
chart topology and bake the platform-standard defaults, so every
productized chart gets a consistent lib-service-discovery contract:

- new optional inputs serviceName/namespace/servicePort/ingressHost:
    SD_INTERNAL_ADDRESS = <serviceName>.<namespace>.svc.cluster.local
    SD_INTERNAL_PORT    = servicePort
    SD_EXTERNAL_ADDRESS = ingressHost
- platform defaults: SD_PREFER_VIEW=internal, SD_INTERNAL_SCHEME=http,
  SD_EXTERNAL_PORT=443, SD_TLS_SKIP_VERIFY=true, SD_TLS=false.
- precedence unchanged: configmap.SD_* (legacy) > caller/grouped param >
  derived/opinionated default > "".

Backward-safe: callers without topology inputs still render (addresses
default ""). No merged consumer yet (helper landed in #1742).
@guimoreirar
guimoreirar requested a review from a team as a code owner July 24, 2026 21:11
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Service discovery environment generation

Layer / File(s) Summary
Helper contract and default precedence
charts/lerian-common/README.md, charts/lerian-common/templates/_service_discovery.tpl
Documents topology inputs, derived SD_* values, opinionated defaults, and per-key precedence.
Topology derivation and environment rendering
charts/lerian-common/templates/_service_discovery.tpl
Derives internal/external addresses and internal port, updates standard defaults, and renders the selected keys through lerian-common.env.flatBlock.

Sequence Diagram(s)

sequenceDiagram
  participant TopologyInputs
  participant serviceDiscoveryEnvFlat
  participant envFlatBlock
  TopologyInputs->>serviceDiscoveryEnvFlat: Provide optional topology inputs
  serviceDiscoveryEnvFlat->>serviceDiscoveryEnvFlat: Derive SD_* values and apply defaults
  serviceDiscoveryEnvFlat->>envFlatBlock: Pass resolved values and ordered keys
  envFlatBlock-->>serviceDiscoveryEnvFlat: Render KEY: value entries
Loading

Possibly related PRs

  • LerianStudio/helm#1741: Midaz templates call the same helper to emit Service Discovery environment variables.
  • LerianStudio/helm#1742: Updates the same helper and README contract with related SD_* derivation and precedence changes.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/lerian-common-sd-topology

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@charts/lerian-common/README.md`:
- Around line 22-30: The generic flat-passthrough description should exclude
serviceDiscovery.envFlat because that helper derives topology values and applies
platform defaults. Update the description to apply only to the truly flat
helpers, while preserving the documented precedence and derivation behavior for
serviceDiscovery.envFlat.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8c36a9c4-2216-4548-ba0c-3c65565718d1

📥 Commits

Reviewing files that changed from the base of the PR and between 947fa64 and 38102d4.

📒 Files selected for processing (2)
  • charts/lerian-common/README.md
  • charts/lerian-common/templates/_service_discovery.tpl

Comment on lines +22 to +30
`serviceDiscovery.envFlat` additionally accepts OPTIONAL topology inputs
(`serviceName`, `namespace`, `servicePort`, `ingressHost`) that DERIVE
`SD_INTERNAL_ADDRESS` (`<serviceName>.<namespace>.svc.cluster.local`, only when both
given), `SD_INTERNAL_PORT` (`servicePort | toString`) and `SD_EXTERNAL_ADDRESS`
(`ingressHost`); each stays `""` when its inputs are absent. It also bakes the
opinionated platform defaults `SD_PREFER_VIEW="internal"`, `SD_TLS_SKIP_VERIFY="true"`,
`SD_EXTERNAL_PORT="443"`, `SD_INTERNAL_SCHEME="http"` unconditionally. All of these are
lowest precedence — per key: `configmap.SD_<KEY>` (legacy) > `defaults.SD_<KEY>`
(grouped param) > derived/opinionated default > `""`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Narrow the no-derivation claim to exclude serviceDiscovery.envFlat.

The preceding flat-passthrough description still says that serviceDiscovery.envFlat reproduces native blocks byte-for-byte with no derivation, while this section documents topology-derived values and baked defaults. Update the generic description to apply only to the truly flat helpers.

🤖 Prompt for 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.

In `@charts/lerian-common/README.md` around lines 22 - 30, The generic
flat-passthrough description should exclude serviceDiscovery.envFlat because
that helper derives topology values and applies platform defaults. Update the
description to apply only to the truly flat helpers, while preserving the
documented precedence and derivation behavior for serviceDiscovery.envFlat.

@guimoreirar

Copy link
Copy Markdown
Member Author

Redundante — o serviceDiscovery.env (derivação de topologia: internal DNS + external https:// + inerte quando global.serviceDiscovery não setado) já está na main via #1742 (lerian-common 1.1.0). O envFlat-topology deste PR é superseded por ele. O wiring do midaz vai consumir o serviceDiscovery.env da main.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant