Skip to main content

vantage_aws/models/logs/
group.rs

1use serde::{Deserialize, Serialize};
2use vantage_table::table::Table;
3
4use crate::{AwsAccount, eq};
5
6use super::event::{LogEvent, events_table};
7use super::stream::{LogStream, streams_table};
8
9/// One CloudWatch Logs group. Field names match the wire shape —
10/// these are exactly what `DescribeLogGroups` returns.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct LogGroup {
13    #[serde(rename = "logGroupName")]
14    pub log_group_name: String,
15    #[serde(rename = "creationTime", default)]
16    pub creation_time: i64,
17    #[serde(rename = "storedBytes", default)]
18    pub stored_bytes: i64,
19}
20
21/// `DescribeLogGroups` table — every log group in the account. Filter
22/// by adding `eq("logGroupNamePrefix", "...")`.
23///
24/// Two relations:
25///   - `events` → `FilterLogEvents` for this group
26///   - `streams` → `DescribeLogStreams` for this group
27///
28/// AWS doesn't accept multi-value filters, so the source has to narrow
29/// to a single group before traversal — otherwise the call errors at
30/// execute time.
31///
32/// ```no_run
33/// # use vantage_aws::{AwsAccount, eq};
34/// # use vantage_aws::models::logs::groups_table;
35/// # async fn run() -> vantage_core::Result<()> {
36/// # let aws = AwsAccount::from_default()?;
37/// let mut groups = groups_table(aws);
38/// groups.add_condition(eq("logGroupNamePrefix", "/aws/lambda/"));
39/// # Ok(()) }
40/// ```
41pub fn groups_table(aws: AwsAccount) -> Table<AwsAccount, LogGroup> {
42    Table::new("json1/logGroups:logs/Logs_20140328.DescribeLogGroups", aws)
43        .with_id_column("logGroupName")
44        .with_column_of::<i64>("creationTime")
45        .with_column_of::<i64>("storedBytes")
46        .with_many("events", "logGroupName", events_table)
47        .with_many("streams", "logGroupName", streams_table)
48}
49
50impl LogGroup {
51    /// Events table pre-filtered to *this* group's name.
52    pub fn ref_events(&self, aws: AwsAccount) -> Table<AwsAccount, LogEvent> {
53        let mut t = events_table(aws);
54        t.add_condition(eq("logGroupName", self.log_group_name.clone()));
55        t
56    }
57
58    /// Streams table pre-filtered to *this* group's name.
59    pub fn ref_streams(&self, aws: AwsAccount) -> Table<AwsAccount, LogStream> {
60        let mut t = streams_table(aws);
61        t.add_condition(eq("logGroupName", self.log_group_name.clone()));
62        t
63    }
64}