Skip to content

fix(jans-cedarling): update hardcoded status field in telemetry entry#14555

Open
dagregi wants to merge 4 commits into
mainfrom
jans-cedarling-14549
Open

fix(jans-cedarling): update hardcoded status field in telemetry entry#14555
dagregi wants to merge 4 commits into
mainfrom
jans-cedarling-14549

Conversation

@dagregi

@dagregi dagregi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Prepare


Description

Target issue

closes #14549

Implementation Details


Test and Document the changes

  • Static code analysis has been run locally and issues have been fixed
  • Relevant unit and integration tests have been added/updated
  • Relevant documentation has been updated if any (i.e. user guides, installation and configuration guides, technical design docs etc)

Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with docs: to indicate documentation changes or if the below checklist is not selected.

  • I confirm that there is no impact on the docs due to the code changes in this PR.

Summary by CodeRabbit

  • New Features
    • Added health-derived status (running, degraded, unknown) to metrics/telemetry records based on registered health checks when available.
    • Metrics now automatically reflect overall system health rather than relying solely on static values.
  • Bug Fixes
    • Metrics no longer default to running when health information isn’t available; they now report unknown.
    • Explicit health status (including degraded) is now preserved end-to-end and correctly mapped into telemetry metrics.
  • Tests
    • Updated and expanded unit tests to cover the new status propagation and mapping behavior.

@dagregi dagregi self-assigned this Jul 15, 2026
@mo-auto

mo-auto commented Jul 15, 2026

Copy link
Copy Markdown
Member

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The change computes aggregate engine health as unknown, running, or degraded, carries it through metric audit items, and preserves it in Lock Server metrics. Audit payload conversion now borrows log entries instead of consuming them.

Health status plumbing

Layer / File(s) Summary
Borrowed audit payload conversion
jans-cedarling/cedarling/src/log/interface.rs, jans-cedarling/cedarling/src/log/log_entry.rs, jans-cedarling/cedarling/src/log/log_strategy.rs
Audit payload conversion uses borrowed receivers and cloned decision or metric entries; metric audit items initialize status as None.
Health status computation and dispatch
jans-cedarling/cedarling/src/lock/health_registry.rs, jans-cedarling/cedarling/src/lock/health_ticker.rs, jans-cedarling/cedarling/src/lock/mod.rs, jans-cedarling/cedarling/src/lock/transport/mod.rs
Health states are aggregated and assigned to metric audit items before telemetry dispatch, while health audit items explicitly omit status.
Metrics status mapping and fixtures
jans-cedarling/cedarling/src/lock/transport/mapping.rs, jans-cedarling/cedarling/src/lock/transport/test_utils.rs
Metric mapping preserves explicit statuses and defaults absent values to unknown; tests and transport fixtures reflect the optional field.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: 0xtinkle, haileyesus2433, olehbozhok

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% 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 is concise and accurately describes the main telemetry status fix.
Description check ✅ Passed The PR description matches the template overall, but the implementation details section is left blank.
Linked Issues check ✅ Passed The changes implement dynamic telemetry status values for unknown, running, and degraded as requested in #14549.
Out of Scope Changes check ✅ Passed The additional refactors around audit payload conversion and status plumbing are directly tied to the telemetry status fix.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jans-cedarling-14549

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.

@mo-auto mo-auto added comp-jans-cedarling Touching folder /jans-cedarling kind-bug Issue or PR is a bug in existing functionality labels Jul 15, 2026

@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: 2

🤖 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 `@jans-cedarling/cedarling/src/lock/health_registry.rs`:
- Around line 101-109: Introduce a public strongly typed SystemHealth enum with
Unknown, Running, and Degraded variants in health_registry.rs, update
compute_status to return it, and use matches!(s, HealthStatus::Success) for
success detection; convert the enum to strings only at serialization boundaries
and update downstream mappings and dispatch_audit assignments to use as_str() or
to_string(). In jans-cedarling/cedarling/src/lock/transport/mod.rs:45, change
AuditItem::status from Option<String> to the appropriate Option<SystemHealth>
type.

In `@jans-cedarling/cedarling/src/lock/mod.rs`:
- Around line 413-422: Update HealthRegistry with a current_status method that
reads the registered checks and computes the overall status directly, returning
the existing unknown, running, or degraded values without collecting a HashMap.
In dispatch_audit, replace HealthRegistry::compute_status(&registry.collect())
with the new current_status call while preserving the existing status assignment
and telemetry dispatch.
🪄 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: d61093c5-863d-4f62-a700-2738e6e84677

📥 Commits

Reviewing files that changed from the base of the PR and between 152db2a and 5733593.

📒 Files selected for processing (9)
  • jans-cedarling/cedarling/src/lock/health_registry.rs
  • jans-cedarling/cedarling/src/lock/health_ticker.rs
  • jans-cedarling/cedarling/src/lock/mod.rs
  • jans-cedarling/cedarling/src/lock/transport/mapping.rs
  • jans-cedarling/cedarling/src/lock/transport/mod.rs
  • jans-cedarling/cedarling/src/lock/transport/test_utils.rs
  • jans-cedarling/cedarling/src/log/interface.rs
  • jans-cedarling/cedarling/src/log/log_entry.rs
  • jans-cedarling/cedarling/src/log/log_strategy.rs

Comment thread jans-cedarling/cedarling/src/lock/health_registry.rs Outdated
Comment thread jans-cedarling/cedarling/src/lock/mod.rs
pub payload: AuditPayload,
pub pdp_id: PdpID,
pub app_name: Option<ApplicationName>,
pub status: Option<String>,

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.

Maybe better to have a status as an enum?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to use an enum in 7729fd0

Signed-off-by: dagregi <dagmawi.m@proton.me>

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
jans-cedarling/cedarling/src/lock/transport/mapping.rs (1)

400-400: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add a descriptive message to the assertion.

As per coding guidelines, all assertions must include a descriptive message explaining what is being tested.

🐛 Proposed fix
-        assert_eq!(lock_entry.status, "unknown");
+        assert_eq!(lock_entry.status, "unknown", "metrics without explicit status should default to unknown");
🤖 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 `@jans-cedarling/cedarling/src/lock/transport/mapping.rs` at line 400, Update
the assertion checking lock_entry.status in the relevant test to include a
descriptive failure message explaining that the lock entry status is expected to
be "unknown".

Source: Coding guidelines

🤖 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 `@jans-cedarling/cedarling/src/lock/health_registry.rs`:
- Around line 26-33: Update the HealthStatus::fmt implementation to use
f.write_str for the literal "success" and "failure" outputs instead of the
write! macro, preserving the existing Display behavior.

In `@jans-cedarling/cedarling/src/lock/transport/mapping.rs`:
- Around line 174-176: Update the status mapping in the surrounding transport
conversion to use SystemHealth::as_str with map_or, returning the existing
"unknown" fallback and allocating only the final String. Replace the current
map_or_else closure and s.to_string formatting while preserving the same output
for present and absent statuses.

---

Outside diff comments:
In `@jans-cedarling/cedarling/src/lock/transport/mapping.rs`:
- Line 400: Update the assertion checking lock_entry.status in the relevant test
to include a descriptive failure message explaining that the lock entry status
is expected to be "unknown".
🪄 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: 0af9e1b6-f15e-4a82-834d-8995f216636c

📥 Commits

Reviewing files that changed from the base of the PR and between 5733593 and 7729fd0.

📒 Files selected for processing (5)
  • jans-cedarling/cedarling/src/lock/health_registry.rs
  • jans-cedarling/cedarling/src/lock/health_ticker.rs
  • jans-cedarling/cedarling/src/lock/mod.rs
  • jans-cedarling/cedarling/src/lock/transport/mapping.rs
  • jans-cedarling/cedarling/src/lock/transport/mod.rs

Comment thread jans-cedarling/cedarling/src/lock/health_registry.rs
Comment thread jans-cedarling/cedarling/src/lock/transport/mapping.rs Outdated
tareknaser
tareknaser previously approved these changes Jul 15, 2026

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

Looks good to me. thank you
I just have a minor comment

"degraded"
}
.to_string();
let overall_status = self.registry.compute_status();

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.

Here collect() already runs every registered check to build engine_status and then compute_status() takes the read lock again and runs every check a second time just to reduce them to the overall value. So on each tick the checks run twice under two separate lock snapshots.

I think compute_status() is the right call in dispatch_audit (there's no collect() there so re-deriving is the cheap option) but here you already have the map in hand. Could you derive the overall from engine_status instead? Something like:

let overall_status = if engine_status.is_empty() {
    SystemHealth::Unknown
} else if engine_status.values().all(|s| *s == HealthStatus::Success) {
    SystemHealth::Running
} else {
    SystemHealth::Degraded
};

That way the checks only run once and the overall status is guaranteed to match the engine_status map you send in the same entry.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed it in 084d910

Signed-off-by: dagregi <dagmawi.m@proton.me>
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 15, 2026
haileyesus2433
haileyesus2433 previously approved these changes Jul 15, 2026
.as_ref()
.map(HealthRegistry::compute_status);
item.status = status;
(self.telemetry_worker.as_ref(), "telemetry")

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.

The worker name can also be an enum

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This might be an overkill since it's only used for a single time logging

olehbozhok
olehbozhok previously approved these changes Jul 16, 2026
assert_eq!(lock_entry.service.as_deref(), Some("jans-auth"));
assert_eq!(lock_entry.node_name, pdp_id.to_string());
assert_eq!(lock_entry.status, "running");
assert_eq!(lock_entry.status, "unknown");

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.

I think better to compare enums

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated it in b0fbdf1

Signed-off-by: dagregi <dagmawi.m@proton.me>

@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 `@jans-cedarling/cedarling/src/lock/transport/mapping.rs`:
- Line 401: Update the changed assert_eq! calls in the lock transport mapping
tests, including the assertions around lock_entry.status at the referenced
locations, to include descriptive failure messages. Ensure each message explains
the expected system health status while preserving the existing comparisons.
🪄 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: 050ffe6e-21cf-4b40-8d87-ac6b3519b336

📥 Commits

Reviewing files that changed from the base of the PR and between 084d910 and b0fbdf1.

📒 Files selected for processing (1)
  • jans-cedarling/cedarling/src/lock/transport/mapping.rs

Comment thread jans-cedarling/cedarling/src/lock/transport/mapping.rs

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

No further comments from my side

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

Labels

comp-jans-cedarling Touching folder /jans-cedarling kind-bug Issue or PR is a bug in existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(jans-cedarling): update hardcoded status field in telemetry entry

5 participants