tatara_core/catalog/
mod.rs1use chrono::{DateTime, Utc};
9use serde::{Deserialize, Serialize};
10use std::collections::HashMap;
11
12#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
14#[serde(rename_all = "snake_case")]
15pub enum ServiceHealth {
16 Passing,
17 Warning,
18 Critical,
19 Maintenance,
20}
21
22impl Default for ServiceHealth {
23 fn default() -> Self {
24 Self::Passing
25 }
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct ServiceEntry {
31 pub service_name: String,
33
34 pub service_id: String,
36
37 pub node_id: String,
39
40 pub address: String,
42
43 pub port: u16,
45
46 #[serde(default)]
48 pub tags: Vec<String>,
49
50 #[serde(default)]
52 pub meta: HashMap<String, String>,
53
54 #[serde(default)]
56 pub health: ServiceHealth,
57
58 pub registered_at: DateTime<Utc>,
60
61 pub alloc_id: Option<String>,
63}
64
65#[derive(Debug, Clone, Default)]
67pub struct ServiceQuery {
68 pub service: String,
70
71 pub tag: Option<String>,
73
74 pub healthy_only: bool,
76
77 pub near: Option<String>,
79}
80
81impl ServiceEntry {
82 pub fn matches(&self, query: &ServiceQuery) -> bool {
84 if self.service_name != query.service {
85 return false;
86 }
87 if let Some(tag) = &query.tag {
88 if !self.tags.contains(tag) {
89 return false;
90 }
91 }
92 if query.healthy_only && self.health != ServiceHealth::Passing {
93 return false;
94 }
95 true
96 }
97}