Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Inject vector aggregator address into config as env #1000

Merged
merged 10 commits into from
Apr 7, 2025
4 changes: 2 additions & 2 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- BREAKING: Inject vector aggregator address into vector config file using an environment variable ([#1000]).

[#1000]: https://github.com/stackabletech/operator-rs/pull/1000

## [0.89.1] - 2025-04-02

### Changed
Expand Down
17 changes: 13 additions & 4 deletions crates/stackable-operator/src/product_logging/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const SHUTDOWN_FILE: &str = "shutdown";

/// File name of the Vector config file
pub const VECTOR_CONFIG_FILE: &str = "vector.yaml";
/// Key in the discovery ConfigMap that holds the vector aggregator address
const VECTOR_AGGREGATOR_CM_KEY: &str = "ADDRESS";
/// Name of the env var in the vector container that holds the vector aggregator address
const VECTOR_AGGREGATOR_ENV_NAME: &str = "VECTOR_AGGREGATOR_ADDRESS";

#[derive(Debug, Snafu)]
pub enum LoggingError {
Expand Down Expand Up @@ -678,7 +682,6 @@ pub fn create_logback_config(
/// # }
/// #
/// # let logging = fragment::validate::<Logging<Container>>(default_logging()).unwrap();
/// # let vector_aggregator_address = "vector-aggregator:6000";
/// # let role_group = RoleGroupRef {
/// # cluster: ObjectRef::<Pod>::new("test-cluster"),
/// # role: "role".into(),
Expand All @@ -702,7 +705,6 @@ pub fn create_logback_config(
/// product_logging::framework::VECTOR_CONFIG_FILE,
/// product_logging::framework::create_vector_config(
/// &role_group,
/// vector_aggregator_address,
/// vector_log_config,
/// ),
/// );
Expand All @@ -712,7 +714,6 @@ pub fn create_logback_config(
/// ```
pub fn create_vector_config<T>(
role_group: &RoleGroupRef<T>,
vector_aggregator_address: &str,
config: Option<&AutomaticContainerLogConfig>,
) -> String
where
Expand Down Expand Up @@ -1330,7 +1331,7 @@ sinks:
inputs:
- extended_logs
type: vector
address: {vector_aggregator_address}
address: ${VECTOR_AGGREGATOR_ENV_NAME}
"#,
namespace = role_group.cluster.namespace.clone().unwrap_or_default(),
cluster_name = role_group.cluster.name,
Expand Down Expand Up @@ -1386,6 +1387,7 @@ sinks:
/// # image_pull_policy: "Always".into(),
/// # pull_secrets: None,
/// # };
/// # let vector_aggregator_config_map_name = "vector-aggregator-discovery";
///
/// let mut pod_builder = PodBuilder::new();
/// pod_builder.metadata(ObjectMetaBuilder::default().build());
Expand Down Expand Up @@ -1425,6 +1427,7 @@ sinks:
/// "log",
/// logging.containers.get(&Container::Vector),
/// resources,
/// vector_aggregator_config_map_name,
/// ).unwrap());
/// }
///
Expand All @@ -1436,6 +1439,7 @@ pub fn vector_container(
log_volume_name: &str,
log_config: Option<&ContainerLogConfig>,
resources: ResourceRequirements,
vector_aggregator_config_map_name: &str,
) -> Result<Container, LoggingError> {
let log_level = if let Some(ContainerLogConfig {
choice: Some(ContainerLogConfigChoice::Automatic(automatic_log_config)),
Expand Down Expand Up @@ -1473,6 +1477,11 @@ kill $vector_pid
"
)])
.add_env_var("VECTOR_LOG", log_level.to_vector_literal())
.add_env_var_from_config_map(
VECTOR_AGGREGATOR_ENV_NAME,
vector_aggregator_config_map_name,
VECTOR_AGGREGATOR_CM_KEY,
)
.add_volume_mount(config_volume_name, STACKABLE_CONFIG_DIR)
.context(AddVolumeMountsSnafu)?
.add_volume_mount(log_volume_name, STACKABLE_LOG_DIR)
Expand Down
Loading