sleet 0.1.0

A fleet manager for SlateDB databases
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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
//! The fleet root: the object-store tree holding all fleet state, and
//! the reads every node performs against it.
//!
//! Layout under the root URL:
//!
//! ```text
//! <root>/
//!   sleet.toml               policy
//!   dbs/<db>.toml            registry
//!   nodes/<node>.<svc>.json  heartbeats
//! ```
//!
//! `ConfigPoller` implements the `config_poll` read: re-read
//! `sleet.toml` and LIST `dbs/`, keeping the last good config on failed
//! reads, skipping unchanged bodies by ETag, and never fetching empty
//! registry files. `list_heartbeats` + `node_view` implement the
//! per-tick liveness read.

use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;
use std::time::Duration;

use chrono::Utc;
use futures::TryStreamExt;
use object_store::path::Path as StorePath;
use object_store::{ObjectMeta, ObjectStore, ObjectStoreExt};

use crate::config::{self, DatabaseConfig, Service, SleetConfig};
use crate::{heartbeat, registry};

/// The time source for heartbeat ages. Liveness compares a heartbeat's
/// `LastModified` (object-store clock) against the reader's clock; this
/// seam lets tests and simulations control the reader's side.
pub trait Clock: Send + Sync {
    /// The reader's current time.
    fn now(&self) -> chrono::DateTime<Utc>;
}

/// The wall clock.
#[derive(Clone, Copy, Debug, Default)]
pub struct SystemClock;

impl Clock for SystemClock {
    fn now(&self) -> chrono::DateTime<Utc> {
        Utc::now()
    }
}

/// A fleet root that could not be opened.
#[derive(Debug, thiserror::Error)]
pub enum OpenError {
    /// The root URL was rejected.
    #[error("invalid fleet root: {0}")]
    Url(#[from] registry::UrlError),
    /// The URL parsed but no object store could be built for it.
    #[error("failed to open fleet root store: {0}")]
    Store(#[from] object_store::Error),
}

/// The fleet root: an object store plus the prefix the tree lives under.
#[derive(Clone)]
pub struct FleetRoot {
    store: Arc<dyn ObjectStore>,
    prefix: StorePath,
    url: String,
    clock: Arc<dyn Clock>,
}

impl FleetRoot {
    /// Open a fleet root from its URL. Credentials come from the
    /// environment, per `object_store`.
    pub fn open(url: &str) -> Result<Self, OpenError> {
        let canonical = registry::canonicalize_url(url)?;
        let parsed = url::Url::parse(&canonical).expect("canonical URL reparses");
        let (store, prefix) = crate::store::parse_url(&parsed)?;
        Ok(Self::from_parts(store.into(), prefix, &canonical))
    }

    /// A root over an existing store, for tests and embedding.
    pub fn from_parts(store: Arc<dyn ObjectStore>, prefix: StorePath, url: &str) -> Self {
        Self {
            store,
            prefix,
            url: url.to_string(),
            clock: Arc::new(SystemClock),
        }
    }

    /// Replace the reader's clock (tests and simulations).
    pub fn with_clock(mut self, clock: Arc<dyn Clock>) -> Self {
        self.clock = clock;
        self
    }

    /// The object store the fleet tree lives in.
    pub fn store(&self) -> &Arc<dyn ObjectStore> {
        &self.store
    }

    /// The canonical fleet root URL.
    pub fn url(&self) -> &str {
        &self.url
    }

    /// `<root>/sleet.toml`.
    pub fn config_path(&self) -> StorePath {
        self.prefix.clone().join("sleet.toml")
    }

    /// `<root>/dbs/`.
    pub fn dbs_prefix(&self) -> StorePath {
        self.prefix.clone().join("dbs")
    }

    /// `<root>/nodes/`.
    pub fn nodes_prefix(&self) -> StorePath {
        self.prefix.clone().join("nodes")
    }

    /// The registry file for a canonical database URL. Built by parsing
    /// rather than joining: `join` would percent-encode the name's `%`
    /// signs a second time.
    pub fn database_path(&self, canonical_url: &str) -> StorePath {
        let name = registry::file_name(canonical_url);
        StorePath::parse(format!("{}/{}", self.dbs_prefix(), name))
            .expect("registry file names are valid paths")
    }

    /// A heartbeat object under `nodes/`.
    pub fn node_path(&self, object_name: &str) -> StorePath {
        self.nodes_prefix().join(object_name)
    }

    /// Every heartbeat object under `nodes/`, with parsed names and
    /// ages. Objects that aren't heartbeats are ignored.
    pub async fn list_heartbeats(&self) -> Result<Vec<HeartbeatEntry>, object_store::Error> {
        let now = self.clock.now();
        let metas = self.list(&self.nodes_prefix()).await?;
        let mut entries = Vec::new();
        for meta in metas {
            let Some(name) = meta.location.filename() else {
                continue;
            };
            let Some((node_id, services)) = heartbeat::parse_object_name(name) else {
                continue;
            };
            let age = (now - meta.last_modified).to_std().unwrap_or_default();
            entries.push(HeartbeatEntry {
                node_id,
                services,
                age,
                location: meta.location,
            });
        }
        Ok(entries)
    }

    /// LIST a prefix, treating a missing prefix as empty.
    async fn list(&self, prefix: &StorePath) -> Result<Vec<ObjectMeta>, object_store::Error> {
        match self.store.list(Some(prefix)).try_collect().await {
            Ok(metas) => Ok(metas),
            Err(object_store::Error::NotFound { .. }) => Ok(Vec::new()),
            Err(e) => Err(e),
        }
    }
}

/// One heartbeat object under `nodes/`.
#[derive(Clone, Debug)]
pub struct HeartbeatEntry {
    /// The node id, from the object name.
    pub node_id: String,
    /// The services the node offers, from the object name.
    pub services: Vec<Service>,
    /// The heartbeat's age: the reader's clock minus `LastModified`.
    pub age: Duration,
    /// The heartbeat object's path.
    pub location: StorePath,
}

/// One live node, deduplicated to the youngest heartbeat per node id.
#[derive(Clone, Debug, PartialEq)]
pub struct NodeView {
    /// The node id.
    pub node_id: String,
    /// The services the node offers.
    pub services: Vec<Service>,
    /// The age of the node's youngest heartbeat.
    pub age: Duration,
}

/// The youngest heartbeat per node id: when a node briefly has two
/// names (a role change), the youngest wins.
pub fn youngest_per_node(entries: &[HeartbeatEntry]) -> BTreeMap<&str, &HeartbeatEntry> {
    let mut by_id: BTreeMap<&str, &HeartbeatEntry> = BTreeMap::new();
    for entry in entries {
        match by_id.get(entry.node_id.as_str()) {
            Some(existing) if existing.age <= entry.age => {}
            _ => {
                by_id.insert(&entry.node_id, entry);
            }
        }
    }
    by_id
}

/// The live node set: heartbeats younger than `heartbeat_timeout`, the
/// youngest name winning when a node briefly has two (a role change).
pub fn node_view(entries: &[HeartbeatEntry], heartbeat_timeout: Duration) -> Vec<NodeView> {
    youngest_per_node(entries)
        .into_values()
        .filter(|e| e.age < heartbeat_timeout)
        .map(|e| NodeView {
            node_id: e.node_id.clone(),
            services: e.services.clone(),
            age: e.age,
        })
        .collect()
}

/// Everything a node knows about the fleet's intent after one
/// `config_poll`: the policy and the registry.
#[derive(Clone, Debug, Default)]
pub struct FleetState {
    /// The fleet policy from `sleet.toml`.
    pub config: SleetConfig,
    /// Registered databases by canonical URL.
    pub databases: BTreeMap<String, DatabaseConfig>,
    /// Registry entries that alias another, aren't canonical, or fail
    /// to parse.
    pub warnings: Vec<String>,
}

/// The `config_poll` loop's read state: last-good config plus per-file
/// ETag caches so unchanged bodies are never re-fetched.
#[derive(Default)]
pub struct ConfigPoller {
    config_etag: Option<String>,
    config: SleetConfig,
    files: HashMap<String, CachedFile>,
    /// The last successful registry view, kept whole when a LIST fails.
    /// The `files` cache cannot rebuild it: empty registry files (the
    /// common case) are never fetched, so they are never cached there.
    databases: BTreeMap<String, DatabaseConfig>,
}

struct CachedFile {
    etag: Option<String>,
    config: Option<DatabaseConfig>,
}

impl ConfigPoller {
    /// Re-read `sleet.toml` and the `dbs/` registry. Never fails: on a
    /// failed read the last good config is kept and a warning recorded.
    pub async fn poll(&mut self, root: &FleetRoot) -> FleetState {
        let mut warnings = Vec::new();
        self.poll_config(root, &mut warnings).await;
        let databases = self.poll_registry(root, &mut warnings).await;
        FleetState {
            config: self.config.clone(),
            databases,
            warnings,
        }
    }

    async fn poll_config(&mut self, root: &FleetRoot, warnings: &mut Vec<String>) {
        let path = root.config_path();
        let result = root.store().get(&path).await;
        let get = match result {
            Ok(get) => get,
            Err(object_store::Error::NotFound { .. }) => {
                // No sleet.toml: built-in defaults.
                self.config_etag = None;
                self.config = SleetConfig::default();
                return;
            }
            Err(e) => {
                warnings.push(format!(
                    "failed to read {path}: {e}; keeping last good config"
                ));
                return;
            }
        };
        let etag = get.meta.e_tag.clone();
        if etag.is_some() && etag == self.config_etag {
            return;
        }
        let body = match get.bytes().await {
            Ok(body) => body,
            Err(e) => {
                warnings.push(format!(
                    "failed to read {path}: {e}; keeping last good config"
                ));
                return;
            }
        };
        match std::str::from_utf8(&body)
            .map_err(|e| e.to_string())
            .and_then(|s| config::parse_config(s).map_err(|e| e.to_string()))
        {
            Ok(config) => {
                self.config = config;
                self.config_etag = etag;
            }
            Err(e) => {
                warnings.push(format!("invalid {path}: {e}; keeping last good config"));
            }
        }
    }

    async fn poll_registry(
        &mut self,
        root: &FleetRoot,
        warnings: &mut Vec<String>,
    ) -> BTreeMap<String, DatabaseConfig> {
        let metas = match root.list(&root.dbs_prefix()).await {
            Ok(metas) => metas,
            Err(e) => {
                warnings.push(format!("failed to list registry: {e}; keeping last good"));
                return self.databases.clone();
            }
        };

        // Decode and canonicalize every entry, then order canonical
        // spellings first so an alias never shadows the real entry.
        let mut entries = Vec::new();
        for meta in &metas {
            let Some(name) = meta.location.filename() else {
                continue;
            };
            let Some(decoded) = registry::parse_file_name(name) else {
                warnings.push(format!("ignoring non-registry object {}", meta.location));
                continue;
            };
            match registry::canonicalize_database_url(&decoded) {
                Ok(canonical) => {
                    if canonical != decoded {
                        warnings.push(format!(
                            "registry entry {name} is not canonical (decodes to \
                             {decoded:?}, canonical {canonical:?})"
                        ));
                    }
                    entries.push((canonical != decoded, name.to_string(), canonical, meta));
                }
                Err(e) => {
                    warnings.push(format!("ignoring registry entry {name}: {e}"));
                }
            }
        }
        entries.sort_by(|a, b| (a.0, &a.1).cmp(&(b.0, &b.1)));

        let mut databases = BTreeMap::new();
        let mut seen: HashMap<String, String> = HashMap::new();
        for (_, name, url, meta) in entries {
            if let Some(winner) = seen.get(&url) {
                warnings.push(format!(
                    "registry entries {winner} and {name} alias {url}; using {winner}"
                ));
                continue;
            }
            let db = self.file_config(root, meta, &name, warnings).await;
            seen.insert(url.clone(), name);
            databases.insert(url, db);
        }
        self.files
            .retain(|name, _| seen.values().any(|n| n == name));
        self.databases = databases.clone();
        databases
    }

    /// The effective `DatabaseConfig` for one registry file: empty files
    /// never need a GET, unchanged ETags reuse the cache, unparseable
    /// bodies keep their last good version or disable the database.
    async fn file_config(
        &mut self,
        root: &FleetRoot,
        meta: &ObjectMeta,
        name: &str,
        warnings: &mut Vec<String>,
    ) -> DatabaseConfig {
        if meta.size == 0 {
            return DatabaseConfig::default();
        }
        if let Some(cached) = self.files.get(name)
            && cached.etag.is_some()
            && cached.etag == meta.e_tag
            && let Some(config) = &cached.config
        {
            return config.clone();
        }
        let body = match root.store().get(&meta.location).await {
            Ok(get) => get.bytes().await,
            Err(e) => Err(e),
        };
        let parsed = body
            .map_err(|e| e.to_string())
            .and_then(|b| String::from_utf8(b.to_vec()).map_err(|e| e.to_string()))
            .and_then(|s| config::parse_database(&self.config, &s).map_err(|e| e.to_string()));
        match parsed {
            Ok(db) => {
                self.files.insert(
                    name.to_string(),
                    CachedFile {
                        etag: meta.e_tag.clone(),
                        config: Some(db.clone()),
                    },
                );
                db
            }
            Err(e) => {
                if let Some(cached) = self.files.get(name)
                    && let Some(config) = &cached.config
                {
                    warnings.push(format!(
                        "invalid registry entry {name}: {e}; keeping last good"
                    ));
                    return config.clone();
                }
                warnings.push(format!(
                    "invalid registry entry {name}: {e}; database disabled"
                ));
                DatabaseConfig {
                    services: Some(Vec::new()),
                    ..DatabaseConfig::default()
                }
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use object_store::PutPayload;
    use object_store::memory::InMemory;

    fn root() -> FleetRoot {
        FleetRoot::from_parts(
            Arc::new(InMemory::new()),
            StorePath::from("fleet"),
            "memory:///fleet",
        )
    }

    async fn put(root: &FleetRoot, path: &StorePath, body: &str) {
        root.store()
            .put(path, PutPayload::from(body.to_string()))
            .await
            .unwrap();
    }

    #[tokio::test]
    async fn empty_root_yields_defaults() {
        let root = root();
        let mut poller = ConfigPoller::default();
        let state = poller.poll(&root).await;
        assert!(state.databases.is_empty());
        assert!(state.warnings.is_empty());
        assert_eq!(
            state.config.node.heartbeat_interval.0,
            Duration::from_secs(10)
        );
    }

    #[tokio::test]
    async fn registry_files_resolve_and_alias_warnings_fire() {
        let root = root();
        put(
            &root,
            &root.config_path(),
            "[database]\nservices = [\"gc\"]",
        )
        .await;
        // Empty file: registered with fleet-wide config, no GET needed.
        put(&root, &root.database_path("s3://b/empty"), "").await;
        // Override file.
        put(
            &root,
            &root.database_path("s3://b/tuned"),
            "services = [\"gc\", \"compaction-workers\"]",
        )
        .await;
        // Invalid file: registered but disabled.
        put(&root, &root.database_path("s3://b/broken"), "nope = 1").await;
        // Alias of s3://b/empty under a non-canonical spelling.
        let alias = StorePath::parse(format!(
            "{}/{}",
            root.dbs_prefix(),
            registry::file_name("s3://b/empty/")
        ))
        .unwrap();
        put(&root, &alias, "").await;

        let mut poller = ConfigPoller::default();
        let state = poller.poll(&root).await;

        assert_eq!(state.databases.len(), 3);
        let resolved = state
            .config
            .resolve(state.databases.get("s3://b/empty").map(|v| v as _));
        assert_eq!(resolved.services, vec![Service::Gc]);
        let tuned = state.config.resolve(state.databases.get("s3://b/tuned"));
        assert_eq!(
            tuned.services,
            vec![Service::Gc, Service::CompactionWorkers]
        );
        let broken = state.config.resolve(state.databases.get("s3://b/broken"));
        assert!(broken.services.is_empty());
        assert_eq!(state.warnings.len(), 3, "{:?}", state.warnings);
        assert!(state.warnings.iter().any(|w| w.contains("not canonical")));
        assert!(state.warnings.iter().any(|w| w.contains("disabled")));
        // The canonical spelling wins the alias collision.
        let alias_warning = state
            .warnings
            .iter()
            .find(|w| w.contains("alias"))
            .expect("alias warning");
        assert!(
            alias_warning.contains("using s3%3A%2F%2Fb%2Fempty.toml"),
            "{alias_warning}"
        );
    }

    /// The design's read-cost promise: empty registry files are never
    /// fetched, and override files are fetched only when their ETag
    /// changes.
    #[tokio::test]
    async fn poller_never_refetches_unchanged_bodies() {
        use crate::testing::{Op, TestStore};
        let store = TestStore::in_memory();
        let root = FleetRoot::from_parts(store.clone(), StorePath::from("fleet"), "memory:///f");
        put(
            &root,
            &root.config_path(),
            "[database]\nservices = [\"gc\"]",
        )
        .await;
        put(&root, &root.database_path("s3://b/empty"), "").await;
        put(&root, &root.database_path("s3://b/tuned"), "services = []").await;

        let mut poller = ConfigPoller::default();
        poller.poll(&root).await;
        let first_pass_gets = store.counters().count(Op::Get);
        // Config + the one non-empty override; the empty file costs no GET.
        assert_eq!(first_pass_gets, 2);

        poller.poll(&root).await;
        // Second pass re-reads only sleet.toml (to see its ETag); the
        // unchanged override body is served from the cache.
        assert_eq!(store.counters().count(Op::Get), first_pass_gets + 1);

        // A changed override is re-fetched once.
        put(
            &root,
            &root.database_path("s3://b/tuned"),
            "services = [\"gc\"]",
        )
        .await;
        let state = poller.poll(&root).await;
        assert_eq!(store.counters().count(Op::Get), first_pass_gets + 3);
        assert_eq!(
            state
                .config
                .resolve(state.databases.get("s3://b/tuned"))
                .services,
            vec![Service::Gc]
        );
    }

    /// An override that turns invalid keeps its last good version; a
    /// failed registry LIST keeps the whole last-good view, including
    /// empty-file databases (never body-fetched, so never in the file
    /// cache) and non-canonical entries under their canonical keys.
    #[tokio::test]
    async fn poller_keeps_last_good_per_file_and_on_list_failure() {
        use crate::testing::{Op, TestStore};
        let store = TestStore::in_memory();
        let root = FleetRoot::from_parts(store.clone(), StorePath::from("fleet"), "memory:///f");
        put(
            &root,
            &root.database_path("s3://b/db"),
            "services = [\"gc\"]",
        )
        .await;
        // Registered with an empty file: the common case.
        put(&root, &root.database_path("s3://b/empty"), "").await;
        // Registered under a non-canonical spelling.
        let noncanonical = StorePath::parse(format!(
            "{}/{}",
            root.dbs_prefix(),
            registry::file_name("s3://b/extra/")
        ))
        .unwrap();
        put(&root, &noncanonical, "").await;

        let mut poller = ConfigPoller::default();
        let state = poller.poll(&root).await;
        assert_eq!(state.databases.len(), 3);
        assert_eq!(
            state
                .config
                .resolve(state.databases.get("s3://b/db"))
                .services,
            vec![Service::Gc]
        );

        // Now corrupt the override: the last good version stays.
        put(&root, &root.database_path("s3://b/db"), "nope = 1").await;
        let state = poller.poll(&root).await;
        assert_eq!(
            state
                .config
                .resolve(state.databases.get("s3://b/db"))
                .services,
            vec![Service::Gc]
        );
        assert!(
            state
                .warnings
                .iter()
                .any(|w| w.contains("keeping last good"))
        );

        // And a failed LIST keeps the whole registry view: the override,
        // the empty-file database, and the non-canonical entry under its
        // canonical key.
        store.fail_next(Op::List, 1);
        let state = poller.poll(&root).await;
        assert_eq!(state.databases.len(), 3, "{:?}", state.databases.keys());
        for db in ["s3://b/db", "s3://b/empty", "s3://b/extra"] {
            assert!(state.databases.contains_key(db), "{db} missing");
        }
        assert_eq!(
            state
                .config
                .resolve(state.databases.get("s3://b/db"))
                .services,
            vec![Service::Gc]
        );
        assert!(state.warnings.iter().any(|w| w.contains("failed to list")));
    }

    #[tokio::test]
    async fn bad_fleet_config_keeps_last_good() {
        let root = root();
        put(
            &root,
            &root.config_path(),
            "[database]\nservices = [\"gc\"]",
        )
        .await;
        let mut poller = ConfigPoller::default();
        let state = poller.poll(&root).await;
        assert_eq!(state.config.resolve(None).services, vec![Service::Gc]);

        put(&root, &root.config_path(), "not toml [").await;
        let state = poller.poll(&root).await;
        assert_eq!(state.config.resolve(None).services, vec![Service::Gc]);
        assert!(state.warnings.iter().any(|w| w.contains("last good")));
    }

    #[tokio::test]
    async fn node_view_dedups_youngest_and_drops_dead() {
        let entries = vec![
            HeartbeatEntry {
                node_id: "a".into(),
                services: vec![Service::Gc],
                age: Duration::from_secs(5),
                location: StorePath::from("nodes/a.g.json"),
            },
            HeartbeatEntry {
                node_id: "a".into(),
                services: Service::ALL.to_vec(),
                age: Duration::from_secs(2),
                location: StorePath::from("nodes/a.cgw.json"),
            },
            HeartbeatEntry {
                node_id: "dead".into(),
                services: Service::ALL.to_vec(),
                age: Duration::from_secs(120),
                location: StorePath::from("nodes/dead.cgw.json"),
            },
        ];
        let view = node_view(&entries, Duration::from_secs(30));
        assert_eq!(view.len(), 1);
        assert_eq!(view[0].node_id, "a");
        assert_eq!(view[0].services, Service::ALL.to_vec());
    }
}