Skip to content

agents: add nsolid-version and add it to metadata - #460

Merged
santigimeno merged 4 commits into
node-v24.x-nsolid-v6.xfrom
santi/nsolidversion
May 25, 2026
Merged

agents: add nsolid-version and add it to metadata#460
santigimeno merged 4 commits into
node-v24.x-nsolid-v6.xfrom
santi/nsolidversion

Conversation

@santigimeno

@santigimeno santigimeno commented Apr 29, 2026

Copy link
Copy Markdown
Member

Also, cache the metadata so it's not generated multiple times per different rpc's.
Finally, resolve having both nsolid-saas and nsolid-saas-token header name and settle for the first.

Summary by CodeRabbit

  • Refactor

    • Unified gRPC metadata: build, cache, and attach a single metadata collection across streams/clients (replaces per-call agent/saas parameters).
  • Tests

    • Updated helpers/tests to validate propagated RPC metadata and removed noisy debug logging from multiple test files.
  • Bug Fix

    • Preserve null gRPC config during updates and enable gRPC startup when saas config is present.

Review Change Stack

@santigimeno
santigimeno requested a review from RafaelGSS April 29, 2026 18:30
@santigimeno santigimeno self-assigned this Apr 29, 2026
@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Centralizes gRPC request metadata into a single GrpcMetadata cached on GrpcAgent. GrpcClient gains AddMetadata and MakeClientContext now accepts GrpcMetadata. Streams, exporters, lib/config, and tests are updated to build, pass, and validate the unified metadata; test noise is reduced.

Changes

Grpc metadata centralization

Layer / File(s) Summary
Data Shape / Types
agents/grpc/src/grpc_client.h
Introduce GrpcMetadata = opentelemetry::v1::exporter::otlp::OtlpHeaders; and change MakeClientContext to accept const GrpcMetadata&.
Core Implementation
agents/grpc/src/grpc_client.cc
Add GrpcClient::AddMetadata(::grpc::ClientContext*, const GrpcMetadata&) and make MakeClientContext populate the context via this helper.
Metadata Construction & Caching
agents/grpc/src/grpc_agent.h, agents/grpc/src/grpc_agent.cc
Add BuildRpcMetadata, RefreshRpcMetadata, store GrpcMetadata rpc_metadata_, expose rpc_metadata(), and initialize/refresh cached metadata.
Call Sites / Exporters
agents/grpc/src/grpc_agent.cc
Replace previous per-call MakeClientContext(agent_id_, saas()) and OTLP option metadata with GrpcClient::MakeClientContext(rpc_metadata()) across streaming and exporter setup.
Wiring / Stream Constructors
agents/grpc/src/asset_stream.h, agents/grpc/src/asset_stream.cc, agents/grpc/src/command_stream.h, agents/grpc/src/command_stream.cc
Update AssetStream and CommandStream constructors to accept const GrpcMetadata& metadata and attach metadata via GrpcClient::AddMetadata(&context_, metadata).
Lib / Config handling
lib/nsolid.js, src/nsolid/nsolid_api.cc
Treat saas as enabling grpc-backed assets, make grpc startup conditional on `grpc
Tests / Test Helpers
test/common/nsolid-grpc-agent/*, test/agents/test-grpc-basic.mjs
Forward call.metadata from server, add checkRpcMetadata(metadata, agentId) helper, update tests to validate user-agent, nsolid-agent-id, nsolid-version, and optional nsolid-saas.
Tests / Debug cleanup
test/agents/*, test/common/nsolid-grpc-agent/server.mjs
Remove noisy console.log/console.dir debug output and remove NODE_DEBUG_NATIVE env entries from many gRPC tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • nodesource/nsolid#310: Overlapping AssetStream constructor/signature changes and asset-streaming code edits.

Suggested labels

QA approved

Suggested reviewers

  • RafaelGSS

  • juanarbol

Poem

🐇 I nibble headers one by one,

A single bundle, no more run.
Cached and tidy, through each call,
Metadata hops — neat for all.
Tiny paws, big tidy haul.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately describes the main change: adding an nsolid-version field and including it in the agent metadata across the codebase.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch santi/nsolidversion

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

@santigimeno
santigimeno force-pushed the santi/nsolidversion branch from 4d4f8ea to e9aee4a Compare May 4, 2026 14:03

@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 the current code and only fix it if needed.

Inline comments:
In `@agents/grpc/src/grpc_agent.cc`:
- Around line 1045-1056: When saas_ is cleared or parse_saas_token fails we must
also tear down existing gRPC clients instead of leaving them running; update the
logic around the "if (grpc_changed || saas_changed)" block so that a
saas_changed event always executes the same gRPC shutdown/reset lifecycle used
for gRPC reconfiguration (the code that resets stubs/command stream/exporters),
even when there is no "/grpc" entry (i.e. when it == config_.end() && !saas_).
Concretely, after saas_ is reset and RefreshRpcMetadata() is called, invoke the
same teardown/reset code path (or refactor that teardown into a helper and call
it) referenced in the existing grpc reconfigure branch so stale endpoints/tokens
are cleared.
🪄 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: CHILL

Plan: Pro

Run ID: 0e2dbd9c-8d8c-4f6e-8fcc-cf6d98cf630b

📥 Commits

Reviewing files that changed from the base of the PR and between 4d4f8ea and e9aee4a.

📒 Files selected for processing (11)
  • agents/grpc/src/asset_stream.cc
  • agents/grpc/src/asset_stream.h
  • agents/grpc/src/command_stream.cc
  • agents/grpc/src/command_stream.h
  • agents/grpc/src/grpc_agent.cc
  • agents/grpc/src/grpc_agent.h
  • agents/grpc/src/grpc_client.cc
  • agents/grpc/src/grpc_client.h
  • test/agents/test-grpc-basic.mjs
  • test/common/nsolid-grpc-agent/index.js
  • test/common/nsolid-grpc-agent/server.mjs
✅ Files skipped from review due to trivial changes (2)
  • agents/grpc/src/grpc_client.h
  • agents/grpc/src/grpc_client.cc
🚧 Files skipped from review as they are similar to previous changes (7)
  • test/common/nsolid-grpc-agent/server.mjs
  • agents/grpc/src/command_stream.h
  • agents/grpc/src/asset_stream.cc
  • test/agents/test-grpc-basic.mjs
  • agents/grpc/src/asset_stream.h
  • test/common/nsolid-grpc-agent/index.js
  • agents/grpc/src/grpc_agent.h

Comment thread agents/grpc/src/grpc_agent.cc
@santigimeno
santigimeno force-pushed the santi/nsolidversion branch from e9aee4a to 1e835bf Compare May 5, 2026 09:11

@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 `@lib/nsolid.js`:
- Around line 792-796: The conditional that assigns nsolidConfig.grpc
re-stringifies the raw input (config.grpc) and can corrupt normalized values;
change this so you do not override the already-normalized value — preserve
nsolidConfig.grpc when config.grpc is not null instead of setting it to '' +
config.grpc; locate the assignment around nsolidConfig.grpc and modify the else
branch to leave the pre-normalized nsolidConfig.grpc intact (or assign from the
normalized source) so boolean and numeric semantics are preserved.
🪄 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: CHILL

Plan: Pro

Run ID: 3efbfec8-4d7c-4fe3-ae9f-11bc532e90a8

📥 Commits

Reviewing files that changed from the base of the PR and between e9aee4a and 1e835bf.

📒 Files selected for processing (12)
  • agents/grpc/src/asset_stream.cc
  • agents/grpc/src/asset_stream.h
  • agents/grpc/src/command_stream.cc
  • agents/grpc/src/command_stream.h
  • agents/grpc/src/grpc_agent.cc
  • agents/grpc/src/grpc_agent.h
  • agents/grpc/src/grpc_client.cc
  • agents/grpc/src/grpc_client.h
  • lib/nsolid.js
  • test/agents/test-grpc-basic.mjs
  • test/common/nsolid-grpc-agent/index.js
  • test/common/nsolid-grpc-agent/server.mjs
✅ Files skipped from review due to trivial changes (2)
  • test/agents/test-grpc-basic.mjs
  • test/common/nsolid-grpc-agent/index.js
🚧 Files skipped from review as they are similar to previous changes (5)
  • agents/grpc/src/asset_stream.h
  • agents/grpc/src/asset_stream.cc
  • agents/grpc/src/command_stream.h
  • test/common/nsolid-grpc-agent/server.mjs
  • agents/grpc/src/grpc_agent.cc

Comment thread lib/nsolid.js Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 5, 2026
RafaelGSS
RafaelGSS previously approved these changes May 5, 2026

@RafaelGSS RafaelGSS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with lint fix.

@santigimeno
santigimeno dismissed stale reviews from RafaelGSS and coderabbitai[bot] via 0634808 May 19, 2026 14:07
@santigimeno
santigimeno force-pushed the santi/nsolidversion branch from 1e835bf to 0634808 Compare May 19, 2026 14:07
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 19, 2026

@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 `@test/common/nsolid-grpc-agent/index.js`:
- Around line 16-22: The checkRpcMetadata function currently indexes
metadata['nsolid-agent-id'][0] and metadata['nsolid-version'][0] without
validating those headers exist or are arrays; update checkRpcMetadata to first
validateArray(metadata['nsolid-agent-id'], 'metadata.nsolid-agent-id') and
validateArray(metadata['nsolid-version'], 'metadata.nsolid-version') and then
validateString(metadata['nsolid-agent-id'][0], 'metadata.nsolid-agent-id[0]')
and validateString(metadata['nsolid-version'][0], 'metadata.nsolid-version[0]')
before asserting their values (retain the existing assert.strictEqual checks for
agentId and version format).
🪄 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: CHILL

Plan: Pro

Run ID: bbf7c740-71b7-4d0e-93fc-2abcc0d425de

📥 Commits

Reviewing files that changed from the base of the PR and between 0634808 and 2bbf4b4.

📒 Files selected for processing (18)
  • agents/grpc/src/asset_stream.cc
  • agents/grpc/src/asset_stream.h
  • agents/grpc/src/command_stream.cc
  • agents/grpc/src/command_stream.h
  • agents/grpc/src/grpc_agent.cc
  • agents/grpc/src/grpc_agent.h
  • agents/grpc/src/grpc_client.cc
  • agents/grpc/src/grpc_client.h
  • lib/nsolid.js
  • src/nsolid/nsolid_api.cc
  • test/agents/test-grpc-basic.mjs
  • test/agents/test-grpc-continuous-profile.mjs
  • test/agents/test-grpc-heap-profile.mjs
  • test/agents/test-grpc-heap-sampling.mjs
  • test/agents/test-grpc-profile.mjs
  • test/agents/test-grpc-snapshot.mjs
  • test/common/nsolid-grpc-agent/index.js
  • test/common/nsolid-grpc-agent/server.mjs
💤 Files with no reviewable changes (5)
  • test/agents/test-grpc-snapshot.mjs
  • test/agents/test-grpc-profile.mjs
  • test/agents/test-grpc-heap-sampling.mjs
  • test/agents/test-grpc-continuous-profile.mjs
  • test/agents/test-grpc-heap-profile.mjs

Comment thread test/common/nsolid-grpc-agent/index.js

@EHortua EHortua 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.

Before

Image After Image

Also, cache the metadata so it is not rebuilt for each RPC.
Finally, resolve the `nsolid-saas` / `nsolid-saas-token` header split by
standardizing on `nsolid-saas`.

PR-URL: #460
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
PR-URL: #460
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
PR-URL: #460
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
PR-URL: #460
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
@santigimeno
santigimeno force-pushed the santi/nsolidversion branch from 2bbf4b4 to 37f19cd Compare May 25, 2026 15:54
@santigimeno
santigimeno merged commit 37f19cd into node-v24.x-nsolid-v6.x May 25, 2026
12 of 17 checks passed
@santigimeno
santigimeno deleted the santi/nsolidversion branch May 25, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants