saluki_env/workload/
mod.rs

1//! Workload provider.
2//!
3//! This modules provides the `WorkloadProvider` trait, which deals with providing information about workloads running
4//! on the process host.
5//!
6//! A number of building blocks are included: generic entity identifiers, tag storage, metadata collection and
7//! aggregation.
8
9use saluki_context::{
10    origin::{OriginTagCardinality, RawOrigin},
11    tags::SharedTagSet,
12};
13
14pub mod aggregator;
15pub mod collectors;
16
17pub mod entity;
18pub use self::entity::EntityId;
19
20mod helpers;
21mod metadata;
22pub use self::metadata::{MetadataAction, MetadataOperation};
23
24mod on_demand_pid;
25pub use self::on_demand_pid::OnDemandPIDResolver;
26
27pub mod origin;
28use self::origin::ResolvedOrigin;
29
30pub mod providers;
31
32pub mod stores;
33
34/// Resolves live process IDs observed during traffic capture to workload entities.
35///
36/// This is intentionally narrower than [`WorkloadProvider`]: callers should only use it for PIDs observed from the
37/// local operating system while capturing traffic. It's not a general-purpose historical PID lookup API.
38pub trait CaptureEntityResolver {
39    /// Resolves a live process ID to the container entity that owns it, if known.
40    fn resolve_container_entity_for_live_pid(&self, process_id: u32) -> Option<EntityId>;
41}
42
43impl<T> CaptureEntityResolver for Option<T>
44where
45    T: CaptureEntityResolver,
46{
47    fn resolve_container_entity_for_live_pid(&self, process_id: u32) -> Option<EntityId> {
48        match self.as_ref() {
49            Some(resolver) => resolver.resolve_container_entity_for_live_pid(process_id),
50            None => None,
51        }
52    }
53}
54
55/// Provides information about workloads running on the process host.
56pub trait WorkloadProvider {
57    /// Gets the tags for an entity.
58    ///
59    /// Entities are workload resources running on the process host, such as containers or pods. The cardinality of the
60    /// tags to get can be controlled via `cardinality`.
61    ///
62    /// Returns `Some(SharedTagSet)` if the entity has tags, or `None` if the entity doesn't have any tags or if the
63    /// entity wasn't found.
64    fn get_tags_for_entity(&self, entity_id: &EntityId, cardinality: OriginTagCardinality) -> Option<SharedTagSet>;
65
66    /// Gets low-cardinality tags for the container that runs this process.
67    ///
68    /// Providers that cannot determine the process container return `None`.
69    fn get_self_container_tags(&self) -> Option<SharedTagSet> {
70        None
71    }
72
73    /// Resolves a raw origin.
74    ///
75    ///  If the origin is empty, `None` is returned. Otherwise, `Some(ResolvedOrigin)` will be returned, which contains
76    ///  fully resolved versions of the raw origin components.
77    fn get_resolved_origin(&self, origin: RawOrigin<'_>) -> Option<ResolvedOrigin>;
78}
79
80impl<T> WorkloadProvider for Option<T>
81where
82    T: WorkloadProvider,
83{
84    fn get_tags_for_entity(&self, entity_id: &EntityId, cardinality: OriginTagCardinality) -> Option<SharedTagSet> {
85        match self.as_ref() {
86            Some(provider) => provider.get_tags_for_entity(entity_id, cardinality),
87            None => None,
88        }
89    }
90
91    fn get_self_container_tags(&self) -> Option<SharedTagSet> {
92        match self.as_ref() {
93            Some(provider) => provider.get_self_container_tags(),
94            None => None,
95        }
96    }
97
98    fn get_resolved_origin(&self, origin: RawOrigin<'_>) -> Option<ResolvedOrigin> {
99        match self.as_ref() {
100            Some(provider) => provider.get_resolved_origin(origin),
101            None => None,
102        }
103    }
104}