Skip to content

refactor(secrets): pair Vault credential failure logs and metrics#3747

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3735
Jul 21, 2026
Merged

refactor(secrets): pair Vault credential failure logs and metrics#3747
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3735

Conversation

@chet

@chet chet commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Vault credential failures incremented carbide_api_vault_requests_failed_total and then wrote a separate diagnostic for the same request outcome.

Four credential-specific sibling Events now own those paired signals while preserving each historical log level, message, and context shape. The existing metric-only VaultRequestFailed continues to cover service-account and certificate failures, and the frozen request/status labels remain unchanged.

A table-driven test covers all six failure shapes without adding irrelevant empty context to any operation.

Related issues

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

The six failure shapes share a check_values table that asserts the returned status, counter delta, and complete log observation for each request type.

Verified with:

  • cargo test -p carbide-secrets (49 passed)
  • cargo make format-nightly
  • cargo make clippy
  • cargo make carbide-lints
  • cargo make check-event-names
  • cargo xtask check-metric-docs

Additional Notes

CodeRabbit suggested adding credential_key to set/delete failures. That would expand their historical log schemas, so this compatibility pass deliberately leaves those fields out; the rationale is also recorded in the PR conversation.

Closes #3735

@chet
chet requested a review from a team as a code owner July 20, 2026 23:05
@chet

chet commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review 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: Enterprise

Run ID: aa64c48b-d8e0-4568-aa2c-c00151c67350

📥 Commits

Reviewing files that changed from the base of the PR and between 4ad44c6 and 7d690cd.

📒 Files selected for processing (1)
  • crates/secrets/src/forge_vault.rs

Summary by CodeRabbit

  • Monitoring & Observability
    • Improved reporting for credential retrieval, creation, update, and deletion failures.
    • Failure metrics now include clearer operation and HTTP status details.
    • Credential-related errors provide more consistent diagnostic logs, including the affected credential context.
    • Service-account login and certificate failures continue to be tracked through metrics without adding duplicate log entries.
  • Bug Fixes
    • Corrected handling of missing credentials so they are treated distinctly from other retrieval failures.

Walkthrough

Vault failure observability now uses specialized credential events and metric-only recorders for service-account and certificate failures. Operation handlers consume returned status codes where needed, and regression coverage validates metrics, logs, credential keys, and error context.

Changes

Vault failure observability

Layer / File(s) Summary
Failure events and recording helpers
crates/secrets/src/forge_vault.rs
Adds specialized credential failure events and separates metric-only recording from credential logging while preserving shared failure counters.
Operation-specific error handling
crates/secrets/src/forge_vault.rs
Updates service-account, credential, and certificate operations to use specialized recorders; credential reads branch on returned status codes.
Observability regression coverage
crates/secrets/src/forge_vault.rs
Updates regression assertions for request-type/status metrics and the revised logging ownership model.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.75% 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
Title check ✅ Passed The title accurately summarizes the main change: refactoring Vault credential failure handling to pair logs and metrics.
Description check ✅ Passed The description is directly aligned with the refactor and test updates described in the changeset.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@chet Understood — I’ll perform a complete review of all changes in #3747.

🐇🔍

✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 11 minutes.

@chet

chet commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@chet Understood. I’ll perform a complete review of all changes in #3747.

🐇🔍

✅ Action performed

Full review finished.

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

🧹 Nitpick comments (2)
crates/secrets/src/forge_vault.rs (2)

275-314: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing credential_key context on write/delete failure events.

VaultCredentialsSetFailed and VaultCredentialsDeleteFailed carry only error, unlike VaultCredentialsNotFound/VaultCredentialsGetFailed, which also capture credential_key. Both SetCredentialsHelper and DeleteCredentialsHelper already hold self.key (used to build the Vault path at Lines 711/725/765), so this context is available but discarded — weakening diagnosability for write/delete failures relative to reads. See the paired comment on the recording functions (Lines 671-689) for the full fix, including struct field additions here.

🤖 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 `@crates/secrets/src/forge_vault.rs` around lines 275 - 314, The
VaultCredentialsSetFailed and VaultCredentialsDeleteFailed event structs are
missing credential_key context. Add a credential_key field matching the existing
field definition used by VaultCredentialsNotFound and VaultCredentialsGetFailed,
then ensure the SetCredentialsHelper and DeleteCredentialsHelper recording
functions populate it from self.key when emitting these events.

671-689: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add credential_key to record_vault_credentials_set_error/delete_error for parity with the get-path.

These two functions emit VaultCredentialsSetFailed/VaultCredentialsDeleteFailed without a credential_key, unlike record_vault_credentials_get_error above, which threads credential_key through for the read path. Both call sites already have self.key in scope (Lines 738-739 in SetCredentialsHelper::execute, Lines 775-776 in DeleteCredentialsHelper::execute), so this is a straightforward, low-risk addition that closes an observability gap for troubleshooting failed writes/deletes.

♻️ Proposed fix threading credential_key through set/delete recorders
 struct VaultCredentialsSetFailed {
     #[label]
     request_type: VaultRequestType,
     #[label]
     http_response_status_code: VaultFailureStatusCode,
+    #[context]
+    credential_key: String,
     #[context]
     error: String,
 }
 struct VaultCredentialsDeleteFailed {
     #[label]
     request_type: VaultRequestType,
     #[label]
     http_response_status_code: VaultFailureStatusCode,
+    #[context]
+    credential_key: String,
     #[context]
     error: String,
 }
-fn record_vault_credentials_set_error(err: &ClientError) -> Option<u16> {
+fn record_vault_credentials_set_error(err: &ClientError, credential_key: &CredentialKey) -> Option<u16> {
     let status_code = vault_client_error_status(err);
     emit(VaultCredentialsSetFailed {
         request_type: VaultRequestType::SetCredentials,
         http_response_status_code: VaultFailureStatusCode(status_code),
+        credential_key: credential_key.to_key_str().into_owned(),
         error: format!("{err:?}"),
     });
     status_code
 }

-fn record_vault_credentials_delete_error(err: &ClientError) -> Option<u16> {
+fn record_vault_credentials_delete_error(err: &ClientError, credential_key: &CredentialKey) -> Option<u16> {
     let status_code = vault_client_error_status(err);
     emit(VaultCredentialsDeleteFailed {
         request_type: VaultRequestType::DeleteCredentials,
         http_response_status_code: VaultFailureStatusCode(status_code),
+        credential_key: credential_key.to_key_str().into_owned(),
         error: format!("{err:?}"),
     });
     status_code
 }

And update the call sites accordingly:

-        let _secret_version_metadata = vault_response.inspect_err(|err| {
-            record_vault_credentials_set_error(err);
-        })?;
+        let _secret_version_metadata = vault_response.inspect_err(|err| {
+            record_vault_credentials_set_error(err, self.key);
+        })?;
-        let _secret_version_metadata = vault_response.inspect_err(|err| {
-            record_vault_credentials_delete_error(err);
-        })?;
+        let _secret_version_metadata = vault_response.inspect_err(|err| {
+            record_vault_credentials_delete_error(err, self.key);
+        })?;
🤖 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 `@crates/secrets/src/forge_vault.rs` around lines 671 - 689, Update
record_vault_credentials_set_error and record_vault_credentials_delete_error to
accept a credential_key argument and include it in their emitted
VaultCredentialsSetFailed and VaultCredentialsDeleteFailed events, matching
record_vault_credentials_get_error. Pass self.key from
SetCredentialsHelper::execute and DeleteCredentialsHelper::execute at their
existing error-recording call sites.
🤖 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.

Nitpick comments:
In `@crates/secrets/src/forge_vault.rs`:
- Around line 275-314: The VaultCredentialsSetFailed and
VaultCredentialsDeleteFailed event structs are missing credential_key context.
Add a credential_key field matching the existing field definition used by
VaultCredentialsNotFound and VaultCredentialsGetFailed, then ensure the
SetCredentialsHelper and DeleteCredentialsHelper recording functions populate it
from self.key when emitting these events.
- Around line 671-689: Update record_vault_credentials_set_error and
record_vault_credentials_delete_error to accept a credential_key argument and
include it in their emitted VaultCredentialsSetFailed and
VaultCredentialsDeleteFailed events, matching
record_vault_credentials_get_error. Pass self.key from
SetCredentialsHelper::execute and DeleteCredentialsHelper::execute at their
existing error-recording call sites.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ec6c45b6-511e-4e14-adb0-42b5f5444beb

📥 Commits

Reviewing files that changed from the base of the PR and between 29b890e and fec9776.

📒 Files selected for processing (1)
  • crates/secrets/src/forge_vault.rs

@chet chet changed the title refactor(secrets): emit Vault request failures refactor(secrets): keep Vault failure counts with credential errors Jul 20, 2026
@chet

chet commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Keeping credential_key off the set/delete failure Events in this refactor. Those paths historically logged only the error, while get/not-found carried the key; adding it here would expand the existing log schema rather than consolidate the metric and record as-is. The table now pins that distinction explicitly. A separate observability follow-up can reconsider the schema if we want the extra context.

@chet

chet commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@chet Understood. I’ll perform a complete review of all changes in #3747, including the established credential_key schema distinction for set/delete failures.

✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 17 minutes.

@chet

chet commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Hey @coderabbitai can you do a full_review when you get a chance? CICD isn't letting me continue because the CodeRabbit check "failed". Thanks!

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@chet I’ve triggered a complete re-review of all changes in #3747.

🐇🔍

✅ Action performed

Full review finished.

@chet chet changed the title refactor(secrets): keep Vault failure counts with credential errors refactor(secrets): pair Vault credential failure logs and metrics Jul 21, 2026
Vault credential failures incremented `carbide_api_vault_requests_failed_total` and then wrote a separate diagnostic for the same request outcome.

Four credential-specific sibling `Event`s now own those paired signals while preserving each historical log level, message, and context shape. The existing metric-only `VaultRequestFailed` continues to cover service-account and certificate failures, and the frozen request/status labels remain unchanged.

A table-driven test covers all six failure shapes without adding irrelevant empty context to any operation.

This supports NVIDIA#3735

Signed-off-by: Chet Nichols III <chetn@nvidia.com>

chet commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@chet Understood — I’ll perform a complete re-review of all changes in #3747.

✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 20 minutes.

@chet

chet commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Hey @coderabbitai can you do a full_review when you get a chance? CICD isn't letting me continue because the CodeRabbit check "failed". Thanks!

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@chet Understood — I’ve triggered a complete re-review of all changes in #3747.

🐇🔍

✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 12 minutes.

chet commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@chet Understood — I’ve triggered a complete re-review of all changes in #3747.

🐇🔍

✅ Action performed

Full review finished.

@chet
chet merged commit 02afd6f into NVIDIA:main Jul 21, 2026
62 checks passed
@chet
chet deleted the gh-issue-3735 branch July 21, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify Vault request failure logs and metrics

2 participants