oxirs-stream 0.2.4

Real-time streaming support with Kafka/NATS/MQTT/OPC-UA I/O, RDF Patch, and SPARQL Update delta
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
//! Observability Configuration Types

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub struct ObservabilityConfig {
    /// Monitoring configuration
    pub monitoring: MonitoringConfig,
    /// Logging configuration
    pub logging: LoggingConfig,
    /// Alerting configuration
    pub alerting: AlertingConfig,
    /// Dashboards configuration
    pub dashboards: DashboardConfig,
}

impl Default for ObservabilityConfig {
    fn default() -> Self {
        Self {
            monitoring: MonitoringConfig::default(),
            logging: LoggingConfig::default(),
            alerting: AlertingConfig::default(),
            dashboards: DashboardConfig::default(),
        }
    }
}

/// Monitoring configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MonitoringConfig {
    /// Prometheus configuration
    pub prometheus: PrometheusConfig,
    /// Service monitors
    pub service_monitors: Vec<ServiceMonitor>,
    /// Pod monitors
    pub pod_monitors: Vec<PodMonitor>,
}

impl Default for MonitoringConfig {
    fn default() -> Self {
        Self {
            prometheus: PrometheusConfig::default(),
            service_monitors: vec![
                ServiceMonitor {
                    name: "oxirs-stream-monitor".to_string(),
                    namespace: "oxirs".to_string(),
                    selector: LabelSelector {
                        match_labels: BTreeMap::from([
                            ("app".to_string(), "oxirs-stream".to_string()),
                        ]),
                    },
                    endpoints: vec![
                        ServiceMonitorEndpoint {
                            port: "metrics".to_string(),
                            path: "/metrics".to_string(),
                            interval: Duration::from_secs(30),
                        },
                    ],
                },
            ],
            pod_monitors: vec![],
        }
    }
}

/// Prometheus configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PrometheusConfig {
    /// Enable Prometheus
    pub enabled: bool,
    /// Retention period
    pub retention: Duration,
    /// Storage size
    pub storage_size: String,
    /// Resource requirements
    pub resources: ResourceRequirements,
}

impl Default for PrometheusConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            retention: Duration::from_secs(30 * 24 * 3600), // 30 days
            storage_size: "50Gi".to_string(),
            resources: ResourceRequirements {
                cpu: "2".to_string(),
                memory: "4Gi".to_string(),
            },
        }
    }
}

/// Service monitor
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServiceMonitor {
    pub name: String,
    pub namespace: String,
    pub selector: LabelSelector,
    pub endpoints: Vec<ServiceMonitorEndpoint>,
}

/// Service monitor endpoint
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServiceMonitorEndpoint {
    pub port: String,
    pub path: String,
    pub interval: Duration,
}

/// Pod monitor
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PodMonitor {
    pub name: String,
    pub namespace: String,
    pub selector: LabelSelector,
    pub pod_metrics_endpoints: Vec<PodMetricsEndpoint>,
}

/// Pod metrics endpoint
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PodMetricsEndpoint {
    pub port: String,
    pub path: String,
    pub interval: Duration,
}

/// Logging configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoggingConfig {
    /// Log aggregation
    pub aggregation: LogAggregationConfig,
    /// Log forwarding
    pub forwarding: LogForwardingConfig,
    /// Log retention
    pub retention: LogRetentionConfig,
}

impl Default for LoggingConfig {
    fn default() -> Self {
        Self {
            aggregation: LogAggregationConfig::default(),
            forwarding: LogForwardingConfig::default(),
            retention: LogRetentionConfig::default(),
        }
    }
}

/// Log aggregation configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogAggregationConfig {
    /// Enable log aggregation
    pub enabled: bool,
    /// Aggregation provider
    pub provider: LogAggregationProvider,
    /// Buffer size
    pub buffer_size: usize,
    /// Flush interval
    pub flush_interval: Duration,
}

impl Default for LogAggregationConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            provider: LogAggregationProvider::Fluentd,
            buffer_size: 64 * 1024, // 64KB
            flush_interval: Duration::from_secs(10),
        }
    }
}

/// Log aggregation providers
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum LogAggregationProvider {
    Fluentd,
    Fluent_Bit,
    Logstash,
    Vector,
}

/// Log forwarding configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogForwardingConfig {
    /// Enable log forwarding
    pub enabled: bool,
    /// Forwarding destinations
    pub destinations: Vec<LogDestination>,
}

impl Default for LogForwardingConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            destinations: vec![
                LogDestination {
                    name: "elasticsearch".to_string(),
                    destination_type: LogDestinationType::Elasticsearch,
                    endpoint: "https://elasticsearch.example.com:9200".to_string(),
                    index: "oxirs-logs".to_string(),
                },
            ],
        }
    }
}

/// Log destination
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogDestination {
    pub name: String,
    pub destination_type: LogDestinationType,
    pub endpoint: String,
    pub index: String,
}

/// Log destination types
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum LogDestinationType {
    Elasticsearch,
    Splunk,
    CloudWatch,
    BigQuery,
    S3,
}

/// Log retention configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogRetentionConfig {
    /// Retention period
    pub retention_period: Duration,
    /// Compression enabled
    pub compression: bool,
    /// Archive to cold storage
    pub cold_storage: bool,
}

impl Default for LogRetentionConfig {
    fn default() -> Self {
        Self {
            retention_period: Duration::from_secs(90 * 24 * 3600), // 90 days
            compression: true,
            cold_storage: true,
        }
    }
}

/// Alerting configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlertingConfig {
    /// Alert manager configuration
    pub alert_manager: AlertManagerConfig,
    /// Alert rules
    pub rules: Vec<AlertRule>,
    /// Notification channels
    pub notification_channels: Vec<NotificationChannel>,
}

impl Default for AlertingConfig {
    fn default() -> Self {
        Self {
            alert_manager: AlertManagerConfig::default(),
            rules: vec![
                AlertRule {
                    name: "high-cpu-usage".to_string(),
                    expression: "rate(container_cpu_usage_seconds_total[5m]) > 0.8".to_string(),
                    duration: Duration::from_secs(300),
                    severity: AlertSeverity::Warning,
                    summary: "High CPU usage detected".to_string(),
                    description: "CPU usage is above 80% for more than 5 minutes".to_string(),
                },
                AlertRule {
                    name: "high-memory-usage".to_string(),
                    expression: "container_memory_usage_bytes / container_spec_memory_limit_bytes > 0.9".to_string(),
                    duration: Duration::from_secs(300),
                    severity: AlertSeverity::Critical,
                    summary: "High memory usage detected".to_string(),
                    description: "Memory usage is above 90% for more than 5 minutes".to_string(),
                },
            ],
            notification_channels: vec![
                NotificationChannel {
                    name: "slack".to_string(),
                    channel_type: NotificationChannelType::Slack,
                    webhook_url: Some("https://hooks.slack.com/services/...".to_string()),
                    email_addresses: None,
                },
            ],
        }
    }
}

/// Alert manager configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlertManagerConfig {
    /// Enable alert manager
    pub enabled: bool,
    /// Storage size
    pub storage_size: String,
    /// Retention period
    pub retention: Duration,
    /// Resource requirements
    pub resources: ResourceRequirements,
}

impl Default for AlertManagerConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            storage_size: "10Gi".to_string(),
            retention: Duration::from_secs(30 * 24 * 3600), // 30 days
            resources: ResourceRequirements {
                cpu: "500m".to_string(),
                memory: "1Gi".to_string(),
            },
        }
    }
}

/// Alert rule
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlertRule {
    pub name: String,
    pub expression: String,
    pub duration: Duration,
    pub severity: AlertSeverity,
    pub summary: String,
    pub description: String,
}

/// Alert severity levels
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AlertSeverity {
    Info,
    Warning,
    Critical,
}

/// Notification channel
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NotificationChannel {
    pub name: String,
    pub channel_type: NotificationChannelType,
    pub webhook_url: Option<String>,
    pub email_addresses: Option<Vec<String>>,
}

/// Notification channel types
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum NotificationChannelType {
    Slack,
    Email,
    PagerDuty,
    Webhook,
}

/// Dashboard configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DashboardConfig {
    /// Grafana configuration
    pub grafana: GrafanaConfig,
    /// Dashboard definitions
    pub dashboards: Vec<Dashboard>,
}

impl Default for DashboardConfig {
    fn default() -> Self {
        Self {
            grafana: GrafanaConfig::default(),
            dashboards: vec![
                Dashboard {
                    name: "oxirs-overview".to_string(),
                    title: "OxiRS Stream Overview".to_string(),
                    description: "Overview dashboard for OxiRS Stream".to_string(),
                    panels: vec![
                        DashboardPanel {
                            title: "Events per Second".to_string(),
                            panel_type: PanelType::Graph,
                            query: "rate(oxirs_stream_events_total[1m])".to_string(),
                        },
                        DashboardPanel {
                            title: "Processing Latency".to_string(),
                            panel_type: PanelType::Graph,
                            query: "histogram_quantile(0.95, oxirs_stream_latency_seconds)".to_string(),
                        },
                    ],
                },
            ],
        }
    }
}

/// Grafana configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GrafanaConfig {
    /// Enable Grafana
    pub enabled: bool,
    /// Admin user
    pub admin_user: String,
    /// Admin password
    pub admin_password: String,
    /// Persistence configuration
    pub persistence: PersistenceConfig,
    /// Resource requirements
    pub resources: ResourceRequirements,
}

impl Default for GrafanaConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            admin_user: "admin".to_string(),
            admin_password: "admin".to_string(), // Should be changed in production
            persistence: PersistenceConfig {
                enabled: true,
                size: "10Gi".to_string(),
                storage_class: "default".to_string(),
            },
            resources: ResourceRequirements {
                cpu: "500m".to_string(),
                memory: "1Gi".to_string(),
            },
        }
    }
}

/// Persistence configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PersistenceConfig {
    pub enabled: bool,
    pub size: String,
    pub storage_class: String,
}

/// Dashboard
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Dashboard {
    pub name: String,
    pub title: String,
    pub description: String,
    pub panels: Vec<DashboardPanel>,
}

/// Dashboard panel
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DashboardPanel {
    pub title: String,
    pub panel_type: PanelType,
    pub query: String,
}

/// Panel types
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PanelType {
    Graph,
    SingleStat,
    Table,
    Heatmap,
    Logs,
}