Skip to main content

dynamo_runtime/component/
namespace.rs

1// SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::component::Namespace;
5use crate::metrics::{MetricsHierarchy, MetricsRegistry};
6
7impl MetricsHierarchy for Namespace {
8    fn basename(&self) -> String {
9        self.name.clone()
10    }
11
12    fn parent_hierarchies(&self) -> Vec<&dyn MetricsHierarchy> {
13        let mut parents = vec![];
14
15        // Walk up the namespace parent chain (grandparents to immediate parent)
16        let parent_chain: Vec<&Namespace> =
17            std::iter::successors(self.parent.as_deref(), |ns| ns.parent.as_deref()).collect();
18
19        // Add DRT first (root)
20        parents.push(&*self.runtime as &dyn MetricsHierarchy);
21
22        // Then add parent namespaces in reverse order (root -> leaf)
23        for parent_ns in parent_chain.iter().rev() {
24            parents.push(*parent_ns as &dyn MetricsHierarchy);
25        }
26
27        parents
28    }
29
30    fn get_metrics_registry(&self) -> &MetricsRegistry {
31        &self.metrics_registry
32    }
33}