Skip to content

Commit

Permalink
feat(aws_cloudwatch_logs sink): allow setting type of log class to cr…
Browse files Browse the repository at this point in the history
…eate

Problem: Prior to this commit it was not possible to specify the log
group's class type. The method prior always created a Standard type.

------------------------------------------------------------

Solution: Allow specifying the log group class type via a new field,
`group_class`.

Initial Issue Report: #22008

Closes #22008
  • Loading branch information
PriceHiller committed Dec 21, 2024
1 parent 029a2ff commit a8f71da
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 37 deletions.
81 changes: 47 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ aws-sdk-s3 = { version = "1.4.0", default-features = false, features = ["behavio
aws-sdk-sqs = { version = "1.3.0", default-features = false, features = ["behavior-version-latest", "rt-tokio"], optional = true }
aws-sdk-sns = { version = "1.3.0", default-features = false, features = ["behavior-version-latest", "rt-tokio"], optional = true }
aws-sdk-cloudwatch = { version = "1.3.0", default-features = false, features = ["behavior-version-latest", "rt-tokio"], optional = true }
aws-sdk-cloudwatchlogs = { version = "1.3.0", default-features = false, features = ["behavior-version-latest", "rt-tokio"], optional = true }
aws-sdk-cloudwatchlogs = { version = "1.62.0", default-features = false, features = ["behavior-version-latest", "rt-tokio"], optional = true }
aws-sdk-elasticsearch = { version = "1.3.0", default-features = false, features = ["behavior-version-latest", "rt-tokio"], optional = true }
aws-sdk-firehose = { version = "1.3.0", default-features = false, features = ["behavior-version-latest", "rt-tokio"], optional = true }
aws-sdk-kinesis = { version = "1.3.0", default-features = false, features = ["behavior-version-latest", "rt-tokio"], optional = true }
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/22008-specify-cloudwatch-log-class.enhancement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The Cloudwatch Logs Sink now supports specifying the type of log class to create.

authors: PriceHiller
34 changes: 34 additions & 0 deletions src/sinks/aws_cloudwatch_logs/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ where
}
}

/// Defines the log class to create
///
/// See https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatch_Logs_Log_Classes.html
#[configurable_component]
#[derive(Clone, Debug, Default)]
pub enum LogGroupClassDef {
/// Logs that require real-time monitoring or frequently accessed logs
#[default]
Standard,
/// Log class that can be used to cost-effectively consolidate logs
InfrequentAccess,
}

impl From<LogGroupClassDef> for aws_sdk_cloudwatchlogs::types::LogGroupClass {
fn from(value: LogGroupClassDef) -> Self {
match value {
LogGroupClassDef::Standard => aws_sdk_cloudwatchlogs::types::LogGroupClass::Standard,
LogGroupClassDef::InfrequentAccess => {
aws_sdk_cloudwatchlogs::types::LogGroupClass::InfrequentAccess
}
}
}
}

/// Configuration for the `aws_cloudwatch_logs` sink.
#[configurable_component(sink(
"aws_cloudwatch_logs",
Expand Down Expand Up @@ -110,6 +134,7 @@ pub struct CloudwatchLogsSinkConfig {
pub region: RegionOrEndpoint,

/// Dynamically create a [log group][log_group] if it does not already exist.
/// This will create the log group with the group class specified by the `group_class` option.
///
/// This ignores `create_missing_stream` directly after creating the group and creates
/// the first stream.
Expand All @@ -118,6 +143,14 @@ pub struct CloudwatchLogsSinkConfig {
#[serde(default = "crate::serde::default_true")]
pub create_missing_group: bool,

/// Specifies the specific [group class][group_class] to create when
/// `create_missing_group` is enabled.
///
/// [group_class]: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatch_Logs_Log_Classes.html
#[configurable(derived)]
#[serde(default)]
pub group_class: LogGroupClassDef,

/// Dynamically create a [log stream][log_stream] if it does not already exist.
///
/// [log_stream]: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html
Expand Down Expand Up @@ -236,6 +269,7 @@ fn default_config(encoding: EncodingConfig) -> CloudwatchLogsSinkConfig {
CloudwatchLogsSinkConfig {
encoding,
group_name: Default::default(),
group_class: Default::default(),
stream_name: Default::default(),
region: Default::default(),
create_missing_group: true,
Expand Down
Loading

0 comments on commit a8f71da

Please sign in to comment.