Skip to content

feat: support env vars in heartbeat - #8064

Merged
v0y4g3r merged 6 commits into
GreptimeTeam:mainfrom
v0y4g3r:feat/env-in-heartbeat
May 8, 2026
Merged

feat: support env vars in heartbeat#8064
v0y4g3r merged 6 commits into
GreptimeTeam:mainfrom
v0y4g3r:feat/env-in-heartbeat

Conversation

@v0y4g3r

@v0y4g3r v0y4g3r commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add heartbeat_env_vars config for datanode, frontend, and standalone, including env-list parsing from environment overrides.
  • Report configured environment variable values through heartbeat extensions and store them in metasrv NodeInfo.
  • Add compatibility and config-loader coverage for env var reporting behavior.

Test Plan

  • cargo test -p cmd --test load_config_test test_load_heartbeat_env_vars_from_env

Add `heartbeat_env_vars` config option for datanode and frontend. When
configured, the specified environment variable values are read at startup
and sent to metasrv in every heartbeat via the `extensions` map. Metasrv
extracts and stores them in `NodeInfo` for use in routing decisions
(e.g. AZ-aware region placement).

- Add `EnvVars` helper in `common/meta/src/datanode.rs` following the
  existing `GcStat` extension pattern with `into_extensions`/`from_extensions`
- Add `env_vars: HashMap<String, String>` field to `NodeInfo` in
  `common/meta/src/cluster.rs` with `#[serde(default)]` for backward compat
- Add `heartbeat_env_vars: Vec<String>` config field to `DatanodeOptions`,
  `FrontendOptions`, and `StandaloneOptions`
- Inject env vars into heartbeat `extensions` in both datanode and frontend
  heartbeat tasks (`datanode/src/heartbeat.rs`, `frontend/src/heartbeat.rs`)
- Extract env vars from `req.extensions` in all three metasrv
  `CollectXxxClusterInfoHandler`s
- Update `NodeInfo` construction sites in `meta-client`,
  `discovery/lease.rs`, and `standalone/information_extension.rs`
- Update expected TOML output in `tests-integration/tests/http.rs`
- Add unit tests for `EnvVars` round-trip and `NodeInfo` backward compat

Signed-off-by: Lei, HUANG <leih@nvidia.com>
Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
@github-actions github-actions Bot added size/S docs-not-required This change does not impact docs. labels May 5, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a mechanism for nodes to report specific environment variables to the meta service via heartbeat messages. Key changes include the addition of a heartbeat_env_vars configuration option, the EnvVars utility struct for managing these variables, and updates to the NodeInfo structure and heartbeat handlers to process and store the reported data. Feedback suggests refactoring duplicated extraction logic in the cluster info handlers into a shared helper function and optimizing the Datanode heartbeat loop by pre-serializing the static environment variables to avoid redundant JSON serialization on every iteration.

Comment thread src/meta-srv/src/handler/collect_cluster_info_handler.rs Outdated
Comment thread src/datanode/src/heartbeat.rs Outdated
Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
@v0y4g3r
v0y4g3r marked this pull request as ready for review May 6, 2026 02:40
@v0y4g3r
v0y4g3r requested a review from MichaelScofield as a code owner May 6, 2026 02:40
Copilot AI review requested due to automatic review settings May 6, 2026 02:40
@v0y4g3r
v0y4g3r requested review from a team and WenyXu as code owners May 6, 2026 02:40

Copilot AI 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.

Pull request overview

Adds support for configuring heartbeat-reported environment variables across node options, serializing them in heartbeat extensions, and persisting them into metasrv NodeInfo. This fits into the existing cluster-info/heartbeat pipeline by extending node metadata without breaking older serialized NodeInfo records.

Changes:

  • Added heartbeat_env_vars config to datanode, frontend, and standalone options, including env-list parsing from environment overrides.
  • Added EnvVars heartbeat-extension encoding/decoding and persisted reported values into metasrv NodeInfo.
  • Added backward-compatibility/default-field updates plus config-loader and serialization tests.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests-integration/tests/http.rs Updates integration test config fixture with the new standalone option.
src/standalone/src/options.rs Adds standalone config field and forwards it into derived frontend/datanode options.
src/standalone/src/information_extension.rs Extends standalone NodeInfo construction with the new env_vars field.
src/meta-srv/src/handler/collect_cluster_info_handler.rs Extracts env vars from heartbeat extensions and stores them in cluster NodeInfo.
src/meta-srv/src/discovery/lease.rs Adjusts tests for the expanded NodeInfo struct.
src/meta-client/src/client/util.rs Adjusts test helper/default NodeInfo construction.
src/meta-client/src/client.rs Fills default env_vars for metasrv node conversions.
src/frontend/src/heartbeat.rs Reads configured env vars and includes them in frontend heartbeat extensions.
src/frontend/src/frontend.rs Adds frontend config field and env-list parsing support.
src/datanode/src/heartbeat.rs Reads configured env vars and includes them in datanode heartbeat extensions.
src/datanode/src/config.rs Adds datanode config field and env-list parsing support.
src/common/meta/src/datanode.rs Introduces EnvVars extension type plus serialization tests.
src/common/meta/src/cluster.rs Adds persisted env_vars to NodeInfo with backward-compatibility tests.
src/cmd/tests/load_config_test.rs Adds config-loader coverage for heartbeat_env_vars from environment variables.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/standalone/src/information_extension.rs
Comment thread src/meta-srv/src/handler/collect_cluster_info_handler.rs
Comment thread src/meta-srv/src/handler/collect_cluster_info_handler.rs
Comment thread src/common/meta/src/datanode.rs
Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
@v0y4g3r

v0y4g3r commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@MichaelScofield

Copy link
Copy Markdown
Collaborator

Why does Metasrv require these env vars, or why do Datanodes and Frontends need to submit them to the Metasrv?

Comment thread src/frontend/src/heartbeat.rs
Comment thread src/datanode/src/heartbeat.rs
@v0y4g3r

v0y4g3r commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Why does Metasrv require these env vars, or why do Datanodes and Frontends need to submit them to the Metasrv?

We will implement a affinity allocator for regions that selects datanodes according to their env vars, like availability zone.

Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
@v0y4g3r
v0y4g3r force-pushed the feat/env-in-heartbeat branch from 38a7283 to d8e87e7 Compare May 7, 2026 06:19
@v0y4g3r

v0y4g3r commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

Comment thread src/datanode/src/heartbeat.rs Outdated
Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
Comment thread src/meta-srv/src/handler/collect_cluster_info_handler.rs
Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
@evenyag
evenyag added this pull request to the merge queue May 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 8, 2026
@v0y4g3r
v0y4g3r added this pull request to the merge queue May 8, 2026
Merged via the queue into GreptimeTeam:main with commit 42aa58a May 8, 2026
88 of 89 checks passed
@v0y4g3r
v0y4g3r deleted the feat/env-in-heartbeat branch May 8, 2026 08:14
@v0y4g3r
v0y4g3r restored the feat/env-in-heartbeat branch May 8, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants