saluki_env/workload/mod.rs
1//! Workload provider.
2//!
3//! This modules provides the `WorkloadProvider` trait, which deals with providing information about workloads running on
4//! the process host.
5//!
6//! A number of building blocks are included -- generic entity identifiers, tag storage, metadata collection and
7//! aggregation -- along with a default workload provider implementation based on the Datadog Agent.
8
9use saluki_context::{
10 origin::{OriginTagCardinality, RawOrigin},
11 tags::SharedTagSet,
12};
13
14mod aggregator;
15mod collectors;
16
17mod entity;
18pub use self::entity::EntityId;
19
20mod helpers;
21mod metadata;
22pub use self::metadata::{MetadataAction, MetadataOperation};
23
24mod on_demand_pid;
25
26pub mod origin;
27use self::origin::ResolvedOrigin;
28
29pub mod providers;
30
31mod stores;
32
33/// Provides information about workloads running on the process host.
34pub trait WorkloadProvider {
35 /// Gets the tags for an entity.
36 ///
37 /// Entities are workload resources running on the process host, such as containers or pods. The cardinality of the
38 /// tags to get can be controlled via `cardinality`.
39 ///
40 /// Returns `Some(SharedTagSet)` if the entity has tags, or `None` if the entity does not have any tags or if the
41 /// entity was not found.
42 fn get_tags_for_entity(&self, entity_id: &EntityId, cardinality: OriginTagCardinality) -> Option<SharedTagSet>;
43
44 /// Resolves a raw origin.
45 ///
46 /// If the origin is empty, `None` is returned. Otherwise, `Some(ResolvedOrigin)` will be returned, which contains
47 /// fully resolved versions of the raw origin components.
48 fn get_resolved_origin(&self, origin: RawOrigin<'_>) -> Option<ResolvedOrigin>;
49}
50
51impl<T> WorkloadProvider for Option<T>
52where
53 T: WorkloadProvider,
54{
55 fn get_tags_for_entity(&self, entity_id: &EntityId, cardinality: OriginTagCardinality) -> Option<SharedTagSet> {
56 match self.as_ref() {
57 Some(provider) => provider.get_tags_for_entity(entity_id, cardinality),
58 None => None,
59 }
60 }
61
62 fn get_resolved_origin(&self, origin: RawOrigin<'_>) -> Option<ResolvedOrigin> {
63 match self.as_ref() {
64 Some(provider) => provider.get_resolved_origin(origin),
65 None => None,
66 }
67 }
68}