Skip to main content

saluki_env/
lib.rs

1//! Helpers for querying environment-specific data.
2//!
3//! In many cases, a Saluki service will need to interact with the environment in which it's running. This may include
4//! interacting with the operating system, introspecting workloads running on the host, and so on.
5//!
6//! This crate provides implementations of various "providers" -- specific facets of the environment that can be queried
7//! -- for a number of different environments, such as bare metal hosts, Kubernetes clusters, and so on.
8#![deny(warnings)]
9#![deny(missing_docs)]
10
11pub mod autodiscovery;
12pub mod features;
13pub mod host;
14pub mod workload;
15
16use std::sync::Arc;
17
18pub use self::autodiscovery::AutodiscoveryProvider;
19pub use self::host::HostProvider;
20pub use self::workload::{CaptureEntityResolver, WorkloadProvider};
21
22/// Provides information about the environment in which the process is running.
23pub trait EnvironmentProvider {
24    /// Type of the host provider.
25    type Host: self::host::HostProvider;
26
27    /// Type of the workload provider.
28    type Workload: self::workload::WorkloadProvider;
29
30    /// Type of the autodiscovery provider.
31    type AutodiscoveryProvider: self::autodiscovery::AutodiscoveryProvider;
32
33    /// Gets a reference to the host provider for this environment.
34    fn host(&self) -> &Self::Host;
35
36    /// Gets a reference to workload provider for this environment.
37    fn workload(&self) -> &Self::Workload;
38
39    /// Gets a reference to autodiscovery provider for this environment.
40    fn autodiscovery(&self) -> &Self::AutodiscoveryProvider;
41}
42
43impl<E> EnvironmentProvider for Arc<E>
44where
45    E: EnvironmentProvider,
46{
47    type Host = E::Host;
48    type Workload = E::Workload;
49    type AutodiscoveryProvider = E::AutodiscoveryProvider;
50
51    fn host(&self) -> &Self::Host {
52        (**self).host()
53    }
54
55    fn workload(&self) -> &Self::Workload {
56        (**self).workload()
57    }
58
59    fn autodiscovery(&self) -> &Self::AutodiscoveryProvider {
60        (**self).autodiscovery()
61    }
62}