Skip to main content

vantage_aws/models/
log_group.rs

1use serde::{Deserialize, Serialize};
2use vantage_table::table::Table;
3
4use crate::{AwsAccount, eq};
5
6use super::log_event::{LogEvent, log_events_table};
7
8/// One CloudWatch Logs group. Field names match the wire shape —
9/// these are exactly what `DescribeLogGroups` returns.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct LogGroup {
12    #[serde(rename = "logGroupName")]
13    pub log_group_name: String,
14    #[serde(rename = "creationTime", default)]
15    pub creation_time: i64,
16    #[serde(rename = "storedBytes", default)]
17    pub stored_bytes: i64,
18}
19
20/// `DescribeLogGroups` table — every log group in the account. Filter
21/// by adding `eq("logGroupNamePrefix", "...")`.
22///
23/// Comes with an `events` relation that traverses to the group's
24/// log events. AWS doesn't accept multi-value filters, so the source
25/// has to narrow to a single group before traversal — otherwise the
26/// traversal errors at execute time.
27///
28/// ```no_run
29/// # use vantage_aws::{AwsAccount, eq};
30/// # use vantage_aws::models::log_groups_table;
31/// # async fn run() -> vantage_core::Result<()> {
32/// # let aws = AwsAccount::from_default()?;
33/// let mut groups = log_groups_table(aws);
34/// groups.add_condition(eq("logGroupNamePrefix", "/aws/lambda/"));
35/// # Ok(()) }
36/// ```
37pub fn log_groups_table(aws: AwsAccount) -> Table<AwsAccount, LogGroup> {
38    Table::new("logGroups:logs/Logs_20140328.DescribeLogGroups", aws)
39        .with_id_column("logGroupName")
40        .with_column_of::<i64>("creationTime")
41        .with_column_of::<i64>("storedBytes")
42        .with_many("events", "logGroupName", log_events_table)
43}
44
45impl LogGroup {
46    /// Events table pre-filtered to *this* group's name. Use when
47    /// you already have a resolved `LogGroup` in hand and don't need
48    /// to go through the table-level relation traversal.
49    pub fn ref_events(&self, aws: AwsAccount) -> Table<AwsAccount, LogEvent> {
50        let mut t = log_events_table(aws);
51        t.add_condition(eq("logGroupName", self.log_group_name.clone()));
52        t
53    }
54}