|
| 1 | +// Copyright 2025 OpenObserve Inc. |
| 2 | +// |
| 3 | +// This program is free software: you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU Affero General Public License as published by |
| 5 | +// the Free Software Foundation, either version 3 of the License, or |
| 6 | +// (at your option) any later version. |
| 7 | +// |
| 8 | +// This program is distributed in the hope that it will be useful |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU Affero General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU Affero General Public License |
| 14 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +use serde::{Deserialize,Serialize}; |
| 17 | +use utoipa::ToSchema; |
| 18 | + |
| 19 | +/// Service Graph topology snapshot record |
| 20 | +/// Stored in ServiceGraph stream for historical queries |
| 21 | +#[derive(Clone,Debug,Serialize,Deserialize,ToSchema)] |
| 22 | +pubstructServiceGraphSnapshot{ |
| 23 | +/// Snapshot timestamp (microseconds since epoch) |
| 24 | +#[serde(rename ="_timestamp")] |
| 25 | +pubtimestamp:i64, |
| 26 | + |
| 27 | +/// Organization identifier |
| 28 | +puborg_id:String, |
| 29 | + |
| 30 | +/// Source trace stream name |
| 31 | +pubtrace_stream_name:String, |
| 32 | + |
| 33 | +/// Client service name (initiator) |
| 34 | +pubclient_service:String, |
| 35 | + |
| 36 | +/// Server service name (receiver) |
| 37 | +pubserver_service:String, |
| 38 | + |
| 39 | +/// Connection type: "standard", "database", "messaging", "virtual" |
| 40 | +pubconnection_type:String, |
| 41 | + |
| 42 | +/// Total requests (cumulative counter) |
| 43 | +pubtotal_requests:u64, |
| 44 | + |
| 45 | +/// Failed requests (cumulative counter) |
| 46 | +pubfailed_requests:u64, |
| 47 | + |
| 48 | +/// Error rate percentage (0-100) |
| 49 | +puberror_rate:f64, |
| 50 | + |
| 51 | +/// P50 latency in nanoseconds |
| 52 | +pubp50_latency_ns:u64, |
| 53 | + |
| 54 | +/// P95 latency in nanoseconds |
| 55 | +pubp95_latency_ns:u64, |
| 56 | + |
| 57 | +/// P99 latency in nanoseconds |
| 58 | +pubp99_latency_ns:u64, |
| 59 | + |
| 60 | +/// First time this edge was seen (microseconds) |
| 61 | +pubfirst_seen:i64, |
| 62 | + |
| 63 | +/// Last time this edge was seen (microseconds) |
| 64 | +publast_seen:i64, |
| 65 | + |
| 66 | +/// Snapshot version (monotonic counter for deduplication) |
| 67 | +pubsnapshot_version:u64, |
| 68 | +} |
| 69 | + |
| 70 | +implServiceGraphSnapshot{ |
| 71 | +/// Convert to JSON value for stream ingestion |
| 72 | +pubfnto_json(&self) -> serde_json::Value{ |
| 73 | + serde_json::to_value(self).expect("Failed to serialize ServiceGraphSnapshot") |
| 74 | +} |
| 75 | +} |
| 76 | + |
| 77 | +/// Graph format for frontend visualization |
| 78 | +#[derive(Clone,Debug,Serialize,Deserialize,ToSchema)] |
| 79 | +pubstructServiceGraphData{ |
| 80 | +pubnodes:Vec<ServiceNode>, |
| 81 | +pubedges:Vec<ServiceEdge>, |
| 82 | +} |
| 83 | + |
| 84 | +/// Node in service graph |
| 85 | +#[derive(Clone,Debug,Serialize,Deserialize,ToSchema)] |
| 86 | +pubstructServiceNode{ |
| 87 | +pubid:String, |
| 88 | +publabel:String, |
| 89 | +pubrequests:u64, |
| 90 | +puberrors:u64, |
| 91 | +puberror_rate:f64, |
| 92 | +} |
| 93 | + |
| 94 | +/// Edge in service graph |
| 95 | +#[derive(Clone,Debug,Serialize,Deserialize,ToSchema)] |
| 96 | +pubstructServiceEdge{ |
| 97 | +pubfrom:String, |
| 98 | +pubto:String, |
| 99 | +pubtotal_requests:u64, |
| 100 | +pubfailed_requests:u64, |
| 101 | +puberror_rate:f64, |
| 102 | +pubp50_latency_ns:u64, |
| 103 | +pubp95_latency_ns:u64, |
| 104 | +pubp99_latency_ns:u64, |
| 105 | +pubconnection_type:String, |
| 106 | +} |