Skip to content

Commit

Permalink
feat(runtime): include leases in runtime diagnostics
Browse files Browse the repository at this point in the history
This change updates `Runtime::spawn_lease` (added in b26b009) to register leases
with the admin server's diagnostics endpoint when the `runtime-diagnostics`
feature is enabled:

```json
{
  "initialTimestamp": "2025-01-04T19:28:33Z",
  "currentTimestamp": "2025-01-04T19:29:28Z",
  "leases": [
    {
      "name": "foobar",
      "namespace": "default",
      "claimant": "code",
      "fieldManager": "kubert-examples",
      "leaseDurationSeconds": 30,
      "renewGracePeriodSeconds": 1,
      "updates": 2,
      "creationTimestamp": "2025-01-04T19:28:33Z",
      "lastUpdateTimestamp": "2025-01-04T19:29:24Z",
      "resourceVersion": "1822330",
      "current": {
        "holder": "code",
        "expiry": "2025-01-04T19:29:54.207379734Z"
      }
    }
  ]
}
```
  • Loading branch information
olix0r committed Jan 4, 2025
1 parent e8b4c18 commit f45c0d1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions kubert/src/admin/diagnostics/lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@ pub(super) struct LeaseState {
name: String,
namespace: String,
claimant: String,
field_manager: Cow<'static, str>,
lease_duration_seconds: f64,
renew_grace_period_seconds: f64,
field_manager: Cow<'static, str>,
#[serde(skip_serializing_if = "Option::is_none")]
claim: Option<crate::lease::Claim>,
#[serde(flatten)]
stats: LeaseStats,
#[serde(skip_serializing_if = "Option::is_none")]
resource_version: Option<String>,
stats: LeaseStats,
#[serde(skip_serializing_if = "Option::is_none")]
current: Option<crate::lease::Claim>,
}

#[derive(Clone, Debug, serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct LeaseStats {
creation_timestamp: Time,

updates: u64,

creation_timestamp: Time,
#[serde(skip_serializing_if = "Option::is_none")]
last_update_timestamp: Option<Time>,
}
Expand Down Expand Up @@ -59,7 +58,7 @@ impl LeaseDiagnostics {
field_manager: field_manager.clone().unwrap_or(Cow::Borrowed(
crate::lease::LeaseManager::DEFAULT_FIELD_MANAGER,
)),
claim: None,
current: None,
resource_version: None,
stats: LeaseStats {
creation_timestamp: now,
Expand All @@ -79,13 +78,13 @@ impl LeaseDiagnostics {
resource_version: String,
) {
let mut state = self.0.write();
if claim.as_deref() == state.claim.as_ref()
if claim.as_deref() == state.current.as_ref()
&& Some(&*resource_version) == state.resource_version.as_deref()
{
return;
}
let now = Time(chrono::Utc::now());
state.claim = claim.as_deref().cloned();
state.current = claim.as_deref().cloned();
state.resource_version = Some(resource_version);
state.stats.updates += 1;
state.stats.last_update_timestamp = Some(now);
Expand Down

0 comments on commit f45c0d1

Please sign in to comment.