Skip to main content

alien_core/
heartbeat.rs

1use std::collections::BTreeMap;
2
3use crate::{ai_catalog::ClientApi, Platform, ResourceType};
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use serde_json::Value as JsonValue;
7
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
10#[serde(rename_all = "camelCase")]
11pub struct ResourceHeartbeat {
12    pub deployment_id: Option<String>,
13    /// Alien resource id, such as the `alien.Container` or `alien.Storage`
14    /// resource id from the stack.
15    pub resource_id: String,
16    pub resource_type: ResourceType,
17    pub controller_platform: Platform,
18    pub backend: HeartbeatBackend,
19    pub observed_at: DateTime<Utc>,
20    pub data: ResourceHeartbeatData,
21    pub raw: Vec<RawHeartbeatSnippet>,
22}
23
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
26#[serde(rename_all = "camelCase")]
27pub struct ObservedInventoryBatch {
28    /// Writer/source for this inventory pass, such as `operator` or
29    /// `manager-observer`.
30    pub source_kind: String,
31    /// Stable scope for the provider list operation that produced this batch.
32    pub inventory_scope: String,
33    /// Platform whose observer produced this snapshot.
34    pub controller_platform: Platform,
35    /// Backend whose observer produced this snapshot.
36    pub backend: HeartbeatBackend,
37    /// Time the inventory scope was observed.
38    pub observed_at: DateTime<Utc>,
39    /// Whether this batch is a complete replacement for the scope. Complete
40    /// batches tombstone previously observed rows in the same scope when they
41    /// are absent from `resources`.
42    pub complete: bool,
43    pub resources: Vec<ObservedResourceSample>,
44}
45
46#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
48#[serde(rename_all = "camelCase")]
49pub struct ObservedResourceSample {
50    pub deployment_id: Option<String>,
51    /// Provider-native stable identity: Kubernetes object identity, cloud ARN,
52    /// GCP full resource name, Azure resource id, etc.
53    pub raw_identity: String,
54    /// Provider-native kind, such as `apps/v1/Deployment`,
55    /// `AWS::S3::Bucket`, `storage.googleapis.com/Bucket`, or an Azure
56    /// resource type.
57    pub provider_kind: String,
58    pub display_name: String,
59    #[serde(default, skip_serializing_if = "Option::is_none")]
60    pub namespace: Option<String>,
61    #[serde(default, skip_serializing_if = "Option::is_none")]
62    pub region: Option<String>,
63    #[serde(default, skip_serializing_if = "Option::is_none")]
64    pub scope: Option<String>,
65    #[serde(default, skip_serializing_if = "Option::is_none")]
66    pub resource_type_hint: Option<ResourceType>,
67    /// Release/version identity observed from the provider resource, when available.
68    #[serde(default, skip_serializing_if = "Option::is_none")]
69    pub version: Option<String>,
70    #[serde(default, skip_serializing_if = "Option::is_none")]
71    pub alien_resource_id: Option<String>,
72    pub health: ObservedHealth,
73    pub lifecycle: ProviderLifecycleState,
74    #[serde(default, skip_serializing_if = "Option::is_none")]
75    pub message: Option<String>,
76    pub partial: bool,
77    pub provider_stale: bool,
78    #[serde(default, skip_serializing_if = "Option::is_none")]
79    pub counts: Option<ObservedCounts>,
80    #[serde(default, skip_serializing_if = "Vec::is_empty")]
81    pub collection_issues: Vec<HeartbeatCollectionIssue>,
82    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
83    pub labels: BTreeMap<String, String>,
84    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
85    pub attributes: BTreeMap<String, JsonValue>,
86    #[serde(default, skip_serializing_if = "Vec::is_empty")]
87    pub raw: Vec<RawHeartbeatSnippet>,
88    /// Distinct container images the resource's running instances report, when
89    /// the provider exposes them.
90    #[serde(default, skip_serializing_if = "Vec::is_empty")]
91    pub images: Vec<ContainerImageIdentity>,
92}
93
94/// Image a running container reports.
95#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
96#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
97#[serde(rename_all = "camelCase")]
98pub struct ContainerImageIdentity {
99    /// Container name.
100    pub name: String,
101    /// Image reference reported by the container runtime.
102    pub image: String,
103    /// Registry manifest digest in `sha256:<hex>` form, when the runtime
104    /// reports one.
105    #[serde(default, skip_serializing_if = "Option::is_none")]
106    pub digest: Option<String>,
107}
108
109#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
110#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
111#[serde(rename_all = "camelCase")]
112pub enum HeartbeatBackend {
113    Aws,
114    Gcp,
115    Azure,
116    Kubernetes,
117    Local,
118    Managed,
119    External,
120    Test,
121}
122
123#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
124#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
125#[serde(rename_all = "kebab-case")]
126pub enum HeartbeatCollectionIssueReason {
127    Forbidden,
128    NotInstalled,
129    ApiUnavailable,
130    CollectionFailed,
131    TimedOut,
132}
133
134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
135#[serde(tag = "resourceType", content = "data", remote = "Self")]
136pub enum ResourceHeartbeatData {
137    #[serde(rename = "storage")]
138    Storage(StorageHeartbeatData),
139    #[serde(rename = "worker")]
140    Worker(WorkerHeartbeatData),
141    #[serde(rename = "container")]
142    Container(ContainerHeartbeatData),
143    #[serde(rename = "daemon")]
144    Daemon(DaemonHeartbeatData),
145    #[serde(rename = "compute-cluster")]
146    ComputeCluster(ComputeClusterHeartbeatData),
147    #[serde(rename = "kubernetes-cluster")]
148    KubernetesCluster(KubernetesClusterHeartbeatData),
149    #[serde(rename = "queue")]
150    Queue(QueueHeartbeatData),
151    #[serde(rename = "kv")]
152    Kv(KvHeartbeatData),
153    #[serde(rename = "postgres")]
154    Postgres(PostgresHeartbeatData),
155    #[serde(rename = "redis")]
156    Redis(RedisHeartbeatData),
157    #[serde(rename = "vault")]
158    Vault(VaultHeartbeatData),
159    #[serde(rename = "service-account")]
160    ServiceAccount(ServiceAccountHeartbeatData),
161    #[serde(rename = "network")]
162    Network(NetworkHeartbeatData),
163    #[serde(rename = "remote-stack-management")]
164    RemoteStackManagement(RemoteStackManagementHeartbeatData),
165    #[serde(rename = "artifact-registry")]
166    ArtifactRegistry(ArtifactRegistryHeartbeatData),
167    #[serde(rename = "build")]
168    Build(BuildHeartbeatData),
169    #[serde(rename = "service_activation")]
170    ServiceActivation(ServiceActivationHeartbeatData),
171    #[serde(rename = "azure_resource_group")]
172    AzureResourceGroup(AzureResourceGroupHeartbeatData),
173    #[serde(rename = "azure_storage_account")]
174    AzureStorageAccount(AzureStorageAccountHeartbeatData),
175    #[serde(rename = "azure_container_apps_environment")]
176    AzureContainerAppsEnvironment(AzureContainerAppsEnvironmentHeartbeatData),
177    #[serde(rename = "azure_service_bus_namespace")]
178    AzureServiceBusNamespace(AzureServiceBusNamespaceHeartbeatData),
179    #[serde(rename = "ai")]
180    Ai(AiHeartbeatData),
181    #[serde(rename = "key")]
182    Key(KeyHeartbeatData),
183    #[serde(rename = "sandbox")]
184    Sandbox(SandboxHeartbeatData),
185    /// A heartbeat from a resource type an extension defines. It serializes to the same
186    /// `{resourceType, data}` object as the variants above, with the extension's type as the tag.
187    #[serde(skip)]
188    Custom(CustomHeartbeat),
189}
190
191// `remote = "Self"` turns the derived impls into inherent fns, which these two call for the
192// built-in variants.
193impl Serialize for ResourceHeartbeatData {
194    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
195        match self {
196            ResourceHeartbeatData::Custom(custom) => custom.serialize(serializer),
197            built_in => ResourceHeartbeatData::serialize(built_in, serializer),
198        }
199    }
200}
201
202/// Only a tag that names an extension's type reads as `Custom`. A built-in tag takes its own
203/// variant's shape and any other tag is refused, so a malformed built-in heartbeat never loads as
204/// custom.
205impl<'de> Deserialize<'de> for ResourceHeartbeatData {
206    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
207        let value = JsonValue::deserialize(deserializer)?;
208        let is_custom = value
209            .get("resourceType")
210            .and_then(JsonValue::as_str)
211            .is_some_and(crate::custom_resource::is_custom_resource_type);
212        if is_custom {
213            serde_json::from_value::<CustomHeartbeat>(value)
214                .map(ResourceHeartbeatData::Custom)
215                .map_err(serde::de::Error::custom)
216        } else {
217            ResourceHeartbeatData::deserialize(value).map_err(serde::de::Error::custom)
218        }
219    }
220}
221
222// Utoipa drops a variant marked `#[serde(skip)]`, as `Custom` is, so the schema lists the
223// built-in variants by hand, each with the shape the derive would give it.
224#[cfg(feature = "openapi")]
225macro_rules! heartbeat_data_schema {
226    ($($tag:literal => $data:ty),* $(,)?) => {
227        impl utoipa::PartialSchema for ResourceHeartbeatData {
228            fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
229                use utoipa::openapi::{ObjectBuilder, OneOfBuilder, Ref, Type};
230                use utoipa::ToSchema as _;
231                OneOfBuilder::new()
232                    $(.item(
233                        ObjectBuilder::new()
234                            .schema_type(Type::Object)
235                            .property("data", Ref::from_schema_name(<$data>::name()))
236                            .required("data")
237                            .property(
238                                "resourceType",
239                                ObjectBuilder::new()
240                                    .schema_type(Type::String)
241                                    .enum_values(Some([$tag])),
242                            )
243                            .required("resourceType"),
244                    ))*
245                    // Inline like the built-in variants, not a `$ref`: generators that sort a
246                    // union's members by kind would otherwise move a reference first, and a
247                    // union that tries the custom variant before the built-ins can take a
248                    // built-in heartbeat's fields and lose them.
249                    .item(
250                        ObjectBuilder::new()
251                            .schema_type(Type::Object)
252                            .description(Some(
253                                "The heartbeat of a resource whose type an extension defines.",
254                            ))
255                            .property(
256                                "data",
257                                Ref::from_schema_name(CustomHeartbeatData::name()),
258                            )
259                            .required("data")
260                            .property(
261                                "resourceType",
262                                Ref::from_schema_name(CustomResourceType::name()),
263                            )
264                            .required("resourceType"),
265                    )
266                    .into()
267            }
268        }
269
270        impl utoipa::ToSchema for ResourceHeartbeatData {
271            fn schemas(
272                schemas: &mut Vec<(
273                    String,
274                    utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>,
275                )>,
276            ) {
277                use utoipa::PartialSchema as _;
278                $(
279                    schemas.push((<$data>::name().into_owned(), <$data>::schema()));
280                    <$data>::schemas(schemas);
281                )*
282                schemas.push((CustomHeartbeat::name().into_owned(), CustomHeartbeat::schema()));
283                CustomHeartbeat::schemas(schemas);
284            }
285        }
286    };
287}
288
289#[cfg(feature = "openapi")]
290heartbeat_data_schema! {
291    "storage" => StorageHeartbeatData,
292    "worker" => WorkerHeartbeatData,
293    "container" => ContainerHeartbeatData,
294    "daemon" => DaemonHeartbeatData,
295    "compute-cluster" => ComputeClusterHeartbeatData,
296    "kubernetes-cluster" => KubernetesClusterHeartbeatData,
297    "queue" => QueueHeartbeatData,
298    "kv" => KvHeartbeatData,
299    "postgres" => PostgresHeartbeatData,
300    "redis" => RedisHeartbeatData,
301    "vault" => VaultHeartbeatData,
302    "service-account" => ServiceAccountHeartbeatData,
303    "network" => NetworkHeartbeatData,
304    "remote-stack-management" => RemoteStackManagementHeartbeatData,
305    "artifact-registry" => ArtifactRegistryHeartbeatData,
306    "build" => BuildHeartbeatData,
307    "service_activation" => ServiceActivationHeartbeatData,
308    "azure_resource_group" => AzureResourceGroupHeartbeatData,
309    "azure_storage_account" => AzureStorageAccountHeartbeatData,
310    "azure_container_apps_environment" => AzureContainerAppsEnvironmentHeartbeatData,
311    "azure_service_bus_namespace" => AzureServiceBusNamespaceHeartbeatData,
312    "ai" => AiHeartbeatData,
313    "key" => KeyHeartbeatData,
314    "sandbox" => SandboxHeartbeatData,
315}
316
317/// The heartbeat of a resource whose type an extension defines.
318#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
319#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
320#[serde(rename_all = "camelCase")]
321pub struct CustomHeartbeat {
322    #[cfg_attr(feature = "openapi", schema(value_type = CustomResourceType))]
323    pub resource_type: ResourceType,
324    pub data: CustomHeartbeatData,
325}
326
327/// The schema of `CustomHeartbeat.resource_type`. The pattern repeats `is_custom_resource_type`:
328/// without it, a union validator that tries the custom variant first reads a built-in heartbeat
329/// as custom and drops its fields. The TypeScript generators (`kubb.config.ts`) map this schema
330/// name to a `${string}/${string}` template literal, so a check like `resourceType === "ai"`
331/// still narrows the union.
332#[cfg(feature = "openapi")]
333pub(crate) struct CustomResourceType;
334
335#[cfg(feature = "openapi")]
336impl utoipa::PartialSchema for CustomResourceType {
337    fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
338        utoipa::openapi::ObjectBuilder::new()
339            .schema_type(utoipa::openapi::Type::String)
340            .pattern(Some("^(?!(?:alien|experimental)/)[^/]+/.+$"))
341            .description(Some(
342                "The type of a resource an extension defines, such as `acme/dns-zone`.",
343            ))
344            .into()
345    }
346}
347
348#[cfg(feature = "openapi")]
349impl utoipa::ToSchema for CustomResourceType {}
350
351#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
352#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
353#[serde(rename_all = "camelCase")]
354pub struct CustomHeartbeatData {
355    pub status: CustomHeartbeatStatus,
356    /// Type-specific fields the extension's controller reports, which Alien does not read.
357    #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
358    pub details: BTreeMap<String, JsonValue>,
359}
360
361/// The status fields every heartbeat carries, so a custom heartbeat's health reads like a
362/// built-in one's.
363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
364#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
365#[serde(rename_all = "camelCase")]
366pub struct CustomHeartbeatStatus {
367    pub health: ObservedHealth,
368    pub lifecycle: ProviderLifecycleState,
369    pub message: Option<String>,
370    pub stale: bool,
371    pub partial: bool,
372    pub collection_issues: Vec<HeartbeatCollectionIssue>,
373}
374
375#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
376#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
377#[serde(rename_all = "kebab-case")]
378pub enum ObservedHealth {
379    Unknown,
380    Healthy,
381    Degraded,
382    Unhealthy,
383}
384
385#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
386#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
387#[serde(rename_all = "kebab-case")]
388pub enum ProviderLifecycleState {
389    Unknown,
390    Creating,
391    Updating,
392    Running,
393    Scaling,
394    Stopping,
395    Stopped,
396    Deleting,
397    Deleted,
398    Failed,
399}
400
401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
402#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
403#[serde(rename_all = "camelCase")]
404pub struct KeyHeartbeatStatus {
405    pub health: ObservedHealth,
406    pub lifecycle: ProviderLifecycleState,
407    pub message: Option<String>,
408}
409
410#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
411#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
412#[serde(tag = "provider", content = "data", rename_all = "kebab-case")]
413pub enum KeyHeartbeatData {
414    AwsKms(AwsKmsKeyHeartbeatData),
415    GcpCloudKms(GcpCloudKmsKeyHeartbeatData),
416    AzureKeyVault(AzureKeyVaultKeyHeartbeatData),
417}
418
419#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
420#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
421#[serde(rename_all = "camelCase")]
422pub struct AwsKmsKeyHeartbeatData {
423    pub status: KeyHeartbeatStatus,
424    pub key_arn: String,
425    pub key_state: String,
426    pub enabled: bool,
427    pub key_spec: String,
428    pub key_usage: String,
429}
430
431#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
432#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
433#[serde(rename_all = "camelCase")]
434pub struct GcpCloudKmsKeyHeartbeatData {
435    pub status: KeyHeartbeatStatus,
436    pub crypto_key_name: String,
437    pub purpose: String,
438    pub primary_version: Option<String>,
439    pub primary_state: Option<String>,
440    pub algorithm: Option<String>,
441}
442
443#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
444#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
445#[serde(rename_all = "camelCase")]
446pub struct AzureKeyVaultKeyHeartbeatData {
447    pub status: KeyHeartbeatStatus,
448    pub key_id: String,
449    pub enabled: Option<bool>,
450    pub key_type: String,
451    pub key_operations: Vec<String>,
452    pub recovery_level: Option<String>,
453}
454
455#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
456#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
457#[serde(rename_all = "camelCase")]
458pub struct HeartbeatCollectionIssue {
459    pub source: String,
460    pub reason: HeartbeatCollectionIssueReason,
461    pub severity: HeartbeatIssueSeverity,
462    pub message: String,
463}
464
465#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
466#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
467#[serde(rename_all = "kebab-case")]
468pub enum HeartbeatIssueSeverity {
469    Info,
470    Warning,
471    Error,
472}
473
474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
475#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
476#[serde(rename_all = "camelCase")]
477pub struct KubernetesEventSnapshot {
478    pub reason: String,
479    #[serde(rename = "type")]
480    pub type_: Option<String>,
481    pub message: String,
482    pub count: Option<i32>,
483    pub first_timestamp: Option<DateTime<Utc>>,
484    pub last_timestamp: Option<DateTime<Utc>>,
485    pub event_time: Option<DateTime<Utc>>,
486    pub source: Option<KubernetesEventSource>,
487    pub involved_object: Option<KubernetesEventInvolvedObject>,
488    pub raw: Option<JsonValue>,
489}
490
491#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
492#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
493#[serde(rename_all = "camelCase")]
494pub struct KubernetesEventSource {
495    pub component: Option<String>,
496    pub host: Option<String>,
497}
498
499#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
500#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
501#[serde(rename_all = "camelCase")]
502pub struct KubernetesEventInvolvedObject {
503    pub kind: Option<String>,
504    pub namespace: Option<String>,
505    pub name: Option<String>,
506    pub uid: Option<String>,
507    pub api_version: Option<String>,
508    pub resource_version: Option<String>,
509    pub field_path: Option<String>,
510}
511
512#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
513#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
514#[serde(rename_all = "camelCase")]
515pub struct ManagedRuntimeEventSnapshot {
516    pub event_id: Option<String>,
517    pub reason: String,
518    #[serde(rename = "type")]
519    pub type_: Option<String>,
520    pub message: String,
521    pub count: Option<i32>,
522    pub first_timestamp: Option<DateTime<Utc>>,
523    pub last_timestamp: Option<DateTime<Utc>>,
524    pub event_time: Option<DateTime<Utc>>,
525    pub source: Option<ManagedRuntimeEventSource>,
526    pub involved_object: Option<ManagedRuntimeEventInvolvedObject>,
527    pub details: Option<JsonValue>,
528    pub raw: Option<JsonValue>,
529}
530
531#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
532#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
533#[serde(rename_all = "camelCase")]
534pub struct ManagedRuntimeEventSource {
535    pub component: Option<String>,
536    pub host: Option<String>,
537}
538
539#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
540#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
541#[serde(rename_all = "camelCase")]
542pub struct ManagedRuntimeEventInvolvedObject {
543    pub kind: Option<String>,
544    pub id: Option<String>,
545    pub name: Option<String>,
546    pub replica_id: Option<String>,
547    pub machine_id: Option<String>,
548    pub details: Option<JsonValue>,
549}
550
551#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
552#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
553#[serde(rename_all = "camelCase")]
554pub struct LocalRuntimeEventSnapshot {
555    pub timestamp: DateTime<Utc>,
556    pub severity: HeartbeatIssueSeverity,
557    pub kind: String,
558    pub message: String,
559    pub subject: Option<LocalRuntimeEventSubject>,
560    pub raw: Option<JsonValue>,
561}
562
563#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
564#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
565#[serde(rename_all = "camelCase")]
566pub struct LocalRuntimeEventSubject {
567    pub kind: String,
568    pub id: Option<String>,
569    pub name: Option<String>,
570}
571
572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
573#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
574#[serde(rename_all = "camelCase")]
575pub struct RawHeartbeatSnippet {
576    pub source: String,
577    pub format: RawHeartbeatSnippetFormat,
578    pub collected_at: DateTime<Utc>,
579    pub body: String,
580    pub truncated: bool,
581}
582
583#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
584#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
585#[serde(rename_all = "kebab-case")]
586pub enum RawHeartbeatSnippetFormat {
587    Json,
588    Yaml,
589    Text,
590}
591
592#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
593#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
594#[serde(rename_all = "camelCase")]
595pub struct ObservedCounts {
596    pub desired: Option<u32>,
597    pub current: Option<u32>,
598    pub ready: Option<u32>,
599}
600
601#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
602#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
603#[serde(rename_all = "camelCase")]
604pub struct MetricSample {
605    pub value: f64,
606    pub unit: MetricUnit,
607}
608
609#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
610#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
611#[serde(rename_all = "kebab-case")]
612pub enum MetricUnit {
613    Count,
614    Percent,
615    Bytes,
616    Cores,
617    Milliseconds,
618    RequestsPerSecond,
619}
620
621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
622#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
623#[serde(tag = "backend", rename_all = "camelCase")]
624pub enum StorageHeartbeatData {
625    AwsS3(AwsS3StorageHeartbeatData),
626    GcpCloudStorage(GcpCloudStorageHeartbeatData),
627    AzureBlob(AzureBlobStorageHeartbeatData),
628    Local(LocalStorageHeartbeatData),
629}
630
631#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
632#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
633#[serde(rename_all = "camelCase")]
634pub struct StorageHeartbeatStatus {
635    pub health: ObservedHealth,
636    pub lifecycle: ProviderLifecycleState,
637    pub message: Option<String>,
638    pub stale: bool,
639    pub partial: bool,
640    pub collection_issues: Vec<HeartbeatCollectionIssue>,
641}
642
643#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
644#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
645#[serde(rename_all = "camelCase")]
646pub struct AwsS3StorageHeartbeatData {
647    pub status: StorageHeartbeatStatus,
648    pub name: String,
649    pub region: Option<String>,
650    pub bucket_location: Option<String>,
651    pub versioning_status: Option<String>,
652    pub versioning_enabled: Option<bool>,
653    pub lifecycle_present: bool,
654    pub lifecycle_rule_count: Option<u64>,
655    pub encryption_config_present: bool,
656    pub encryption_enabled: Option<bool>,
657    pub public_access_block_present: bool,
658    pub block_public_acls: Option<bool>,
659    pub ignore_public_acls: Option<bool>,
660    pub block_public_policy: Option<bool>,
661    pub restrict_public_buckets: Option<bool>,
662    pub bucket_policy_present: Option<bool>,
663    pub bucket_acl_present: Option<bool>,
664}
665
666#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
667#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
668#[serde(rename_all = "camelCase")]
669pub struct AzureBlobStorageHeartbeatData {
670    pub status: StorageHeartbeatStatus,
671    pub name: String,
672    pub storage_account_name: Option<String>,
673    pub resource_group: Option<String>,
674    pub location: Option<String>,
675    pub account_kind: Option<String>,
676    pub sku_name: Option<String>,
677    pub sku_tier: Option<String>,
678    pub access_tier: Option<String>,
679    pub provisioning_state: Option<String>,
680    pub primary_location: Option<String>,
681    pub secondary_location: Option<String>,
682    pub status_of_primary: Option<String>,
683    pub status_of_secondary: Option<String>,
684    pub public_network_access: Option<String>,
685    pub allow_blob_public_access: Option<bool>,
686    pub encryption_key_source: Option<String>,
687    pub blob_encryption_enabled: Option<bool>,
688    pub file_encryption_enabled: Option<bool>,
689    pub queue_encryption_enabled: Option<bool>,
690    pub table_encryption_enabled: Option<bool>,
691    pub blob_versioning_enabled: Option<bool>,
692    pub blob_delete_retention_enabled: Option<bool>,
693    pub blob_delete_retention_days: Option<u64>,
694    pub container_delete_retention_enabled: Option<bool>,
695    pub container_delete_retention_days: Option<u64>,
696    pub change_feed_enabled: Option<bool>,
697    pub change_feed_retention_days: Option<u64>,
698    pub container_public_access: Option<String>,
699}
700
701#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
702#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
703#[serde(rename_all = "camelCase")]
704pub struct GcpCloudStorageHeartbeatData {
705    pub status: StorageHeartbeatStatus,
706    pub name: String,
707    pub bucket_id: Option<String>,
708    pub location: Option<String>,
709    pub location_type: Option<String>,
710    pub storage_class: Option<String>,
711    pub versioning_enabled: Option<bool>,
712    pub lifecycle_present: bool,
713    pub lifecycle_rule_count: Option<u64>,
714    pub retention_policy_effective_time: Option<String>,
715    pub retention_policy_is_locked: Option<bool>,
716    pub retention_period: Option<String>,
717    pub soft_delete_retention_duration_seconds: Option<String>,
718    pub soft_delete_effective_time: Option<String>,
719    pub uniform_bucket_level_access_enabled: Option<bool>,
720    pub uniform_bucket_level_access_locked_time: Option<String>,
721    pub public_access_prevention: Option<String>,
722    pub encryption_config_present: bool,
723    pub default_kms_key_name: Option<String>,
724}
725
726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
727#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
728#[serde(rename_all = "camelCase")]
729pub struct LocalStorageHeartbeatData {
730    pub status: StorageHeartbeatStatus,
731    pub path: String,
732    pub path_exists: bool,
733    pub is_directory: Option<bool>,
734    pub readonly: Option<bool>,
735    pub modified_at: Option<DateTime<Utc>>,
736}
737
738#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
739#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
740#[serde(tag = "backend", rename_all = "camelCase")]
741pub enum WorkerHeartbeatData {
742    AwsLambda(AwsLambdaWorkerHeartbeatData),
743    GcpCloudRun(GcpCloudRunWorkerHeartbeatData),
744    AzureContainerApps(AzureContainerAppsWorkerHeartbeatData),
745    Kubernetes(KubernetesWorkerHeartbeatData),
746    Local(LocalWorkerHeartbeatData),
747}
748
749#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
750#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
751#[serde(tag = "backend", rename_all = "camelCase")]
752pub enum ContainerHeartbeatData {
753    HorizonPlatform(HorizonContainerHeartbeatData),
754    Kubernetes(KubernetesContainerHeartbeatData),
755    Local(LocalContainerHeartbeatData),
756}
757
758#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
759#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
760#[serde(tag = "backend", rename_all = "camelCase")]
761pub enum DaemonHeartbeatData {
762    Aws(AwsDaemonHeartbeatData),
763    Gcp(GcpDaemonHeartbeatData),
764    Azure(AzureDaemonHeartbeatData),
765    Machines(MachinesDaemonHeartbeatData),
766    Kubernetes(KubernetesDaemonHeartbeatData),
767    Local(LocalDaemonHeartbeatData),
768}
769
770#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
771#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
772#[serde(rename_all = "camelCase")]
773pub struct WorkloadHeartbeatStatus {
774    pub health: ObservedHealth,
775    pub lifecycle: ProviderLifecycleState,
776    pub message: Option<String>,
777    pub stale: bool,
778    pub partial: bool,
779    pub collection_issues: Vec<HeartbeatCollectionIssue>,
780}
781
782#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
783#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
784#[serde(rename_all = "camelCase")]
785pub struct WorkloadReplicaStatus {
786    pub desired: Option<u32>,
787    pub current: Option<u32>,
788    pub ready: Option<u32>,
789    pub available: Option<u32>,
790    pub updated: Option<u32>,
791    pub misscheduled: Option<u32>,
792}
793
794#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
795#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
796#[serde(rename_all = "camelCase")]
797pub struct AwsLambdaWorkerHeartbeatData {
798    pub status: WorkloadHeartbeatStatus,
799    pub function_name: String,
800    pub runtime: Option<String>,
801    pub package_type: Option<String>,
802    pub memory_size_mb: Option<i64>,
803    pub timeout_seconds: Option<i64>,
804    pub version: Option<String>,
805    pub revision_id: Option<String>,
806    pub last_modified: Option<String>,
807    pub state: Option<String>,
808    pub state_reason: Option<String>,
809    pub state_reason_code: Option<String>,
810    pub last_update_status: Option<String>,
811    pub last_update_status_reason: Option<String>,
812    pub last_update_status_reason_code: Option<String>,
813    pub code_sha256: Option<String>,
814    pub layer_count: u32,
815    pub function_url_auth_type: Option<String>,
816    pub function_url_cors_present: bool,
817    pub trigger_count: u32,
818}
819
820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
821#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
822#[serde(rename_all = "camelCase")]
823pub struct GcpCloudRunWorkerHeartbeatData {
824    pub status: WorkloadHeartbeatStatus,
825    pub service: String,
826    pub region: Option<String>,
827    pub uri: Option<String>,
828    pub urls: Vec<String>,
829    pub latest_created_revision: Option<String>,
830    pub latest_ready_revision: Option<String>,
831    pub generation: Option<i64>,
832    pub observed_generation: Option<i64>,
833    pub traffic_count: u32,
834    pub min_instance_count: Option<i32>,
835    pub max_instance_count: Option<i32>,
836    pub container_image: Option<String>,
837    pub cpu_limit: Option<String>,
838    pub memory_limit: Option<String>,
839}
840
841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
842#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
843#[serde(rename_all = "camelCase")]
844pub struct AzureContainerAppsWorkerHeartbeatData {
845    pub status: WorkloadHeartbeatStatus,
846    pub app_name: String,
847    pub revision: Option<String>,
848    pub environment_name: Option<String>,
849    pub provisioning_state: Option<String>,
850    pub running_status: Option<String>,
851    pub ingress_fqdn: Option<String>,
852    pub min_replicas: Option<i32>,
853    pub max_replicas: Option<i32>,
854    pub cpu: Option<f64>,
855    pub memory: Option<String>,
856}
857
858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
859#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
860#[serde(rename_all = "camelCase")]
861pub struct KubernetesWorkerHeartbeatData {
862    pub status: WorkloadHeartbeatStatus,
863    pub namespace: String,
864    pub name: String,
865    pub workload_kind: KubernetesWorkloadKind,
866    pub replicas: WorkloadReplicaStatus,
867    pub restarts: Option<u32>,
868    pub cpu: Option<MetricSample>,
869    pub memory: Option<MetricSample>,
870    pub workload: Option<KubernetesWorkloadStatus>,
871    pub pods: Vec<KubernetesPodRuntimeUnitStatus>,
872    pub trigger_count: u32,
873    pub events: Vec<KubernetesEventSnapshot>,
874}
875
876#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
877#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
878#[serde(rename_all = "camelCase")]
879pub struct LocalWorkerHeartbeatData {
880    pub status: WorkloadHeartbeatStatus,
881    pub pid: Option<u32>,
882    pub command_supported: bool,
883    pub image_path_present: bool,
884    pub readiness_probe_ok: Option<bool>,
885    pub trigger_count: u32,
886    pub cpu: Option<MetricSample>,
887    pub memory: Option<MetricSample>,
888    pub process: Option<LocalRuntimeUnitStatus>,
889    pub events: Vec<LocalRuntimeEventSnapshot>,
890}
891
892#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
893#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
894#[serde(rename_all = "camelCase")]
895pub struct HorizonContainerHeartbeatData {
896    pub status: WorkloadHeartbeatStatus,
897    pub container_id: String,
898    pub image: Option<String>,
899    #[serde(default)]
900    pub observed_image: Option<String>,
901    #[serde(default)]
902    pub latest_update_timestamp: Option<String>,
903    pub scheduling_mode: HorizonWorkloadSchedulingMode,
904    pub replicas: WorkloadReplicaStatus,
905    pub cpu: Option<MetricSample>,
906    pub memory: Option<MetricSample>,
907    pub attention_count: u32,
908    pub replica_units: Vec<ManagedRuntimeUnitStatus>,
909    pub events: Vec<ManagedRuntimeEventSnapshot>,
910}
911
912#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
913#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
914#[serde(rename_all = "camelCase")]
915pub enum HorizonWorkloadSchedulingMode {
916    Replicated,
917    Stateful,
918    Daemon,
919}
920
921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
922#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
923#[serde(rename_all = "camelCase")]
924pub struct KubernetesContainerHeartbeatData {
925    pub status: WorkloadHeartbeatStatus,
926    pub namespace: String,
927    pub name: String,
928    pub workload_kind: KubernetesWorkloadKind,
929    pub replicas: WorkloadReplicaStatus,
930    pub restarts: Option<u32>,
931    pub cpu: Option<MetricSample>,
932    pub memory: Option<MetricSample>,
933    pub workload: Option<KubernetesWorkloadStatus>,
934    pub pods: Vec<KubernetesPodRuntimeUnitStatus>,
935    pub events: Vec<KubernetesEventSnapshot>,
936}
937
938#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
939#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
940#[serde(rename_all = "camelCase")]
941pub struct LocalContainerHeartbeatData {
942    pub status: WorkloadHeartbeatStatus,
943    pub container_id: Option<String>,
944    pub name: Option<String>,
945    pub image: Option<String>,
946    pub runtime_status: Option<String>,
947    pub restart_count: Option<u32>,
948    pub port_count: u32,
949    pub bind_mount_count: u32,
950    pub local_url: Option<String>,
951    pub runtime_reachable: bool,
952    pub cpu: Option<MetricSample>,
953    pub memory: Option<MetricSample>,
954    pub container_unit: Option<LocalRuntimeUnitStatus>,
955    pub events: Vec<LocalRuntimeEventSnapshot>,
956}
957
958#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
959#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
960#[serde(rename_all = "camelCase")]
961pub struct AwsDaemonHeartbeatData {
962    pub status: WorkloadHeartbeatStatus,
963    pub horizon_cluster_id: String,
964    #[serde(default)]
965    pub daemon_name: String,
966    pub horizon_status: String,
967    pub horizon_status_reason: Option<String>,
968    pub horizon_status_message: Option<String>,
969    pub capacity_group: String,
970    pub desired_machines: u32,
971    pub assigned_machines: u32,
972    pub healthy_instances: u32,
973    pub unavailable_instances: u32,
974    pub command_supported: bool,
975    #[serde(default)]
976    pub observed_image: Option<String>,
977    pub latest_update_timestamp: String,
978    pub daemon_instances: Vec<ManagedRuntimeUnitStatus>,
979    pub events: Vec<ManagedRuntimeEventSnapshot>,
980}
981
982#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
983#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
984#[serde(rename_all = "camelCase")]
985pub struct GcpDaemonHeartbeatData {
986    pub status: WorkloadHeartbeatStatus,
987    pub horizon_cluster_id: String,
988    #[serde(default)]
989    pub daemon_name: String,
990    pub horizon_status: String,
991    pub horizon_status_reason: Option<String>,
992    pub horizon_status_message: Option<String>,
993    pub capacity_group: String,
994    pub desired_machines: u32,
995    pub assigned_machines: u32,
996    pub healthy_instances: u32,
997    pub unavailable_instances: u32,
998    pub command_supported: bool,
999    #[serde(default)]
1000    pub observed_image: Option<String>,
1001    pub latest_update_timestamp: String,
1002    pub daemon_instances: Vec<ManagedRuntimeUnitStatus>,
1003    pub events: Vec<ManagedRuntimeEventSnapshot>,
1004}
1005
1006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1007#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1008#[serde(rename_all = "camelCase")]
1009pub struct AzureDaemonHeartbeatData {
1010    pub status: WorkloadHeartbeatStatus,
1011    pub horizon_cluster_id: String,
1012    #[serde(default)]
1013    pub daemon_name: String,
1014    pub horizon_status: String,
1015    pub horizon_status_reason: Option<String>,
1016    pub horizon_status_message: Option<String>,
1017    pub capacity_group: String,
1018    pub desired_machines: u32,
1019    pub assigned_machines: u32,
1020    pub healthy_instances: u32,
1021    pub unavailable_instances: u32,
1022    pub command_supported: bool,
1023    #[serde(default)]
1024    pub observed_image: Option<String>,
1025    pub latest_update_timestamp: String,
1026    pub daemon_instances: Vec<ManagedRuntimeUnitStatus>,
1027    pub events: Vec<ManagedRuntimeEventSnapshot>,
1028}
1029
1030#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1031#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1032#[serde(rename_all = "camelCase")]
1033pub struct MachinesDaemonHeartbeatData {
1034    pub status: WorkloadHeartbeatStatus,
1035    pub horizon_cluster_id: String,
1036    #[serde(default)]
1037    pub daemon_name: String,
1038    pub horizon_status: String,
1039    pub horizon_status_reason: Option<String>,
1040    pub horizon_status_message: Option<String>,
1041    pub capacity_group: String,
1042    pub desired_machines: u32,
1043    pub assigned_machines: u32,
1044    pub healthy_instances: u32,
1045    pub unavailable_instances: u32,
1046    pub command_supported: bool,
1047    #[serde(default)]
1048    pub observed_image: Option<String>,
1049    pub latest_update_timestamp: String,
1050    pub daemon_instances: Vec<ManagedRuntimeUnitStatus>,
1051    pub events: Vec<ManagedRuntimeEventSnapshot>,
1052}
1053
1054#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1055#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1056#[serde(rename_all = "camelCase")]
1057pub struct ManagedRuntimeUnitStatus {
1058    pub replica_id: String,
1059    pub name: String,
1060    pub machine_id: Option<String>,
1061    pub node_name: Option<String>,
1062    pub ip: Option<String>,
1063    pub ready: bool,
1064    pub phase: Option<String>,
1065    pub status: Option<String>,
1066    pub reason: Option<String>,
1067    pub message: Option<String>,
1068    pub restart_count: Option<u32>,
1069    pub waiting_reason: Option<String>,
1070    pub terminated_reason: Option<String>,
1071    pub metrics_healthy: Option<bool>,
1072    pub metrics_status: Option<String>,
1073    pub metrics_last_updated: Option<String>,
1074    pub cpu: Option<MetricSample>,
1075    pub memory: Option<MetricSample>,
1076    /// Image this replica runs.
1077    #[serde(default)]
1078    pub image: Option<String>,
1079}
1080
1081#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1082#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1083#[serde(rename_all = "camelCase")]
1084pub struct KubernetesDaemonHeartbeatData {
1085    pub status: WorkloadHeartbeatStatus,
1086    pub namespace: String,
1087    pub name: String,
1088    pub replicas: WorkloadReplicaStatus,
1089    pub restarts: Option<u32>,
1090    pub command_supported: bool,
1091    pub cpu: Option<MetricSample>,
1092    pub memory: Option<MetricSample>,
1093    pub workload: Option<KubernetesWorkloadStatus>,
1094    pub pods: Vec<KubernetesPodRuntimeUnitStatus>,
1095    pub events: Vec<KubernetesEventSnapshot>,
1096}
1097
1098#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1099#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1100#[serde(rename_all = "camelCase")]
1101pub struct LocalDaemonHeartbeatData {
1102    pub status: WorkloadHeartbeatStatus,
1103    #[serde(default)]
1104    pub daemon_name: String,
1105    pub runtime_id: String,
1106    pub pid: Option<u32>,
1107    pub command_supported: bool,
1108    pub image_path_present: bool,
1109    pub restart_count: Option<u32>,
1110    pub exit_reason: Option<String>,
1111    pub daemon_instance: Option<LocalRuntimeUnitStatus>,
1112    pub events: Vec<LocalRuntimeEventSnapshot>,
1113}
1114
1115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1116#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1117#[serde(rename_all = "camelCase")]
1118pub struct LocalRuntimeUnitStatus {
1119    pub unit_id: String,
1120    pub name: String,
1121    pub kind: LocalRuntimeUnitKind,
1122    pub ready: bool,
1123    pub phase: Option<String>,
1124    pub pid: Option<u32>,
1125    pub restart_count: Option<u32>,
1126    pub cpu: Option<MetricSample>,
1127    pub memory: Option<MetricSample>,
1128}
1129
1130#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1131#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1132#[serde(rename_all = "kebab-case")]
1133pub enum LocalRuntimeUnitKind {
1134    Container,
1135    Process,
1136    Daemon,
1137}
1138
1139#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1140#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1141#[serde(rename_all = "camelCase")]
1142pub enum KubernetesWorkloadKind {
1143    Deployment,
1144    StatefulSet,
1145    DaemonSet,
1146    ReplicaSet,
1147    Pod,
1148}
1149
1150#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1151#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1152#[serde(rename_all = "camelCase")]
1153pub struct KubernetesWorkloadStatus {
1154    pub desired_replicas: Option<u32>,
1155    pub ready_replicas: Option<u32>,
1156    pub available_replicas: Option<u32>,
1157    pub updated_replicas: Option<u32>,
1158    pub observed_generation: Option<i64>,
1159    pub desired_generation: Option<i64>,
1160    pub rollout_reason: Option<String>,
1161    pub conditions: Vec<KubernetesWorkloadCondition>,
1162}
1163
1164#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1165#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1166#[serde(rename_all = "camelCase")]
1167pub struct KubernetesWorkloadCondition {
1168    #[serde(rename = "type")]
1169    pub condition_type: String,
1170    pub status: String,
1171    pub reason: Option<String>,
1172    pub message: Option<String>,
1173    pub last_transition_time: Option<DateTime<Utc>>,
1174}
1175
1176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1177#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1178#[serde(rename_all = "camelCase")]
1179pub struct KubernetesPodRuntimeUnitStatus {
1180    pub name: String,
1181    pub uid: Option<String>,
1182    pub phase: Option<String>,
1183    pub ready: bool,
1184    pub restart_count: u32,
1185    pub waiting_reason: Option<String>,
1186    pub terminated_reason: Option<String>,
1187    pub node_name: Option<String>,
1188    pub pod_ip: Option<String>,
1189    pub owner_references: Vec<KubernetesOwnerReference>,
1190    pub cpu: Option<MetricSample>,
1191    pub memory: Option<MetricSample>,
1192    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1193    pub containers: Vec<ContainerImageIdentity>,
1194}
1195
1196#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1197#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1198#[serde(rename_all = "camelCase")]
1199pub struct KubernetesOwnerReference {
1200    pub kind: String,
1201    pub name: String,
1202    pub uid: String,
1203    pub controller: bool,
1204}
1205
1206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1207#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1208#[serde(tag = "backend", rename_all = "camelCase")]
1209pub enum ComputeClusterHeartbeatData {
1210    Aws(AwsComputeClusterHeartbeatData),
1211    Gcp(GcpComputeClusterHeartbeatData),
1212    Azure(AzureComputeClusterHeartbeatData),
1213    Machines(MachinesComputeClusterHeartbeatData),
1214    Local(LocalComputeClusterHeartbeatData),
1215}
1216
1217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1218#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1219#[serde(rename_all = "camelCase")]
1220pub struct ComputeClusterHeartbeatStatus {
1221    pub health: ObservedHealth,
1222    pub lifecycle: ProviderLifecycleState,
1223    pub message: Option<String>,
1224    pub stale: bool,
1225    pub partial: bool,
1226    pub collection_issues: Vec<HeartbeatCollectionIssue>,
1227}
1228
1229#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1230#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1231#[serde(rename_all = "camelCase")]
1232pub struct LocalComputeClusterHeartbeatData {
1233    pub status: ComputeClusterHeartbeatStatus,
1234    pub nodes: ObservedCounts,
1235    pub name: String,
1236    pub host_identifier: Option<String>,
1237    pub docker_available: bool,
1238    pub docker_version: Option<String>,
1239    pub docker_api_version: Option<String>,
1240    pub docker_os: Option<String>,
1241    pub docker_arch: Option<String>,
1242    pub network_name: Option<String>,
1243    pub network_available: bool,
1244    pub tracked_containers: Option<u32>,
1245    pub running_containers: Option<u32>,
1246}
1247
1248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1249#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1250#[serde(rename_all = "camelCase")]
1251pub struct AwsComputeClusterHeartbeatData {
1252    pub status: ComputeClusterHeartbeatStatus,
1253    pub nodes: ObservedCounts,
1254    pub cpu: Option<MetricSample>,
1255    pub memory: Option<MetricSample>,
1256    pub name: String,
1257    pub region: Option<String>,
1258    pub backend_cluster_id: Option<String>,
1259    pub capacity_groups: Vec<ComputeCapacityGroupStatus>,
1260    pub provider_fleets: Vec<ProviderFleetStatus>,
1261}
1262
1263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1264#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1265#[serde(rename_all = "camelCase")]
1266pub struct GcpComputeClusterHeartbeatData {
1267    pub status: ComputeClusterHeartbeatStatus,
1268    pub nodes: ObservedCounts,
1269    pub cpu: Option<MetricSample>,
1270    pub memory: Option<MetricSample>,
1271    pub name: String,
1272    pub region: Option<String>,
1273    pub backend_cluster_id: Option<String>,
1274    pub capacity_groups: Vec<ComputeCapacityGroupStatus>,
1275    pub provider_fleets: Vec<ProviderFleetStatus>,
1276}
1277
1278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1279#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1280#[serde(rename_all = "camelCase")]
1281pub struct AzureComputeClusterHeartbeatData {
1282    pub status: ComputeClusterHeartbeatStatus,
1283    pub nodes: ObservedCounts,
1284    pub cpu: Option<MetricSample>,
1285    pub memory: Option<MetricSample>,
1286    pub name: String,
1287    pub region: Option<String>,
1288    pub backend_cluster_id: Option<String>,
1289    pub capacity_groups: Vec<ComputeCapacityGroupStatus>,
1290    pub provider_fleets: Vec<ProviderFleetStatus>,
1291}
1292
1293#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1294#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1295#[serde(rename_all = "camelCase")]
1296pub struct MachinesComputeClusterHeartbeatData {
1297    pub status: ComputeClusterHeartbeatStatus,
1298    pub nodes: ObservedCounts,
1299    pub cpu: Option<MetricSample>,
1300    pub memory: Option<MetricSample>,
1301    pub name: String,
1302    pub backend_cluster_id: Option<String>,
1303    pub capacity_groups: Vec<ComputeCapacityGroupStatus>,
1304    pub machines: Vec<MachinesComputeMachineStatus>,
1305}
1306
1307#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1308#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1309#[serde(rename_all = "camelCase")]
1310pub struct MachinesComputeMachineStatus {
1311    pub machine_id: String,
1312    pub status: String,
1313    pub capacity_group: String,
1314    pub zone: String,
1315    pub public_ip: Option<String>,
1316    pub overlay_ip: Option<String>,
1317    pub last_heartbeat: String,
1318    pub horizond_version: Option<String>,
1319    pub replica_count: i64,
1320    pub cpu_cores: Option<f64>,
1321    pub memory_bytes: Option<i64>,
1322    pub drain_force: bool,
1323    pub drain_requested_at: Option<String>,
1324    pub drain_deadline_at: Option<String>,
1325    pub drained_at: Option<String>,
1326    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1327    pub drain_blockers: Vec<ComputeDrainBlocker>,
1328}
1329
1330#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1331#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1332#[serde(rename_all = "camelCase")]
1333pub struct ComputeCapacityGroupStatus {
1334    pub group_id: String,
1335    pub current_machines: u32,
1336    pub desired_machines: u32,
1337    pub min_machines: Option<u32>,
1338    pub max_machines: Option<u32>,
1339    pub instance_type: Option<String>,
1340    pub recommendation: Option<ComputeCapacityRecommendation>,
1341    pub capacity_blocker: Option<ComputeCapacityBlocker>,
1342    #[serde(default, skip_serializing_if = "Option::is_none")]
1343    pub drain_progress: Option<ComputeDrainProgress>,
1344}
1345
1346#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1347#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1348#[serde(rename_all = "camelCase")]
1349pub enum ComputeCapacityBlockerCategory {
1350    Quota,
1351    Capacity,
1352    Allocation,
1353    Other,
1354}
1355
1356#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1357#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1358#[serde(rename_all = "camelCase")]
1359pub struct ComputeCapacityBlocker {
1360    pub category: ComputeCapacityBlockerCategory,
1361    pub provider_code: Option<String>,
1362    pub message: String,
1363    pub provider_reference: Option<String>,
1364    pub observed_at: DateTime<Utc>,
1365}
1366
1367#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1368#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1369#[serde(rename_all = "camelCase")]
1370pub struct ComputeCapacityRecommendation {
1371    pub desired_machines: u32,
1372    pub reason: Option<String>,
1373    pub utilization: Option<MetricSample>,
1374    pub unschedulable_replicas: Option<u32>,
1375}
1376
1377#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
1378#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1379#[serde(rename_all = "camelCase")]
1380pub enum ComputeDrainProgressStatus {
1381    Draining,
1382    Drained,
1383    Terminating,
1384}
1385
1386#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1387#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1388#[serde(rename_all = "camelCase")]
1389pub struct ComputeDrainBlocker {
1390    pub workload_name: String,
1391    pub replica_id: String,
1392    pub scheduling_mode: String,
1393    pub state: String,
1394    pub reason: String,
1395}
1396
1397#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1398#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1399#[serde(rename_all = "camelCase")]
1400pub struct ComputeDrainProgress {
1401    pub machine_id: String,
1402    pub status: ComputeDrainProgressStatus,
1403    pub replica_count: i64,
1404    pub force: bool,
1405    pub stalled: bool,
1406    pub drain_requested_at: Option<String>,
1407    pub drain_deadline_at: Option<String>,
1408    pub drained_at: Option<String>,
1409    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1410    pub blockers: Vec<ComputeDrainBlocker>,
1411}
1412
1413#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1414#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1415#[serde(rename_all = "camelCase")]
1416pub struct ProviderFleetStatus {
1417    pub group_id: String,
1418    pub provider_id: String,
1419    pub location: Option<String>,
1420    pub current_machines: u32,
1421    pub desired_machines: u32,
1422}
1423
1424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1425#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1426#[serde(rename_all = "camelCase")]
1427pub struct KubernetesClusterHeartbeatData {
1428    pub status: WorkloadHeartbeatStatus,
1429    pub node_counts: ObservedCounts,
1430    pub pod_counts: ObservedCounts,
1431    pub cpu: Option<MetricSample>,
1432    pub memory: Option<MetricSample>,
1433    pub name: String,
1434    pub region: Option<String>,
1435    pub namespace: Option<String>,
1436    pub version: Option<String>,
1437    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1438    pub node_statuses: Vec<KubernetesClusterNodeStatus>,
1439    pub events: Vec<KubernetesEventSnapshot>,
1440}
1441
1442#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1443#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1444#[serde(rename_all = "camelCase")]
1445pub struct KubernetesClusterNodeStatus {
1446    pub name: String,
1447    pub uid: Option<String>,
1448    pub ready: bool,
1449    #[serde(default, skip_serializing_if = "Vec::is_empty")]
1450    pub conditions: Vec<KubernetesNodeConditionStatus>,
1451    pub roles: Vec<String>,
1452    pub labels: BTreeMap<String, String>,
1453    pub allocatable: KubernetesNodeResources,
1454    pub capacity: KubernetesNodeResources,
1455    pub usage: Option<KubernetesNodeUsage>,
1456    pub kubelet_version: Option<String>,
1457    pub container_runtime_version: Option<String>,
1458}
1459
1460#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1461#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1462#[serde(rename_all = "camelCase")]
1463pub struct KubernetesNodeConditionStatus {
1464    pub type_: String,
1465    pub status: String,
1466    pub reason: Option<String>,
1467    pub message: Option<String>,
1468}
1469
1470#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
1471#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1472#[serde(rename_all = "camelCase")]
1473pub struct KubernetesNodeResources {
1474    pub cpu: Option<MetricSample>,
1475    pub memory: Option<MetricSample>,
1476    pub pods: Option<u64>,
1477}
1478
1479#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1480#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1481#[serde(rename_all = "camelCase")]
1482pub struct KubernetesNodeUsage {
1483    pub cpu: Option<MetricSample>,
1484    pub memory: Option<MetricSample>,
1485}
1486
1487#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1488#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1489#[serde(tag = "backend", rename_all = "camelCase")]
1490pub enum QueueHeartbeatData {
1491    AwsSqs(AwsSqsQueueHeartbeatData),
1492    GcpPubSub(GcpPubSubQueueHeartbeatData),
1493    AzureServiceBus(AzureServiceBusQueueHeartbeatData),
1494    Local(LocalQueueHeartbeatData),
1495}
1496
1497#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1498#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1499#[serde(rename_all = "camelCase")]
1500pub struct QueueHeartbeatStatus {
1501    pub health: ObservedHealth,
1502    pub lifecycle: ProviderLifecycleState,
1503    pub message: Option<String>,
1504    pub stale: bool,
1505    pub partial: bool,
1506    pub collection_issues: Vec<HeartbeatCollectionIssue>,
1507}
1508
1509impl Default for QueueHeartbeatStatus {
1510    fn default() -> Self {
1511        Self {
1512            health: ObservedHealth::Unknown,
1513            lifecycle: ProviderLifecycleState::Unknown,
1514            message: None,
1515            stale: false,
1516            partial: false,
1517            collection_issues: vec![],
1518        }
1519    }
1520}
1521
1522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
1523#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1524#[serde(rename_all = "camelCase")]
1525pub struct LocalQueueHeartbeatData {
1526    pub status: QueueHeartbeatStatus,
1527    pub name: String,
1528    pub path: Option<String>,
1529    pub service_status: Option<String>,
1530}
1531
1532#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
1533#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1534#[serde(rename_all = "camelCase")]
1535pub struct GcpPubSubQueueHeartbeatData {
1536    pub status: QueueHeartbeatStatus,
1537    pub topic_name: String,
1538    pub subscription_name: Option<String>,
1539    pub project_id: Option<String>,
1540    pub topic_full_name: Option<String>,
1541    pub subscription_full_name: Option<String>,
1542    pub endpoint: Option<String>,
1543    pub topic_labels: BTreeMap<String, String>,
1544    pub subscription_labels: BTreeMap<String, String>,
1545    pub message_storage_allowed_persistence_regions: Vec<String>,
1546    pub message_storage_enforce_in_transit: Option<bool>,
1547    pub kms_key_name: Option<String>,
1548    pub schema_name: Option<String>,
1549    pub schema_encoding: Option<String>,
1550    pub schema_first_revision_id: Option<String>,
1551    pub schema_last_revision_id: Option<String>,
1552    pub topic_message_retention_duration: Option<String>,
1553    pub topic_state: Option<String>,
1554    pub subscription_ack_deadline_seconds: Option<u32>,
1555    pub subscription_message_retention_duration: Option<String>,
1556    pub subscription_retain_acked_messages: Option<bool>,
1557    pub subscription_enable_message_ordering: Option<bool>,
1558    pub subscription_filter: Option<String>,
1559    pub subscription_detached: Option<bool>,
1560    pub subscription_state: Option<String>,
1561    pub subscription_push_config_present: Option<bool>,
1562    pub subscription_push_endpoint: Option<String>,
1563    pub subscription_push_attributes: BTreeMap<String, String>,
1564    pub subscription_push_oidc_service_account_email: Option<String>,
1565    pub subscription_push_oidc_audience: Option<String>,
1566    pub subscription_push_pubsub_wrapper_write_metadata: Option<bool>,
1567    pub subscription_push_no_wrapper_write_metadata: Option<bool>,
1568    pub subscription_dead_letter_topic: Option<String>,
1569    pub subscription_dead_letter_max_delivery_attempts: Option<u32>,
1570}
1571
1572#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1573#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1574#[serde(rename_all = "camelCase")]
1575pub struct AzureServiceBusQueueHeartbeatData {
1576    pub status: QueueHeartbeatStatus,
1577    pub name: String,
1578    pub namespace_name: String,
1579    pub resource_group: Option<String>,
1580    pub resource_id: Option<String>,
1581    pub endpoint: Option<String>,
1582    pub queue_status: Option<String>,
1583    pub lock_duration: Option<String>,
1584    pub max_delivery_count: Option<u32>,
1585    pub requires_duplicate_detection: Option<bool>,
1586    pub duplicate_detection_history_time_window: Option<String>,
1587    pub requires_session: Option<bool>,
1588    pub dead_lettering_on_message_expiration: Option<bool>,
1589    pub forward_dead_lettered_messages_to: Option<String>,
1590    pub forward_to: Option<String>,
1591    pub default_message_time_to_live: Option<String>,
1592    pub auto_delete_on_idle: Option<String>,
1593    pub enable_batched_operations: Option<bool>,
1594    pub enable_express: Option<bool>,
1595    pub enable_partitioning: Option<bool>,
1596    pub max_message_size_in_kilobytes: Option<u64>,
1597    pub max_size_in_megabytes: Option<u32>,
1598    pub message_count: Option<u64>,
1599    pub active_message_count: Option<u64>,
1600    pub dead_letter_message_count: Option<u64>,
1601    pub scheduled_message_count: Option<u64>,
1602    pub transfer_message_count: Option<u64>,
1603    pub transfer_dead_letter_message_count: Option<u64>,
1604    pub size_in_bytes: Option<u64>,
1605    pub accessed_at: Option<String>,
1606    pub created_at: Option<String>,
1607    pub updated_at: Option<String>,
1608}
1609
1610#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1611#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1612#[serde(rename_all = "camelCase")]
1613pub struct AwsSqsQueueHeartbeatData {
1614    pub status: QueueHeartbeatStatus,
1615    pub name: String,
1616    pub region: Option<String>,
1617    pub queue_url: Option<String>,
1618    pub queue_arn: Option<String>,
1619    pub visibility_timeout_seconds: Option<u32>,
1620    pub message_retention_period_seconds: Option<u32>,
1621    pub delay_seconds: Option<u32>,
1622    pub receive_message_wait_time_seconds: Option<u32>,
1623    pub maximum_message_size: Option<u32>,
1624    pub redrive_policy: Option<String>,
1625    pub redrive_allow_policy: Option<String>,
1626    pub fifo_queue: Option<bool>,
1627    pub content_based_deduplication: Option<bool>,
1628    pub deduplication_scope: Option<String>,
1629    pub fifo_throughput_limit: Option<String>,
1630    pub sse_enabled: Option<bool>,
1631    pub kms_master_key_id: Option<String>,
1632    pub kms_data_key_reuse_period_seconds: Option<u32>,
1633    pub sqs_managed_sse_enabled: Option<bool>,
1634    pub approximate_visible_messages: Option<u64>,
1635    pub approximate_in_flight_messages: Option<u64>,
1636    pub approximate_delayed_messages: Option<u64>,
1637    pub approximate_counts: bool,
1638}
1639
1640#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1641#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1642#[serde(tag = "backend", rename_all = "camelCase")]
1643pub enum KvHeartbeatData {
1644    AwsDynamoDb(AwsDynamoDbKvHeartbeatData),
1645    GcpFirestore(GcpFirestoreKvHeartbeatData),
1646    AzureTable(AzureTableKvHeartbeatData),
1647    Local(LocalKvHeartbeatData),
1648}
1649
1650#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1651#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1652#[serde(rename_all = "camelCase")]
1653pub struct KvHeartbeatStatus {
1654    pub health: ObservedHealth,
1655    pub lifecycle: ProviderLifecycleState,
1656    pub message: Option<String>,
1657    pub stale: bool,
1658    pub partial: bool,
1659    pub collection_issues: Vec<HeartbeatCollectionIssue>,
1660}
1661
1662impl Default for KvHeartbeatStatus {
1663    fn default() -> Self {
1664        Self {
1665            health: ObservedHealth::Unknown,
1666            lifecycle: ProviderLifecycleState::Unknown,
1667            message: None,
1668            stale: false,
1669            partial: false,
1670            collection_issues: vec![],
1671        }
1672    }
1673}
1674
1675#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1676#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1677#[serde(rename_all = "camelCase")]
1678pub struct AwsDynamoDbKvHeartbeatData {
1679    pub status: KvHeartbeatStatus,
1680    pub name: String,
1681    pub region: Option<String>,
1682    pub table_arn: Option<String>,
1683    pub table_status: Option<String>,
1684    pub billing_mode: Option<String>,
1685    pub key_schema: Vec<AwsDynamoDbKeySchemaElement>,
1686    pub global_secondary_index_count: Option<u32>,
1687    pub local_secondary_index_count: Option<u32>,
1688    pub item_count: Option<u64>,
1689    pub table_size_bytes: Option<u64>,
1690    pub stream_enabled: Option<bool>,
1691    pub stream_view_type: Option<String>,
1692    pub ttl_status: Option<String>,
1693    pub ttl_attribute_name: Option<String>,
1694    pub deletion_protection_enabled: Option<bool>,
1695    pub sse_status: Option<String>,
1696    pub sse_type: Option<String>,
1697    pub table_class: Option<String>,
1698    pub replica_count: Option<u32>,
1699    pub restore_in_progress: Option<bool>,
1700}
1701
1702#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1703#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1704#[serde(rename_all = "camelCase")]
1705pub struct AwsDynamoDbKeySchemaElement {
1706    pub attribute_name: String,
1707    pub key_type: String,
1708}
1709
1710#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1711#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1712#[serde(rename_all = "camelCase")]
1713pub struct GcpFirestoreKvHeartbeatData {
1714    pub status: KvHeartbeatStatus,
1715    pub database_name: String,
1716    pub project_id: Option<String>,
1717    pub endpoint: Option<String>,
1718    pub location_id: Option<String>,
1719    pub database_type: Option<String>,
1720    pub concurrency_mode: Option<String>,
1721    pub app_engine_integration_mode: Option<String>,
1722    pub delete_protection_state: Option<String>,
1723    pub point_in_time_recovery_enablement: Option<String>,
1724    pub version_retention_period: Option<String>,
1725    pub earliest_version_time: Option<String>,
1726    pub create_time: Option<String>,
1727    pub update_time: Option<String>,
1728    pub delete_time: Option<String>,
1729    pub database_edition: Option<String>,
1730    pub cmek_enabled: bool,
1731    pub source_info_present: bool,
1732}
1733
1734#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1735#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1736#[serde(rename_all = "camelCase")]
1737pub struct AzureTableKvHeartbeatData {
1738    pub status: KvHeartbeatStatus,
1739    pub table_name: String,
1740    pub storage_account_name: String,
1741    pub resource_group: Option<String>,
1742    pub endpoint: Option<String>,
1743    pub storage_account_resource_id: Option<String>,
1744    pub storage_account_location: Option<String>,
1745    pub storage_account_kind: Option<String>,
1746    pub storage_account_provisioning_state: Option<String>,
1747    pub storage_account_primary_status: Option<String>,
1748    pub table_exists: bool,
1749    pub signed_identifier_count: Option<u32>,
1750}
1751
1752#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1753#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1754#[serde(rename_all = "camelCase")]
1755pub struct LocalKvHeartbeatData {
1756    pub status: KvHeartbeatStatus,
1757    pub name: String,
1758    pub path: String,
1759    pub path_exists: bool,
1760    pub is_directory: Option<bool>,
1761    pub cloud_metadata_supported: bool,
1762}
1763
1764#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1765#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1766#[serde(tag = "backend", rename_all = "camelCase")]
1767pub enum PostgresHeartbeatData {
1768    /// AWS Aurora Serverless v2 backend.
1769    Aurora(AuroraPostgresHeartbeatData),
1770    /// GCP Cloud SQL backend.
1771    CloudSql(GcpCloudSqlPostgresHeartbeatData),
1772    /// Azure Flexible Server backend.
1773    FlexibleServer(AzureFlexibleServerPostgresHeartbeatData),
1774    /// Local embedded Postgres backend.
1775    Local(LocalPostgresHeartbeatData),
1776}
1777
1778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1779#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1780#[serde(rename_all = "camelCase")]
1781pub struct PostgresHeartbeatStatus {
1782    pub health: ObservedHealth,
1783    pub lifecycle: ProviderLifecycleState,
1784    pub message: Option<String>,
1785    pub stale: bool,
1786    pub partial: bool,
1787    pub collection_issues: Vec<HeartbeatCollectionIssue>,
1788}
1789
1790impl Default for PostgresHeartbeatStatus {
1791    fn default() -> Self {
1792        Self {
1793            health: ObservedHealth::Unknown,
1794            lifecycle: ProviderLifecycleState::Unknown,
1795            message: None,
1796            stale: false,
1797            partial: false,
1798            collection_issues: vec![],
1799        }
1800    }
1801}
1802
1803/// Heartbeat data for a Redis resource. Everything comes from the cloud's
1804/// management and metrics APIs; the manager never opens a Redis connection.
1805#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1806#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1807#[serde(tag = "backend", rename_all = "camelCase")]
1808pub enum RedisHeartbeatData {
1809    /// AWS ElastiCache for Valkey.
1810    Elasticache(ElasticacheRedisHeartbeatData),
1811    /// GCP Memorystore for Valkey.
1812    Memorystore(MemorystoreRedisHeartbeatData),
1813    /// Azure Managed Redis.
1814    AzureManagedRedis(AzureManagedRedisHeartbeatData),
1815    /// Local Valkey container.
1816    Local(LocalRedisHeartbeatData),
1817}
1818
1819/// Same fields as every other resource heartbeat status.
1820#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1821#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1822#[serde(rename_all = "camelCase")]
1823pub struct RedisHeartbeatStatus {
1824    pub health: ObservedHealth,
1825    pub lifecycle: ProviderLifecycleState,
1826    pub message: Option<String>,
1827    pub stale: bool,
1828    pub partial: bool,
1829    pub collection_issues: Vec<HeartbeatCollectionIssue>,
1830}
1831
1832impl Default for RedisHeartbeatStatus {
1833    fn default() -> Self {
1834        Self {
1835            health: ObservedHealth::Unknown,
1836            lifecycle: ProviderLifecycleState::Unknown,
1837            message: None,
1838            stale: false,
1839            partial: false,
1840            collection_issues: vec![],
1841        }
1842    }
1843}
1844
1845/// One sample of the numbers that matter for a Redis server. A field is `None`
1846/// when the cloud did not return that metric in the window.
1847#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1848#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1849#[serde(rename_all = "camelCase")]
1850pub struct RedisMetricsSample {
1851    /// Memory used as a percentage of the configured maximum (0-100).
1852    #[serde(skip_serializing_if = "Option::is_none")]
1853    pub memory_used_percent: Option<f64>,
1854    /// Keys evicted during the sampled window.
1855    #[serde(skip_serializing_if = "Option::is_none")]
1856    pub evictions: Option<f64>,
1857    /// Connected clients at the end of the window.
1858    #[serde(skip_serializing_if = "Option::is_none")]
1859    pub connected_clients: Option<f64>,
1860    /// Replication lag in seconds, when a replica exists.
1861    #[serde(skip_serializing_if = "Option::is_none")]
1862    pub replication_lag_seconds: Option<f64>,
1863}
1864
1865/// Configuration the controller reads back from the cloud, to compare with the
1866/// desired configuration.
1867#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
1868#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1869#[serde(rename_all = "camelCase")]
1870pub struct RedisObservedConfig {
1871    /// Engine name and version as the cloud reports it.
1872    #[serde(skip_serializing_if = "Option::is_none")]
1873    pub engine_version: Option<String>,
1874    /// Node type or SKU name.
1875    #[serde(skip_serializing_if = "Option::is_none")]
1876    pub node_type: Option<String>,
1877    #[serde(skip_serializing_if = "Option::is_none")]
1878    pub endpoint: Option<String>,
1879    #[serde(skip_serializing_if = "Option::is_none")]
1880    pub port: Option<u16>,
1881    #[serde(skip_serializing_if = "Option::is_none")]
1882    pub eviction_policy: Option<String>,
1883    #[serde(skip_serializing_if = "Option::is_none")]
1884    pub persistence_enabled: Option<bool>,
1885    /// Replicas behind the primary.
1886    #[serde(skip_serializing_if = "Option::is_none")]
1887    pub replica_count: Option<u32>,
1888    #[serde(skip_serializing_if = "Option::is_none")]
1889    pub tls_enabled: Option<bool>,
1890    #[serde(skip_serializing_if = "Option::is_none")]
1891    pub auth_enabled: Option<bool>,
1892    /// Azure only: true when the server accepts connections from the public internet.
1893    #[serde(skip_serializing_if = "Option::is_none")]
1894    pub public_network_access: Option<bool>,
1895}
1896
1897#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1898#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1899#[serde(rename_all = "camelCase")]
1900pub struct ElasticacheRedisHeartbeatData {
1901    pub status: RedisHeartbeatStatus,
1902    pub replication_group_id: String,
1903    #[serde(skip_serializing_if = "Option::is_none")]
1904    pub state: Option<String>,
1905    pub config: RedisObservedConfig,
1906    pub metrics: RedisMetricsSample,
1907}
1908
1909#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1910#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1911#[serde(rename_all = "camelCase")]
1912pub struct MemorystoreRedisHeartbeatData {
1913    pub status: RedisHeartbeatStatus,
1914    pub instance_name: String,
1915    #[serde(skip_serializing_if = "Option::is_none")]
1916    pub state: Option<String>,
1917    pub config: RedisObservedConfig,
1918    pub metrics: RedisMetricsSample,
1919}
1920
1921#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1922#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1923#[serde(rename_all = "camelCase")]
1924pub struct AzureManagedRedisHeartbeatData {
1925    pub status: RedisHeartbeatStatus,
1926    pub cluster_name: String,
1927    #[serde(skip_serializing_if = "Option::is_none")]
1928    pub state: Option<String>,
1929    pub config: RedisObservedConfig,
1930    pub metrics: RedisMetricsSample,
1931}
1932
1933#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1934#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1935#[serde(rename_all = "camelCase")]
1936pub struct LocalRedisHeartbeatData {
1937    pub status: RedisHeartbeatStatus,
1938    pub name: String,
1939    pub port: Option<u16>,
1940    pub version: String,
1941    pub process_running: bool,
1942}
1943
1944/// Content-free telemetry about what a sandbox resource is running.
1945///
1946/// Never anything from inside a sandbox. A controller reaches only the cloud's management APIs,
1947/// and the whole point of the resource is that the control plane cannot see what runs in it.
1948#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1949#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1950#[serde(tag = "backend", rename_all = "camelCase")]
1951pub enum SandboxHeartbeatData {
1952    AwsMicrovm(AwsMicrovmSandboxHeartbeatData),
1953    AzureSandboxGroup(AzureSandboxGroupHeartbeatData),
1954    GcpAgentPlatform(GcpAgentPlatformSandboxHeartbeatData),
1955    KubernetesPods(KubernetesSandboxHeartbeatData),
1956    Local(LocalSandboxHeartbeatData),
1957}
1958
1959#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1960#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1961#[serde(rename_all = "camelCase")]
1962pub struct SandboxHeartbeatStatus {
1963    pub health: ObservedHealth,
1964    pub lifecycle: ProviderLifecycleState,
1965    pub message: Option<String>,
1966    pub stale: bool,
1967    pub partial: bool,
1968    pub collection_issues: Vec<HeartbeatCollectionIssue>,
1969}
1970
1971impl Default for SandboxHeartbeatStatus {
1972    fn default() -> Self {
1973        Self {
1974            health: ObservedHealth::Healthy,
1975            lifecycle: ProviderLifecycleState::Running,
1976            message: None,
1977            stale: false,
1978            partial: false,
1979            collection_issues: Vec::new(),
1980        }
1981    }
1982}
1983
1984/// AWS: the image a sandbox runs from, and the lifecycle state AWS reports for it.
1985#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1986#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
1987#[serde(rename_all = "camelCase")]
1988pub struct AwsMicrovmSandboxHeartbeatData {
1989    pub status: SandboxHeartbeatStatus,
1990    /// Image the sandboxes belong to.
1991    pub image_identifier: String,
1992    /// The image's own lifecycle state, which is where AWS surfaces base-image deprecation.
1993    ///
1994    /// No sandbox count sits beside it: counting means `lambda:ListMicrovms`, which authorizes
1995    /// against no resource type and so cannot be granted without an account-wide reach the
1996    /// permission sets refuse. A field only an over-broad grant could fill is a field whose
1997    /// implementer ships AccessDenied into a customer's account.
1998    pub image_state: Option<String>,
1999}
2000
2001/// Azure: the sandbox group's ARM state. The data plane has no list operation, so a sandbox count
2002/// is not available here.
2003#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2004#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2005#[serde(rename_all = "camelCase")]
2006pub struct AzureSandboxGroupHeartbeatData {
2007    pub status: SandboxHeartbeatStatus,
2008    pub sandbox_group: String,
2009    pub provisioning_state: Option<String>,
2010}
2011
2012/// GCP: the Agent Platform template sandboxes are cut from, and the engine it hangs under.
2013///
2014/// No sandbox count: that needs `aiplatform.sandboxEnvironments.list`, which only the management
2015/// permission set holds. No template state either — emission is gated on reading it `ACTIVE`,
2016/// which is what `status` already says.
2017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2018#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2019#[serde(rename_all = "camelCase")]
2020pub struct GcpAgentPlatformSandboxHeartbeatData {
2021    pub status: SandboxHeartbeatStatus,
2022    /// Reasoning engine the template hangs under, without which the template id names nothing.
2023    pub engine: String,
2024    /// The template sandboxes are currently cut from.
2025    pub template_id: String,
2026}
2027
2028/// Kubernetes: pods carrying the sandbox label, in the deployment's namespace.
2029#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2030#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2031#[serde(rename_all = "camelCase")]
2032pub struct KubernetesSandboxHeartbeatData {
2033    pub status: SandboxHeartbeatStatus,
2034    pub namespace: String,
2035    pub active_sessions: u32,
2036    /// Claimed but unused pods waiting in the pool.
2037    pub idle_pods: u32,
2038}
2039
2040/// Local: containers Docker still holds for this sandbox.
2041#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2042#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2043#[serde(rename_all = "camelCase")]
2044pub struct LocalSandboxHeartbeatData {
2045    pub status: SandboxHeartbeatStatus,
2046    pub active_sessions: u32,
2047    /// Whether the loopback route is serving in this process. False after a manager restart until
2048    /// the next tick rebinds it.
2049    pub route_serving: bool,
2050}
2051
2052#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2053#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2054#[serde(tag = "backend", rename_all = "camelCase")]
2055pub enum AiHeartbeatData {
2056    AwsBedrock(AwsBedrockAiHeartbeatData),
2057    GcpVertex(GcpVertexAiHeartbeatData),
2058    AzureFoundry(AzureFoundryAiHeartbeatData),
2059    External(ExternalAiHeartbeatData),
2060}
2061
2062#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2063#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2064#[serde(rename_all = "camelCase")]
2065pub struct AiHeartbeatStatus {
2066    pub health: ObservedHealth,
2067    pub lifecycle: ProviderLifecycleState,
2068    pub message: Option<String>,
2069    pub stale: bool,
2070    pub partial: bool,
2071    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2072}
2073
2074impl Default for AiHeartbeatStatus {
2075    fn default() -> Self {
2076        // A configured AI binding is not proof that its models are usable.
2077        Self {
2078            health: ObservedHealth::Unknown,
2079            lifecycle: ProviderLifecycleState::Unknown,
2080            message: None,
2081            stale: false,
2082            partial: false,
2083            collection_issues: vec![],
2084        }
2085    }
2086}
2087
2088/// Provider control plane used to observe model availability without invoking
2089/// a model, spending customer quota, or accepting provider terms.
2090#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2091#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2092#[serde(rename_all = "kebab-case")]
2093pub enum AiAvailabilitySource {
2094    AwsBedrock,
2095    GcpVertex,
2096    AzureFoundry,
2097    Anthropic,
2098}
2099
2100#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2101#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2102#[serde(rename_all = "kebab-case")]
2103pub enum AiModelAvailability {
2104    Available,
2105    Blocked,
2106    Unknown,
2107}
2108
2109#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2110#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2111#[serde(rename_all = "kebab-case")]
2112pub enum AiAvailabilityBlocker {
2113    AgreementRequired,
2114    EntitlementRequired,
2115    ModelActivationRequired,
2116    DeploymentRequired,
2117    QuotaConfigurationRequired,
2118    RegionUnavailable,
2119    AccessDenied,
2120    ObservationFailed,
2121}
2122
2123#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
2124#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2125#[serde(rename_all = "kebab-case")]
2126pub enum AiAccessTest {
2127    Verified,
2128    Failed,
2129    NotChecked,
2130}
2131
2132#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2133#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2134#[serde(rename_all = "camelCase")]
2135pub struct AiModelAvailabilityObservation {
2136    pub public_model_id: String,
2137    pub client_apis: Vec<ClientApi>,
2138    pub availability: AiModelAvailability,
2139    pub blockers: Vec<AiAvailabilityBlocker>,
2140    pub access_test: AiAccessTest,
2141    #[serde(skip_serializing_if = "Option::is_none")]
2142    pub tested_at: Option<DateTime<Utc>>,
2143    #[serde(skip_serializing_if = "Option::is_none")]
2144    pub error_code: Option<String>,
2145    /// Applied quotas far below the cloud's default for this model. Empty when none were read
2146    /// or none are low.
2147    #[serde(default, skip_serializing_if = "Vec::is_empty")]
2148    pub quota_warnings: Vec<AiQuotaWarning>,
2149    /// Requests the cloud throttled for this model in the last hour, from the cloud's own
2150    /// metrics. `None` when not read; `Some(0)` is a real zero.
2151    #[serde(default, skip_serializing_if = "Option::is_none")]
2152    pub throttled_last_hour: Option<u64>,
2153}
2154
2155/// One quota the account has set well below the cloud's default (under 10%).
2156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2157#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2158#[serde(rename_all = "camelCase")]
2159pub struct AiQuotaWarning {
2160    pub quota_name: String,
2161    pub applied: f64,
2162    pub default: f64,
2163}
2164
2165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2166#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2167#[serde(rename_all = "camelCase")]
2168pub struct AiAvailabilityObservation {
2169    pub source: AiAvailabilitySource,
2170    pub catalog_revision: String,
2171    #[serde(skip_serializing_if = "Option::is_none")]
2172    pub location: Option<String>,
2173    pub models: Vec<AiModelAvailabilityObservation>,
2174}
2175
2176impl AiAvailabilityObservation {
2177    /// Conservative observation used until a provider control-plane read has
2178    /// completed. It never claims that a configured model is usable.
2179    pub fn unobserved(
2180        source: AiAvailabilitySource,
2181        platform: Platform,
2182        location: Option<String>,
2183    ) -> Self {
2184        Self {
2185            source,
2186            catalog_revision: crate::ai_catalog::AI_CATALOG_REVISION.to_string(),
2187            location,
2188            models: crate::ai_catalog::models_for(platform)
2189                .into_iter()
2190                .map(|model| AiModelAvailabilityObservation {
2191                    public_model_id: model.public_id.to_string(),
2192                    client_apis: ClientApi::ALL.to_vec(),
2193                    availability: AiModelAvailability::Unknown,
2194                    blockers: vec![AiAvailabilityBlocker::ObservationFailed],
2195                    access_test: AiAccessTest::NotChecked,
2196                    tested_at: None,
2197                    error_code: None,
2198                    quota_warnings: Vec::new(),
2199                    throttled_last_hour: None,
2200                })
2201                .collect(),
2202        }
2203    }
2204}
2205
2206#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2207#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2208#[serde(rename_all = "camelCase")]
2209pub struct LocalPostgresHeartbeatData {
2210    pub status: PostgresHeartbeatStatus,
2211    pub name: String,
2212    pub port: Option<u16>,
2213    pub version: String,
2214    pub process_running: bool,
2215}
2216
2217#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2218#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2219#[serde(rename_all = "camelCase")]
2220pub struct AuroraPostgresHeartbeatData {
2221    pub status: PostgresHeartbeatStatus,
2222    pub cluster_identifier: String,
2223    #[serde(skip_serializing_if = "Option::is_none")]
2224    pub engine_version: Option<String>,
2225    #[serde(skip_serializing_if = "Option::is_none")]
2226    pub endpoint: Option<String>,
2227    /// Latest sampled `ServerlessDatabaseCapacity` (ACU).
2228    #[serde(skip_serializing_if = "Option::is_none")]
2229    pub serverless_capacity: Option<f64>,
2230    /// True when a `minCapacity: 0` instance has not reached 0 ACU over the observation
2231    /// window — it is silently paying always-on prices (auto-pause verification).
2232    pub never_pauses: bool,
2233}
2234
2235#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2236#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2237#[serde(rename_all = "camelCase")]
2238pub struct GcpCloudSqlPostgresHeartbeatData {
2239    pub status: PostgresHeartbeatStatus,
2240    pub instance_name: String,
2241    #[serde(skip_serializing_if = "Option::is_none")]
2242    pub state: Option<String>,
2243    #[serde(skip_serializing_if = "Option::is_none")]
2244    pub database_version: Option<String>,
2245}
2246
2247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2248#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2249#[serde(rename_all = "camelCase")]
2250pub struct AzureFlexibleServerPostgresHeartbeatData {
2251    pub status: PostgresHeartbeatStatus,
2252    pub server_name: String,
2253    #[serde(skip_serializing_if = "Option::is_none")]
2254    pub state: Option<String>,
2255    #[serde(skip_serializing_if = "Option::is_none")]
2256    pub version: Option<String>,
2257}
2258
2259#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2260#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2261#[serde(rename_all = "camelCase")]
2262pub struct AwsBedrockAiHeartbeatData {
2263    pub status: AiHeartbeatStatus,
2264    pub region: String,
2265    pub availability: AiAvailabilityObservation,
2266}
2267
2268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2269#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2270#[serde(rename_all = "camelCase")]
2271pub struct GcpVertexAiHeartbeatData {
2272    pub status: AiHeartbeatStatus,
2273    pub project: String,
2274    pub location: String,
2275    pub availability: AiAvailabilityObservation,
2276}
2277
2278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2279#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2280#[serde(rename_all = "camelCase")]
2281pub struct AzureFoundryAiHeartbeatData {
2282    pub status: AiHeartbeatStatus,
2283    pub account_name: String,
2284    pub endpoint: Option<String>,
2285    pub resource_group: Option<String>,
2286    pub location: Option<String>,
2287    pub availability: AiAvailabilityObservation,
2288}
2289
2290#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2291#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2292#[serde(rename_all = "camelCase")]
2293pub struct ExternalAiHeartbeatData {
2294    pub status: AiHeartbeatStatus,
2295    /// The BYO-key provider serving this binding (e.g. "openai"). Used on the Local
2296    /// platform, where the app brings its own provider key instead of an ambient cloud.
2297    pub provider: String,
2298    #[serde(skip_serializing_if = "Option::is_none")]
2299    pub availability: Option<AiAvailabilityObservation>,
2300}
2301
2302#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2303#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2304#[serde(tag = "backend", rename_all = "camelCase")]
2305pub enum VaultHeartbeatData {
2306    AwsParameterStore(AwsParameterStoreVaultHeartbeatData),
2307    GcpSecretManager(GcpSecretManagerVaultHeartbeatData),
2308    AzureKeyVault(AzureKeyVaultHeartbeatData),
2309    KubernetesSecret(KubernetesSecretVaultHeartbeatData),
2310    Local(LocalVaultHeartbeatData),
2311}
2312
2313#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2314#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2315#[serde(rename_all = "camelCase")]
2316pub struct VaultHeartbeatStatus {
2317    pub health: ObservedHealth,
2318    pub lifecycle: ProviderLifecycleState,
2319    pub message: Option<String>,
2320    pub stale: bool,
2321    pub partial: bool,
2322    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2323}
2324
2325impl Default for VaultHeartbeatStatus {
2326    fn default() -> Self {
2327        Self {
2328            health: ObservedHealth::Healthy,
2329            lifecycle: ProviderLifecycleState::Running,
2330            message: None,
2331            stale: false,
2332            partial: false,
2333            collection_issues: vec![],
2334        }
2335    }
2336}
2337
2338#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2339#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2340#[serde(rename_all = "camelCase")]
2341pub struct AwsParameterStoreVaultHeartbeatData {
2342    pub status: VaultHeartbeatStatus,
2343    pub account_id: String,
2344    pub region: String,
2345    pub prefix: String,
2346    pub parameter_metadata_sampled: bool,
2347    pub sampled_parameter_count: Option<u32>,
2348    pub sampled_secure_string_count: Option<u32>,
2349    pub sampled_string_count: Option<u32>,
2350    pub sampled_string_list_count: Option<u32>,
2351    pub sampled_advanced_tier_count: Option<u32>,
2352    pub sampled_kms_key_metadata_present_count: Option<u32>,
2353    pub latest_modified_at: Option<DateTime<Utc>>,
2354    pub has_more_parameters: Option<bool>,
2355}
2356
2357#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2358#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2359#[serde(rename_all = "camelCase")]
2360pub struct GcpSecretManagerVaultHeartbeatData {
2361    pub status: VaultHeartbeatStatus,
2362    pub project_id: String,
2363    pub location: String,
2364    pub prefix: String,
2365    pub secret_metadata_listed: bool,
2366}
2367
2368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2369#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2370#[serde(rename_all = "camelCase")]
2371pub struct AzureKeyVaultHeartbeatData {
2372    pub status: VaultHeartbeatStatus,
2373    pub name: String,
2374    pub resource_group: Option<String>,
2375    pub resource_id: Option<String>,
2376    pub location: Option<String>,
2377    pub vault_uri: Option<String>,
2378    pub provisioning_state: Option<String>,
2379    pub sku_family: Option<String>,
2380    pub sku_name: Option<String>,
2381    pub soft_delete_enabled: bool,
2382    pub soft_delete_retention_days: i32,
2383    pub purge_protection_enabled: Option<bool>,
2384    pub rbac_authorization_enabled: bool,
2385    pub public_network_access: String,
2386    pub access_policy_count: u32,
2387    pub private_endpoint_connection_count: u32,
2388    pub secret_metadata_listed: bool,
2389}
2390
2391#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2392#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2393#[serde(rename_all = "camelCase")]
2394pub struct KubernetesSecretVaultHeartbeatData {
2395    pub status: VaultHeartbeatStatus,
2396    pub namespace: String,
2397    pub prefix: String,
2398    pub secret_metadata_listed: bool,
2399}
2400
2401#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2402#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2403#[serde(rename_all = "camelCase")]
2404pub struct LocalVaultHeartbeatData {
2405    pub status: VaultHeartbeatStatus,
2406    pub path: String,
2407    pub path_exists: bool,
2408    pub is_directory: Option<bool>,
2409    pub readonly: Option<bool>,
2410    pub modified_at: Option<DateTime<Utc>>,
2411    pub secret_metadata_listed: bool,
2412}
2413
2414#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2415#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2416#[serde(tag = "backend", rename_all = "camelCase")]
2417pub enum ServiceAccountHeartbeatData {
2418    AwsIamRole(AwsIamRoleServiceAccountHeartbeatData),
2419    GcpServiceAccount(GcpServiceAccountHeartbeatData),
2420    AzureManagedIdentity(AzureManagedIdentityServiceAccountHeartbeatData),
2421    Local(LocalServiceAccountHeartbeatData),
2422}
2423
2424#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2425#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2426#[serde(rename_all = "camelCase")]
2427pub struct ServiceAccountHeartbeatStatus {
2428    pub health: ObservedHealth,
2429    pub lifecycle: ProviderLifecycleState,
2430    pub message: Option<String>,
2431    pub stale: bool,
2432    pub partial: bool,
2433    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2434}
2435
2436#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2437#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2438#[serde(rename_all = "camelCase")]
2439pub struct AwsIamRoleServiceAccountHeartbeatData {
2440    pub status: ServiceAccountHeartbeatStatus,
2441    pub role_name: String,
2442    pub role_arn: String,
2443    pub role_id: String,
2444    pub path: String,
2445    pub create_date: String,
2446    pub description: Option<String>,
2447    pub max_session_duration: Option<i32>,
2448    pub assume_role_policy_present: bool,
2449    pub permissions_boundary_type: Option<String>,
2450    pub permissions_boundary_arn: Option<String>,
2451    pub tag_count: u32,
2452    pub managed_tag_count: u32,
2453    pub attached_policy_count: u32,
2454    pub attached_policy_names: Vec<String>,
2455    pub inline_policy_count: u32,
2456    pub inline_policy_names: Vec<String>,
2457    pub stack_permissions_applied: bool,
2458    pub last_used_date: Option<String>,
2459    pub last_used_region: Option<String>,
2460}
2461
2462#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2463#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2464#[serde(rename_all = "camelCase")]
2465pub struct GcpServiceAccountHeartbeatData {
2466    pub status: ServiceAccountHeartbeatStatus,
2467    pub name: Option<String>,
2468    pub project_id: Option<String>,
2469    pub unique_id: Option<String>,
2470    pub email: String,
2471    pub display_name: Option<String>,
2472    pub description: Option<String>,
2473    pub oauth2_client_id: Option<String>,
2474    pub disabled: Option<bool>,
2475    pub etag: Option<String>,
2476    pub project_binding_count: u32,
2477    pub project_roles: Vec<String>,
2478    pub service_account_binding_count: u32,
2479    pub service_account_roles: Vec<String>,
2480}
2481
2482#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2483#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2484#[serde(rename_all = "camelCase")]
2485pub struct AzureManagedIdentityServiceAccountHeartbeatData {
2486    pub status: ServiceAccountHeartbeatStatus,
2487    pub name: String,
2488    pub resource_id: String,
2489    pub resource_group: String,
2490    pub location: String,
2491    pub type_: Option<String>,
2492    pub client_id: Option<String>,
2493    pub principal_id: Option<String>,
2494    pub tenant_id: Option<String>,
2495    pub isolation_scope: Option<String>,
2496    pub managed_tag_count: u32,
2497    pub role_assignment_count: u32,
2498    pub role_assignment_ids: Vec<String>,
2499    pub custom_role_definition_count: u32,
2500    pub custom_role_definition_ids: Vec<String>,
2501    pub stack_permissions_applied: bool,
2502}
2503
2504#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2505#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2506#[serde(rename_all = "camelCase")]
2507pub struct LocalServiceAccountHeartbeatData {
2508    pub status: ServiceAccountHeartbeatStatus,
2509    pub identity: String,
2510    pub configured: bool,
2511}
2512
2513#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2514#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2515#[serde(tag = "backend", rename_all = "camelCase")]
2516pub enum NetworkHeartbeatData {
2517    AwsVpc(AwsVpcNetworkHeartbeatData),
2518    GcpVpc(GcpVpcNetworkHeartbeatData),
2519    AzureVnet(AzureVnetNetworkHeartbeatData),
2520}
2521
2522#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2523#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2524#[serde(rename_all = "camelCase")]
2525pub struct NetworkHeartbeatStatus {
2526    pub health: ObservedHealth,
2527    pub lifecycle: ProviderLifecycleState,
2528    pub message: Option<String>,
2529    pub stale: bool,
2530    pub partial: bool,
2531    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2532}
2533
2534#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2535#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2536#[serde(rename_all = "camelCase")]
2537pub struct AwsVpcNetworkHeartbeatData {
2538    pub status: NetworkHeartbeatStatus,
2539    pub vpc_id: Option<String>,
2540    pub vpc_state: Option<String>,
2541    pub cidr_block: Option<String>,
2542    pub public_subnet_ids: Vec<String>,
2543    pub private_subnet_ids: Vec<String>,
2544    pub availability_zones: Vec<String>,
2545    pub internet_gateway_id: Option<String>,
2546    pub nat_gateway_id: Option<String>,
2547    pub route_table_count: u32,
2548    pub security_group_id: Option<String>,
2549    pub is_byo_vpc: bool,
2550}
2551
2552#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2553#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2554#[serde(rename_all = "camelCase")]
2555pub struct GcpVpcNetworkHeartbeatData {
2556    pub status: NetworkHeartbeatStatus,
2557    pub network_name: Option<String>,
2558    pub network_self_link: Option<String>,
2559    pub subnetwork_name: Option<String>,
2560    pub subnetwork_self_link: Option<String>,
2561    pub region: Option<String>,
2562    pub cidr_block: Option<String>,
2563    pub router_name: Option<String>,
2564    pub cloud_nat_name: Option<String>,
2565    pub firewall_name: Option<String>,
2566    pub is_byo_vpc: bool,
2567}
2568
2569#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2570#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2571#[serde(rename_all = "camelCase")]
2572pub struct AzureVnetNetworkHeartbeatData {
2573    pub status: NetworkHeartbeatStatus,
2574    pub vnet_name: Option<String>,
2575    pub vnet_resource_id: Option<String>,
2576    pub resource_group: Option<String>,
2577    pub location: Option<String>,
2578    pub cidr_block: Option<String>,
2579    pub public_subnet_name: Option<String>,
2580    pub private_subnet_name: Option<String>,
2581    pub application_gateway_subnet_name: Option<String>,
2582    pub private_endpoint_subnet_name: Option<String>,
2583    pub nat_gateway_id: Option<String>,
2584    pub public_ip_id: Option<String>,
2585    pub nsg_id: Option<String>,
2586    pub is_byo_vnet: bool,
2587    pub last_byo_vnet_verification_error_code: Option<String>,
2588}
2589
2590#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2591#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2592#[serde(tag = "backend", rename_all = "camelCase")]
2593pub enum RemoteStackManagementHeartbeatData {
2594    AwsIamRole(AwsRemoteStackManagementHeartbeatData),
2595    GcpServiceAccount(GcpRemoteStackManagementHeartbeatData),
2596    AzureManagedIdentity(AzureRemoteStackManagementHeartbeatData),
2597}
2598
2599#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2600#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2601#[serde(rename_all = "camelCase")]
2602pub struct RemoteStackManagementHeartbeatStatus {
2603    pub health: ObservedHealth,
2604    pub lifecycle: ProviderLifecycleState,
2605    pub message: Option<String>,
2606    pub stale: bool,
2607    pub partial: bool,
2608    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2609}
2610
2611#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2612#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2613#[serde(rename_all = "camelCase")]
2614pub struct AwsRemoteStackManagementHeartbeatData {
2615    pub status: RemoteStackManagementHeartbeatStatus,
2616    pub role_name: Option<String>,
2617    pub role_arn: Option<String>,
2618    pub management_permissions_applied: bool,
2619}
2620
2621#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2622#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2623#[serde(rename_all = "camelCase")]
2624pub struct GcpRemoteStackManagementHeartbeatData {
2625    pub status: RemoteStackManagementHeartbeatStatus,
2626    pub service_account_email: Option<String>,
2627    pub service_account_unique_id: Option<String>,
2628    pub role_bound: bool,
2629    pub impersonation_granted: bool,
2630}
2631
2632#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2633#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2634#[serde(rename_all = "camelCase")]
2635pub struct AzureRemoteStackManagementHeartbeatData {
2636    pub status: RemoteStackManagementHeartbeatStatus,
2637    pub uami_resource_id: Option<String>,
2638    pub uami_client_id: Option<String>,
2639    pub uami_principal_id: Option<String>,
2640    pub tenant_id: Option<String>,
2641    pub fic_name: Option<String>,
2642    pub role_definition_id: Option<String>,
2643    pub role_assignment_ids: Vec<String>,
2644}
2645
2646#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2647#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2648#[serde(tag = "backend", rename_all = "camelCase")]
2649pub enum ArtifactRegistryHeartbeatData {
2650    AwsEcr(AwsEcrArtifactRegistryHeartbeatData),
2651    GcpArtifactRegistry(GcpArtifactRegistryHeartbeatData),
2652    AzureContainerRegistry(AzureContainerRegistryHeartbeatData),
2653    Local(LocalArtifactRegistryHeartbeatData),
2654}
2655
2656#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2657#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2658#[serde(rename_all = "camelCase")]
2659pub struct ArtifactRegistryHeartbeatStatus {
2660    pub health: ObservedHealth,
2661    pub lifecycle: ProviderLifecycleState,
2662    pub message: Option<String>,
2663    pub stale: bool,
2664    pub partial: bool,
2665    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2666}
2667
2668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2669#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2670#[serde(rename_all = "camelCase")]
2671pub struct AwsEcrArtifactRegistryHeartbeatData {
2672    pub status: ArtifactRegistryHeartbeatStatus,
2673    pub registry_id: String,
2674    pub region: String,
2675    pub registry_uri: String,
2676    pub repository_prefix: String,
2677    pub pull_role_arn: Option<String>,
2678    pub push_role_arn: Option<String>,
2679    pub repository_count: u32,
2680    pub repositories_truncated: bool,
2681    pub repositories: Vec<AwsEcrRepositoryHeartbeatData>,
2682}
2683
2684#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2685#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2686#[serde(rename_all = "camelCase")]
2687pub struct AwsEcrRepositoryHeartbeatData {
2688    pub repository_arn: String,
2689    pub registry_id: String,
2690    pub repository_name: String,
2691    pub repository_uri: String,
2692    pub created_at: f64,
2693    pub image_tag_mutability: Option<String>,
2694    pub scan_on_push: Option<bool>,
2695    pub encryption_type: Option<String>,
2696    pub kms_key_present: bool,
2697}
2698
2699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2700#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2701#[serde(rename_all = "camelCase")]
2702pub struct GcpArtifactRegistryHeartbeatData {
2703    pub status: ArtifactRegistryHeartbeatStatus,
2704    pub project_id: String,
2705    pub location: String,
2706    pub repository_id: String,
2707    pub name: Option<String>,
2708    pub format: Option<String>,
2709    pub mode: Option<String>,
2710    pub description: Option<String>,
2711    pub label_count: u32,
2712    pub cleanup_policy_count: u32,
2713    pub cleanup_policy_dry_run: Option<bool>,
2714    pub kms_key_name_present: bool,
2715    pub size_bytes: Option<String>,
2716    pub satisfies_pzs: Option<bool>,
2717    pub create_time: Option<String>,
2718    pub update_time: Option<String>,
2719    pub iam_policy_etag_present: bool,
2720    pub iam_binding_count: u32,
2721    pub iam_roles: Vec<String>,
2722    pub pull_service_account_email: Option<String>,
2723    pub push_service_account_email: Option<String>,
2724}
2725
2726#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2727#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2728#[serde(rename_all = "camelCase")]
2729pub struct AzureContainerRegistryHeartbeatData {
2730    pub status: ArtifactRegistryHeartbeatStatus,
2731    pub name: String,
2732    pub resource_id: Option<String>,
2733    pub resource_group: String,
2734    pub location: String,
2735    pub type_: Option<String>,
2736    pub login_server: Option<String>,
2737    pub sku_name: String,
2738    pub sku_tier: Option<String>,
2739    pub provisioning_state: Option<String>,
2740    pub admin_user_enabled: bool,
2741    pub anonymous_pull_enabled: bool,
2742    pub public_network_access: String,
2743    pub network_rule_bypass_options: String,
2744    pub network_rule_default_action: Option<String>,
2745    pub ip_rule_count: u32,
2746    pub encryption_status: Option<String>,
2747    pub encryption_key_vault_uri_present: bool,
2748    pub encryption_key_identifier_present: bool,
2749    pub policies_present: bool,
2750    pub policy_count: u32,
2751    pub private_endpoint_connection_count: u32,
2752    pub data_endpoint_enabled: Option<bool>,
2753    pub data_endpoint_host_names: Vec<String>,
2754    pub zone_redundancy: String,
2755    pub creation_date: Option<String>,
2756    pub managed_tag_count: u32,
2757}
2758
2759#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2760#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2761#[serde(rename_all = "camelCase")]
2762pub struct LocalArtifactRegistryHeartbeatData {
2763    pub status: ArtifactRegistryHeartbeatStatus,
2764    pub registry_url: String,
2765    pub reachable: bool,
2766}
2767
2768#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2769#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2770#[serde(tag = "backend", rename_all = "camelCase")]
2771pub enum BuildHeartbeatData {
2772    AwsCodeBuild(AwsCodeBuildHeartbeatData),
2773    GcpCloudBuild(GcpCloudBuildHeartbeatData),
2774    AzureContainerApps(AzureContainerAppsBuildHeartbeatData),
2775    KubernetesJob(KubernetesBuildHeartbeatData),
2776}
2777
2778#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2779#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2780#[serde(rename_all = "camelCase")]
2781pub struct BuildHeartbeatStatus {
2782    pub health: ObservedHealth,
2783    pub lifecycle: ProviderLifecycleState,
2784    pub message: Option<String>,
2785    pub stale: bool,
2786    pub partial: bool,
2787    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2788}
2789
2790#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2791#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2792#[serde(rename_all = "camelCase")]
2793pub struct AwsCodeBuildHeartbeatData {
2794    pub status: BuildHeartbeatStatus,
2795    pub project_name: String,
2796    pub project_arn: Option<String>,
2797    pub description: Option<String>,
2798    pub source_type: Option<String>,
2799    pub artifacts_type: Option<String>,
2800    pub artifacts_encryption_disabled: Option<bool>,
2801    pub environment_type: Option<String>,
2802    pub environment_image: Option<String>,
2803    pub compute_type: Option<String>,
2804    pub image_pull_credentials_type: Option<String>,
2805    pub privileged_mode: Option<bool>,
2806    pub environment_variable_count: u32,
2807    pub service_role_present: bool,
2808    pub encryption_key_present: bool,
2809    pub cloud_watch_logs_status: Option<String>,
2810    pub s3_logs_status: Option<String>,
2811    pub timeout_in_minutes: Option<i32>,
2812    pub queued_timeout_in_minutes: Option<i32>,
2813    pub created: Option<f64>,
2814    pub last_modified: Option<f64>,
2815}
2816
2817#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2818#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2819#[serde(rename_all = "camelCase")]
2820pub struct GcpCloudBuildHeartbeatData {
2821    pub status: BuildHeartbeatStatus,
2822    pub project_id: String,
2823    pub location: String,
2824    pub build_config_id: String,
2825    pub service_account: Option<String>,
2826    pub environment_variable_count: u32,
2827}
2828
2829#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2830#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2831#[serde(rename_all = "camelCase")]
2832pub struct AzureContainerAppsBuildHeartbeatData {
2833    pub status: BuildHeartbeatStatus,
2834    pub managed_environment_id: String,
2835    pub resource_group_name: String,
2836    pub managed_identity_id: Option<String>,
2837    pub resource_prefix: Option<String>,
2838    pub environment_variable_count: u32,
2839}
2840
2841#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2842#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2843#[serde(rename_all = "camelCase")]
2844pub struct KubernetesBuildHeartbeatData {
2845    pub status: BuildHeartbeatStatus,
2846    pub job_name: String,
2847    pub namespace: String,
2848    pub active: Option<i32>,
2849    pub succeeded: Option<i32>,
2850    pub failed: Option<i32>,
2851    pub start_time: Option<DateTime<Utc>>,
2852    pub completion_time: Option<DateTime<Utc>>,
2853    pub condition_count: u32,
2854    pub image_digest: Option<String>,
2855    pub events: Vec<KubernetesEventSnapshot>,
2856}
2857
2858#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2859#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2860#[serde(tag = "backend", rename_all = "camelCase")]
2861pub enum ServiceActivationHeartbeatData {
2862    GcpServiceUsage(GcpServiceUsageActivationHeartbeatData),
2863    AzureResourceProvider(AzureResourceProviderActivationHeartbeatData),
2864}
2865
2866#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2867#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2868#[serde(rename_all = "camelCase")]
2869pub struct ServiceActivationHeartbeatStatus {
2870    pub health: ObservedHealth,
2871    pub lifecycle: ProviderLifecycleState,
2872    pub message: Option<String>,
2873    pub stale: bool,
2874    pub partial: bool,
2875    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2876}
2877
2878impl Default for ServiceActivationHeartbeatStatus {
2879    fn default() -> Self {
2880        Self {
2881            health: ObservedHealth::Healthy,
2882            lifecycle: ProviderLifecycleState::Running,
2883            message: None,
2884            stale: false,
2885            partial: false,
2886            collection_issues: vec![],
2887        }
2888    }
2889}
2890
2891#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2892#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2893#[serde(rename_all = "camelCase")]
2894pub struct GcpServiceUsageActivationHeartbeatData {
2895    pub status: ServiceActivationHeartbeatStatus,
2896    pub project_id: String,
2897    pub service_name: String,
2898    pub service_resource_name: Option<String>,
2899    pub title: Option<String>,
2900    pub state: Option<String>,
2901    pub enabled: bool,
2902    pub last_operation_name: Option<String>,
2903}
2904
2905#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2906#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2907#[serde(rename_all = "camelCase")]
2908pub struct AzureResourceProviderActivationHeartbeatData {
2909    pub status: ServiceActivationHeartbeatStatus,
2910    pub namespace: String,
2911    pub provider_id: Option<String>,
2912    pub registration_state: Option<String>,
2913    pub registration_policy: Option<String>,
2914    pub resource_type_count: u32,
2915    pub registered: bool,
2916}
2917
2918#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2919#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2920#[serde(rename_all = "camelCase")]
2921pub struct AzureResourceGroupHeartbeatData {
2922    pub status: AzureResourceGroupHeartbeatStatus,
2923    pub name: String,
2924    pub resource_id: Option<String>,
2925    pub location: Option<String>,
2926    pub provisioning_state: Option<String>,
2927    pub managed_tags: BTreeMap<String, String>,
2928}
2929
2930#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2931#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2932#[serde(rename_all = "camelCase")]
2933pub struct AzureResourceGroupHeartbeatStatus {
2934    pub health: ObservedHealth,
2935    pub lifecycle: ProviderLifecycleState,
2936    pub message: Option<String>,
2937    pub stale: bool,
2938    pub partial: bool,
2939    pub collection_issues: Vec<HeartbeatCollectionIssue>,
2940}
2941
2942impl Default for AzureResourceGroupHeartbeatStatus {
2943    fn default() -> Self {
2944        Self {
2945            health: ObservedHealth::Healthy,
2946            lifecycle: ProviderLifecycleState::Running,
2947            message: None,
2948            stale: false,
2949            partial: false,
2950            collection_issues: vec![],
2951        }
2952    }
2953}
2954
2955#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2956#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2957#[serde(rename_all = "camelCase")]
2958pub struct AzureStorageAccountHeartbeatData {
2959    pub status: StorageHeartbeatStatus,
2960    pub name: String,
2961    pub resource_id: Option<String>,
2962    pub resource_group: Option<String>,
2963    pub location: Option<String>,
2964    pub kind: Option<String>,
2965    pub sku_name: Option<String>,
2966    pub sku_tier: Option<String>,
2967    pub provisioning_state: Option<String>,
2968    pub primary_endpoints: AzureStorageAccountEndpoints,
2969    pub secondary_endpoints: AzureStorageAccountEndpoints,
2970    pub public_network_access: Option<String>,
2971    pub allow_blob_public_access: Option<bool>,
2972    pub allow_shared_key_access: Option<bool>,
2973    pub minimum_tls_version: Option<String>,
2974    pub supports_https_traffic_only: Option<bool>,
2975    pub encryption_key_source: Option<String>,
2976    pub require_infrastructure_encryption: Option<bool>,
2977    pub network_default_action: Option<String>,
2978    pub network_bypass: Option<String>,
2979    pub network_ip_rule_count: Option<u32>,
2980    pub network_virtual_network_rule_count: Option<u32>,
2981    pub network_resource_access_rule_count: Option<u32>,
2982}
2983
2984#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
2985#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2986#[serde(rename_all = "camelCase")]
2987pub struct AzureStorageAccountEndpoints {
2988    pub blob: Option<String>,
2989    pub dfs: Option<String>,
2990    pub file: Option<String>,
2991    pub queue: Option<String>,
2992    pub table: Option<String>,
2993    pub web: Option<String>,
2994}
2995
2996#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
2997#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
2998#[serde(rename_all = "camelCase")]
2999pub struct AzureContainerAppsEnvironmentHeartbeatData {
3000    pub status: AzureContainerAppsEnvironmentHeartbeatStatus,
3001    pub name: String,
3002    pub resource_id: Option<String>,
3003    pub resource_group: Option<String>,
3004    pub location: Option<String>,
3005    pub kind: Option<String>,
3006    pub provisioning_state: Option<String>,
3007    pub default_domain: Option<String>,
3008    pub static_ip: Option<String>,
3009    pub custom_domain_verification_id: Option<String>,
3010    pub infrastructure_resource_group: Option<String>,
3011    pub event_stream_endpoint: Option<String>,
3012    pub zone_redundant: Option<bool>,
3013    pub workload_profile_count: u32,
3014    pub workload_profiles: Vec<AzureContainerAppsEnvironmentWorkloadProfile>,
3015}
3016
3017#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3018#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
3019#[serde(rename_all = "camelCase")]
3020pub struct AzureContainerAppsEnvironmentHeartbeatStatus {
3021    pub health: ObservedHealth,
3022    pub lifecycle: ProviderLifecycleState,
3023    pub message: Option<String>,
3024    pub stale: bool,
3025    pub partial: bool,
3026    pub collection_issues: Vec<HeartbeatCollectionIssue>,
3027}
3028
3029#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3030#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
3031#[serde(rename_all = "camelCase")]
3032pub struct AzureContainerAppsEnvironmentWorkloadProfile {
3033    pub name: String,
3034    pub workload_profile_type: String,
3035    pub minimum_count: Option<i32>,
3036    pub maximum_count: Option<i32>,
3037}
3038
3039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3040#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
3041#[serde(rename_all = "camelCase")]
3042pub struct AzureServiceBusNamespaceHeartbeatData {
3043    pub status: QueueHeartbeatStatus,
3044    pub name: String,
3045    pub resource_id: Option<String>,
3046    pub resource_group: Option<String>,
3047    pub location: Option<String>,
3048    pub sku_name: Option<String>,
3049    pub sku_tier: Option<String>,
3050    pub sku_capacity: Option<i32>,
3051    pub namespace_status: Option<String>,
3052    pub provisioning_state: Option<String>,
3053    pub service_bus_endpoint: Option<String>,
3054    pub metric_id: Option<String>,
3055    pub public_network_access: Option<String>,
3056    pub disable_local_auth: Option<bool>,
3057    pub minimum_tls_version: Option<String>,
3058    pub premium_messaging_partitions: Option<i32>,
3059    pub private_endpoint_connection_count: u32,
3060    pub zone_redundant: Option<bool>,
3061    pub created_at: Option<String>,
3062    pub updated_at: Option<String>,
3063}
3064
3065#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
3066#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
3067#[serde(rename_all = "camelCase")]
3068pub struct NamedResourceDetail {
3069    pub name: String,
3070    pub region: Option<String>,
3071}
3072
3073#[cfg(test)]
3074mod tests {
3075    use super::*;
3076    use chrono::TimeZone as _;
3077    use serde_json::json;
3078
3079    fn observed_at() -> DateTime<Utc> {
3080        Utc.with_ymd_and_hms(2026, 5, 28, 10, 30, 0).unwrap()
3081    }
3082
3083    fn workload_status() -> WorkloadHeartbeatStatus {
3084        WorkloadHeartbeatStatus {
3085            health: ObservedHealth::Healthy,
3086            lifecycle: ProviderLifecycleState::Running,
3087            message: None,
3088            stale: false,
3089            partial: false,
3090            collection_issues: vec![],
3091        }
3092    }
3093
3094    fn workload_replicas() -> WorkloadReplicaStatus {
3095        WorkloadReplicaStatus {
3096            desired: Some(2),
3097            current: Some(2),
3098            ready: Some(1),
3099            available: Some(1),
3100            updated: Some(2),
3101            misscheduled: None,
3102        }
3103    }
3104
3105    fn heartbeat(data: ResourceHeartbeatData, resource_type: &str) -> ResourceHeartbeat {
3106        ResourceHeartbeat {
3107            deployment_id: Some("dep_123".to_string()),
3108            resource_id: "api".to_string(),
3109            resource_type: ResourceType::from(resource_type),
3110            controller_platform: Platform::Kubernetes,
3111            backend: HeartbeatBackend::Kubernetes,
3112            observed_at: observed_at(),
3113            data,
3114            raw: vec![RawHeartbeatSnippet {
3115                source: "kubernetes/apps/v1/deployments/api".to_string(),
3116                format: RawHeartbeatSnippetFormat::Json,
3117                collected_at: observed_at(),
3118                body: r#"{"readyReplicas":1}"#.to_string(),
3119                truncated: false,
3120            }],
3121        }
3122    }
3123
3124    #[test]
3125    fn resource_heartbeat_roundtrips_managed_resource_data() {
3126        let heartbeat_json = serde_json::to_value(heartbeat(
3127            ResourceHeartbeatData::Container(ContainerHeartbeatData::Kubernetes(
3128                KubernetesContainerHeartbeatData {
3129                    status: workload_status(),
3130                    namespace: "default".to_string(),
3131                    name: "api".to_string(),
3132                    workload_kind: KubernetesWorkloadKind::Deployment,
3133                    replicas: workload_replicas(),
3134                    restarts: None,
3135                    cpu: None,
3136                    memory: None,
3137                    workload: None,
3138                    pods: vec![],
3139                    events: vec![],
3140                },
3141            )),
3142            "container",
3143        ))
3144        .unwrap();
3145
3146        let parsed: ResourceHeartbeat = serde_json::from_value(heartbeat_json).unwrap();
3147        assert_eq!(parsed.resource_id, "api");
3148        assert!(matches!(
3149            parsed.data,
3150            ResourceHeartbeatData::Container(ContainerHeartbeatData::Kubernetes(_))
3151        ));
3152    }
3153
3154    #[test]
3155    fn local_daemon_heartbeat_defaults_missing_daemon_name() {
3156        let mut value =
3157            serde_json::to_value(DaemonHeartbeatData::Local(LocalDaemonHeartbeatData {
3158                status: workload_status(),
3159                daemon_name: "agent".to_string(),
3160                runtime_id: "local-agent".to_string(),
3161                pid: None,
3162                command_supported: false,
3163                image_path_present: true,
3164                restart_count: None,
3165                exit_reason: None,
3166                daemon_instance: None,
3167                events: vec![],
3168            }))
3169            .unwrap();
3170
3171        value.as_object_mut().unwrap().remove("daemonName");
3172
3173        let parsed: DaemonHeartbeatData = serde_json::from_value(value).unwrap();
3174        match parsed {
3175            DaemonHeartbeatData::Local(data) => assert_eq!(data.daemon_name, ""),
3176            other => panic!("expected local daemon heartbeat, got {other:?}"),
3177        }
3178    }
3179
3180    #[test]
3181    fn container_heartbeat_serializes_resource_first_data() {
3182        let heartbeat = heartbeat(
3183            ResourceHeartbeatData::Container(ContainerHeartbeatData::Kubernetes(
3184                KubernetesContainerHeartbeatData {
3185                    status: workload_status(),
3186                    namespace: "default".to_string(),
3187                    name: "api".to_string(),
3188                    workload_kind: KubernetesWorkloadKind::Deployment,
3189                    replicas: workload_replicas(),
3190                    restarts: Some(1),
3191                    cpu: Some(MetricSample {
3192                        value: 0.5,
3193                        unit: MetricUnit::Cores,
3194                    }),
3195                    memory: None,
3196                    workload: None,
3197                    pods: vec![],
3198                    events: vec![],
3199                },
3200            )),
3201            "container",
3202        );
3203
3204        let value = serde_json::to_value(&heartbeat).unwrap();
3205
3206        assert_eq!(value["resourceType"], "container");
3207        assert_eq!(value["data"]["resourceType"], "container");
3208        assert_eq!(value["data"]["data"]["backend"], "kubernetes");
3209        assert_eq!(value["raw"][0]["body"], r#"{"readyReplicas":1}"#);
3210        assert!(value.get("collection").is_none());
3211        assert!(value["data"]["data"].get("summary").is_none());
3212        assert!(value["data"]["data"].get("detail").is_none());
3213    }
3214
3215    #[test]
3216    fn representative_workload_data_has_stable_tags() {
3217        let daemon = serde_json::to_value(ResourceHeartbeatData::Daemon(
3218            DaemonHeartbeatData::Kubernetes(KubernetesDaemonHeartbeatData {
3219                status: workload_status(),
3220                namespace: "default".to_string(),
3221                name: "agent".to_string(),
3222                replicas: workload_replicas(),
3223                restarts: Some(0),
3224                command_supported: true,
3225                cpu: None,
3226                memory: None,
3227                workload: None,
3228                pods: vec![],
3229                events: vec![],
3230            }),
3231        ))
3232        .unwrap();
3233        let worker = serde_json::to_value(ResourceHeartbeatData::Worker(
3234            WorkerHeartbeatData::AwsLambda(AwsLambdaWorkerHeartbeatData {
3235                status: workload_status(),
3236                function_name: "handler".to_string(),
3237                runtime: Some("nodejs22.x".to_string()),
3238                package_type: None,
3239                memory_size_mb: None,
3240                timeout_seconds: None,
3241                version: None,
3242                revision_id: None,
3243                last_modified: None,
3244                state: None,
3245                state_reason: None,
3246                state_reason_code: None,
3247                last_update_status: None,
3248                last_update_status_reason: None,
3249                last_update_status_reason_code: None,
3250                code_sha256: None,
3251                layer_count: 0,
3252                function_url_auth_type: None,
3253                function_url_cors_present: false,
3254                trigger_count: 0,
3255            }),
3256        ))
3257        .unwrap();
3258
3259        assert_eq!(daemon["resourceType"], "daemon");
3260        assert_eq!(daemon["data"]["backend"], "kubernetes");
3261        assert_eq!(worker["resourceType"], "worker");
3262        assert_eq!(worker["data"]["backend"], "awsLambda");
3263    }
3264
3265    /// A variant that compiles can still be unreadable on the wire: the transport round-trips every
3266    /// heartbeat through the generated manager type, which matches on the tag string alone.
3267    #[test]
3268    fn gcp_sandbox_heartbeat_keeps_its_wire_tag_and_camel_case_names() {
3269        let data = ResourceHeartbeatData::Sandbox(SandboxHeartbeatData::GcpAgentPlatform(
3270            GcpAgentPlatformSandboxHeartbeatData {
3271                status: SandboxHeartbeatStatus::default(),
3272                engine: "eng".to_string(),
3273                template_id: "tpl1".to_string(),
3274            },
3275        ));
3276
3277        let value = serde_json::to_value(&data).unwrap();
3278        assert_eq!(
3279            value,
3280            json!({
3281                "resourceType": "sandbox",
3282                "data": {
3283                    "backend": "gcpAgentPlatform",
3284                    "status": {
3285                        "health": "healthy",
3286                        "lifecycle": "running",
3287                        "message": null,
3288                        "stale": false,
3289                        "partial": false,
3290                        "collectionIssues": []
3291                    },
3292                    "engine": "eng",
3293                    "templateId": "tpl1"
3294                }
3295            })
3296        );
3297
3298        let parsed: ResourceHeartbeatData = serde_json::from_value(value).unwrap();
3299        assert_eq!(parsed, data);
3300    }
3301
3302    #[test]
3303    fn representative_cluster_and_data_variants_have_optional_counts() {
3304        let cluster = serde_json::to_value(ResourceHeartbeatData::KubernetesCluster(
3305            KubernetesClusterHeartbeatData {
3306                status: WorkloadHeartbeatStatus {
3307                    health: ObservedHealth::Healthy,
3308                    lifecycle: ProviderLifecycleState::Running,
3309                    message: None,
3310                    stale: false,
3311                    partial: false,
3312                    collection_issues: vec![],
3313                },
3314                node_counts: ObservedCounts {
3315                    desired: Some(3),
3316                    current: Some(3),
3317                    ready: None,
3318                },
3319                pod_counts: ObservedCounts {
3320                    desired: None,
3321                    current: Some(12),
3322                    ready: Some(11),
3323                },
3324                cpu: None,
3325                memory: None,
3326                name: "prod".to_string(),
3327                region: Some("us-east-1".to_string()),
3328                namespace: None,
3329                version: Some("1.33".to_string()),
3330                node_statuses: vec![],
3331                events: vec![],
3332            },
3333        ))
3334        .unwrap();
3335        let queue = serde_json::to_value(ResourceHeartbeatData::Queue(QueueHeartbeatData::AwsSqs(
3336            AwsSqsQueueHeartbeatData {
3337                status: QueueHeartbeatStatus {
3338                    health: ObservedHealth::Healthy,
3339                    lifecycle: ProviderLifecycleState::Running,
3340                    message: None,
3341                    stale: false,
3342                    partial: false,
3343                    collection_issues: vec![],
3344                },
3345                name: "jobs".to_string(),
3346                region: Some("us-east-1".to_string()),
3347                queue_url: Some("https://sqs.us-east-1.amazonaws.com/123/jobs".to_string()),
3348                queue_arn: Some("arn:aws:sqs:us-east-1:123:jobs".to_string()),
3349                visibility_timeout_seconds: Some(30),
3350                message_retention_period_seconds: Some(345600),
3351                delay_seconds: Some(0),
3352                receive_message_wait_time_seconds: Some(0),
3353                maximum_message_size: Some(262144),
3354                redrive_policy: None,
3355                redrive_allow_policy: None,
3356                fifo_queue: Some(false),
3357                content_based_deduplication: None,
3358                deduplication_scope: None,
3359                fifo_throughput_limit: None,
3360                sse_enabled: Some(false),
3361                kms_master_key_id: None,
3362                kms_data_key_reuse_period_seconds: None,
3363                sqs_managed_sse_enabled: Some(false),
3364                approximate_visible_messages: Some(42),
3365                approximate_in_flight_messages: Some(1),
3366                approximate_delayed_messages: Some(0),
3367                approximate_counts: true,
3368            },
3369        )))
3370        .unwrap();
3371        let storage = serde_json::to_value(ResourceHeartbeatData::Storage(
3372            StorageHeartbeatData::AwsS3(AwsS3StorageHeartbeatData {
3373                status: StorageHeartbeatStatus {
3374                    health: ObservedHealth::Healthy,
3375                    lifecycle: ProviderLifecycleState::Running,
3376                    message: None,
3377                    stale: false,
3378                    partial: false,
3379                    collection_issues: vec![],
3380                },
3381                name: "assets".to_string(),
3382                region: Some("us-east-1".to_string()),
3383                bucket_location: Some("us-east-1".to_string()),
3384                versioning_status: Some("Enabled".to_string()),
3385                versioning_enabled: Some(true),
3386                lifecycle_present: false,
3387                lifecycle_rule_count: Some(0),
3388                encryption_config_present: true,
3389                encryption_enabled: Some(true),
3390                public_access_block_present: true,
3391                block_public_acls: Some(true),
3392                ignore_public_acls: Some(true),
3393                block_public_policy: Some(true),
3394                restrict_public_buckets: Some(true),
3395                bucket_policy_present: Some(false),
3396                bucket_acl_present: Some(true),
3397            }),
3398        ))
3399        .unwrap();
3400        let gcp_storage = serde_json::to_value(ResourceHeartbeatData::Storage(
3401            StorageHeartbeatData::GcpCloudStorage(GcpCloudStorageHeartbeatData {
3402                status: StorageHeartbeatStatus {
3403                    health: ObservedHealth::Healthy,
3404                    lifecycle: ProviderLifecycleState::Running,
3405                    message: None,
3406                    stale: false,
3407                    partial: false,
3408                    collection_issues: vec![],
3409                },
3410                name: "assets".to_string(),
3411                bucket_id: Some("project/assets".to_string()),
3412                location: Some("US".to_string()),
3413                location_type: Some("multi-region".to_string()),
3414                storage_class: Some("STANDARD".to_string()),
3415                versioning_enabled: Some(true),
3416                lifecycle_present: false,
3417                lifecycle_rule_count: Some(0),
3418                retention_policy_effective_time: None,
3419                retention_policy_is_locked: None,
3420                retention_period: None,
3421                soft_delete_retention_duration_seconds: None,
3422                soft_delete_effective_time: None,
3423                uniform_bucket_level_access_enabled: Some(true),
3424                uniform_bucket_level_access_locked_time: None,
3425                public_access_prevention: Some("enforced".to_string()),
3426                encryption_config_present: true,
3427                default_kms_key_name: Some(
3428                    "projects/p/locations/l/keyRings/r/cryptoKeys/k".to_string(),
3429                ),
3430            }),
3431        ))
3432        .unwrap();
3433        let kv = serde_json::to_value(ResourceHeartbeatData::Kv(KvHeartbeatData::AwsDynamoDb(
3434            AwsDynamoDbKvHeartbeatData {
3435                status: KvHeartbeatStatus {
3436                    health: ObservedHealth::Healthy,
3437                    lifecycle: ProviderLifecycleState::Running,
3438                    message: None,
3439                    stale: false,
3440                    partial: false,
3441                    collection_issues: vec![],
3442                },
3443                name: "state".to_string(),
3444                region: Some("us-east-1".to_string()),
3445                table_arn: None,
3446                table_status: Some("ACTIVE".to_string()),
3447                billing_mode: Some("PAY_PER_REQUEST".to_string()),
3448                key_schema: vec![AwsDynamoDbKeySchemaElement {
3449                    attribute_name: "pk".to_string(),
3450                    key_type: "HASH".to_string(),
3451                }],
3452                global_secondary_index_count: Some(0),
3453                local_secondary_index_count: Some(0),
3454                item_count: None,
3455                table_size_bytes: None,
3456                stream_enabled: Some(false),
3457                stream_view_type: None,
3458                ttl_status: Some("ENABLED".to_string()),
3459                ttl_attribute_name: Some("ttl".to_string()),
3460                deletion_protection_enabled: Some(false),
3461                sse_status: Some("ENABLED".to_string()),
3462                sse_type: Some("KMS".to_string()),
3463                table_class: None,
3464                replica_count: Some(0),
3465                restore_in_progress: None,
3466            },
3467        )))
3468        .unwrap();
3469
3470        assert_eq!(cluster["resourceType"], "kubernetes-cluster");
3471        assert!(cluster["data"].get("summary").is_none());
3472        assert!(cluster["data"].get("detail").is_none());
3473        assert_eq!(cluster["data"]["name"], "prod");
3474        assert_eq!(queue["data"]["backend"], "awsSqs");
3475        assert_eq!(queue["data"]["approximateVisibleMessages"], 42);
3476        assert!(queue["data"].get("summary").is_none());
3477        assert_eq!(storage["data"]["backend"], "awsS3");
3478        assert!(storage["data"].get("summary").is_none());
3479        assert_eq!(gcp_storage["data"]["backend"], "gcpCloudStorage");
3480        assert_eq!(gcp_storage["data"]["publicAccessPrevention"], "enforced");
3481        assert_eq!(kv["data"]["backend"], "awsDynamoDb");
3482        assert!(kv["data"].get("summary").is_none());
3483        assert_eq!(kv["data"]["itemCount"], json!(null));
3484    }
3485
3486    #[test]
3487    fn ai_heartbeat_serializes_stable_tags() {
3488        let aws = serde_json::to_value(ResourceHeartbeatData::Ai(AiHeartbeatData::AwsBedrock(
3489            AwsBedrockAiHeartbeatData {
3490                status: AiHeartbeatStatus::default(),
3491                region: "us-east-1".to_string(),
3492                availability: AiAvailabilityObservation::unobserved(
3493                    AiAvailabilitySource::AwsBedrock,
3494                    Platform::Aws,
3495                    Some("us-east-1".to_string()),
3496                ),
3497            },
3498        )))
3499        .unwrap();
3500        let gcp = serde_json::to_value(ResourceHeartbeatData::Ai(AiHeartbeatData::GcpVertex(
3501            GcpVertexAiHeartbeatData {
3502                status: AiHeartbeatStatus::default(),
3503                project: "my-project".to_string(),
3504                location: "us-central1".to_string(),
3505                availability: AiAvailabilityObservation::unobserved(
3506                    AiAvailabilitySource::GcpVertex,
3507                    Platform::Gcp,
3508                    Some("us-central1".to_string()),
3509                ),
3510            },
3511        )))
3512        .unwrap();
3513        let azure = serde_json::to_value(ResourceHeartbeatData::Ai(AiHeartbeatData::AzureFoundry(
3514            AzureFoundryAiHeartbeatData {
3515                status: AiHeartbeatStatus::default(),
3516                account_name: "my-ai-account".to_string(),
3517                endpoint: Some("https://my-ai-account.openai.azure.com/".to_string()),
3518                resource_group: Some("my-rg".to_string()),
3519                location: Some("eastus".to_string()),
3520                availability: AiAvailabilityObservation::unobserved(
3521                    AiAvailabilitySource::AzureFoundry,
3522                    Platform::Azure,
3523                    Some("eastus".to_string()),
3524                ),
3525            },
3526        )))
3527        .unwrap();
3528
3529        assert_eq!(aws["resourceType"], "ai");
3530        assert_eq!(aws["data"]["backend"], "awsBedrock");
3531        assert_eq!(aws["data"]["region"], "us-east-1");
3532        assert!(aws["data"].get("summary").is_none());
3533
3534        assert_eq!(gcp["resourceType"], "ai");
3535        assert_eq!(gcp["data"]["backend"], "gcpVertex");
3536        assert_eq!(gcp["data"]["project"], "my-project");
3537        assert_eq!(gcp["data"]["location"], "us-central1");
3538
3539        assert_eq!(azure["resourceType"], "ai");
3540        assert_eq!(azure["data"]["backend"], "azureFoundry");
3541        assert_eq!(azure["data"]["accountName"], "my-ai-account");
3542        assert_eq!(
3543            azure["data"]["endpoint"],
3544            "https://my-ai-account.openai.azure.com/"
3545        );
3546    }
3547
3548    fn status_json() -> JsonValue {
3549        json!({
3550            "health": "healthy", "lifecycle": "unknown", "message": null,
3551            "stale": false, "partial": false, "collectionIssues": []
3552        })
3553    }
3554
3555    #[test]
3556    fn custom_heartbeat_round_trips_and_built_in_heartbeats_stay_typed() {
3557        let custom = json!({
3558            "deploymentId": null,
3559            "resourceId": "zone",
3560            "resourceType": "acme/dns-zone",
3561            "controllerPlatform": "aws",
3562            "backend": "aws",
3563            "observedAt": "2026-11-06T00:00:00Z",
3564            "data": {
3565                "resourceType": "acme/dns-zone",
3566                "data": { "status": status_json(), "details": { "records": 12 } }
3567            },
3568            "raw": []
3569        });
3570        let heartbeat: ResourceHeartbeat = serde_json::from_value(custom.clone()).unwrap();
3571        let ResourceHeartbeatData::Custom(data) = &heartbeat.data else {
3572            panic!("expected Custom, got {:?}", heartbeat.data);
3573        };
3574        assert_eq!(data.resource_type.as_ref(), "acme/dns-zone");
3575        assert_eq!(data.data.status.health, ObservedHealth::Healthy);
3576        assert_eq!(data.data.details["records"], 12);
3577        assert_eq!(serde_json::to_value(&heartbeat).unwrap(), custom);
3578
3579        let built_in: ResourceHeartbeatData = serde_json::from_value(json!({
3580            "resourceType": "service-account",
3581            "data": {
3582                "backend": "local",
3583                "status": status_json(),
3584                "identity": "sa",
3585                "configured": true
3586            }
3587        }))
3588        .unwrap();
3589        assert!(
3590            matches!(built_in, ResourceHeartbeatData::ServiceAccount(_)),
3591            "{built_in:?}"
3592        );
3593    }
3594
3595    #[test]
3596    fn malformed_built_in_heartbeat_is_refused() {
3597        // The body is a valid custom heartbeat body, so only the tag keeps it from loading.
3598        let err = serde_json::from_value::<ResourceHeartbeatData>(json!({
3599            "resourceType": "service-account",
3600            "data": { "status": status_json() }
3601        }))
3602        .expect_err("a service-account heartbeat needs its backend");
3603        assert!(err.to_string().contains("backend"), "{err}");
3604    }
3605
3606    #[test]
3607    fn unknown_heartbeat_type_outside_an_extension_namespace_is_refused() {
3608        for tag in ["not-a-resource", "alien/dns-zone", "experimental/dns-zone"] {
3609            let err = serde_json::from_value::<ResourceHeartbeatData>(json!({
3610                "resourceType": tag,
3611                "data": { "status": status_json() }
3612            }))
3613            .expect_err(tag);
3614            assert!(err.to_string().contains("unknown variant"), "{err}");
3615        }
3616    }
3617
3618    /// The schema lists the built-in variants by hand. A variant added to the enum and not to
3619    /// the schema, or the other way round, fails here.
3620    #[cfg(feature = "openapi")]
3621    #[test]
3622    fn heartbeat_schema_lists_every_built_in_variant_and_custom() {
3623        use utoipa::PartialSchema as _;
3624
3625        let refusal = serde_json::from_value::<ResourceHeartbeatData>(json!({
3626            "resourceType": "not-a-resource",
3627            "data": {}
3628        }))
3629        .expect_err("an unknown tag is refused")
3630        .to_string();
3631        let mut variants: Vec<&str> = refusal
3632            .split('`')
3633            .skip(1)
3634            .step_by(2)
3635            .filter(|tag| *tag != "not-a-resource")
3636            .collect();
3637        variants.sort_unstable();
3638
3639        let schema = serde_json::to_value(ResourceHeartbeatData::schema()).unwrap();
3640        let items = schema["oneOf"].as_array().expect("a oneOf");
3641        // The custom variant comes last, inline like the others, so a generator that sorts a
3642        // union's references first or tries members in order reaches it after the built-ins.
3643        let (custom, built_in) = items.split_last().expect("at least the custom variant");
3644        let mut schema_tags: Vec<&str> = built_in
3645            .iter()
3646            .map(|item| {
3647                item["properties"]["resourceType"]["enum"][0]
3648                    .as_str()
3649                    .unwrap()
3650            })
3651            .collect();
3652        schema_tags.sort_unstable();
3653
3654        assert_eq!(schema_tags, variants);
3655        assert_eq!(custom.get("$ref"), None, "{custom}");
3656        assert_eq!(
3657            custom["properties"]["resourceType"]["$ref"],
3658            "#/components/schemas/CustomResourceType"
3659        );
3660        assert_eq!(
3661            custom["properties"]["data"]["$ref"],
3662            "#/components/schemas/CustomHeartbeatData"
3663        );
3664    }
3665}