Skip to content

Commit 5960009

Browse files
authored
feat: Make containerdebug configurable (#794)
* feat: Make containerdebug configurable Adds the containerdebug config (enabled, interval) from stackable-operator 0.122.0 to the metastore config and starts containerdebug from the validated, merged role group config. * Add changelog * Adding docs * Adding test for defaults * Update changelog * Rather show enabled: false
1 parent 4120103 commit 5960009

9 files changed

Lines changed: 263 additions & 17 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Add the `config.containerdebug` field to roles and role groups ([#794]).
10+
11+
[#794]: https://github.com/stackabletech/hive-operator/pull/794
12+
713
## [26.11.0] - 2026-11-20
814

915
## [26.11.0-rc1] - 2026-11-19

‎docs/modules/hive/pages/usage-guide/logging.adoc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ spec:
1010
vectorAggregatorConfigMapName: vector-aggregator-discovery
1111
metastore:
1212
config:
13+
containerdebug:
14+
enabled: false
1315
logging:
1416
enableVectorAgent: true
1517
----
@@ -22,4 +24,6 @@ Overriding `FILE_LOG_DIRECTORY` with `envOverrides` therefore changes how these
2224
The agent only collects files one level below `/stackable/log`, so a sibling directory such as `/stackable/log/hive` relabels the events instead of dropping them, while any deeper or shallower path stops the aggregation.
2325
A path outside `/stackable/log` also leaves the size-capped log volume.
2426

27+
The `containerdebug` process can be configured or turned off per role and role group, as described in xref:concepts:observability/containerdebug.adoc#configuration[].
28+
2529
Further information on how to configure logging, can be found in xref:concepts:logging.adoc[].

‎extra/crds.yaml‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,26 @@ spec:
541541
type: object
542542
x-kubernetes-preserve-unknown-fields: true
543543
type: object
544+
containerdebug:
545+
default:
546+
enabled: null
547+
interval: null
548+
description: |-
549+
Configures the `containerdebug` tool, which periodically logs information about the container
550+
environment (such as network interfaces, DNS lookups and disk usage) in the background of the
551+
product container.
552+
properties:
553+
enabled:
554+
description: Whether `containerdebug` runs in the background of the product container. Defaults to `true`.
555+
nullable: true
556+
type: boolean
557+
interval:
558+
description: |-
559+
Time between two runs of `containerdebug`, e.g. `30m`, `1h` or `2d`. Must not be zero.
560+
Defaults to `30m`.
561+
nullable: true
562+
type: string
563+
type: object
544564
gracefulShutdownTimeout:
545565
description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details.
546566
nullable: true
@@ -994,6 +1014,26 @@ spec:
9941014
type: object
9951015
x-kubernetes-preserve-unknown-fields: true
9961016
type: object
1017+
containerdebug:
1018+
default:
1019+
enabled: null
1020+
interval: null
1021+
description: |-
1022+
Configures the `containerdebug` tool, which periodically logs information about the container
1023+
environment (such as network interfaces, DNS lookups and disk usage) in the background of the
1024+
product container.
1025+
properties:
1026+
enabled:
1027+
description: Whether `containerdebug` runs in the background of the product container. Defaults to `true`.
1028+
nullable: true
1029+
type: boolean
1030+
interval:
1031+
description: |-
1032+
Time between two runs of `containerdebug`, e.g. `30m`, `1h` or `2d`. Must not be zero.
1033+
Defaults to `30m`.
1034+
nullable: true
1035+
type: string
1036+
type: object
9971037
gracefulShutdownTimeout:
9981038
description: Time period Pods have to gracefully shut down, e.g. `30m`, `1h` or `2d`. Consult the operator documentation for details.
9991039
nullable: true

‎rust/operator-binary/src/controller.rs‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use stackable_operator::{
2020
resources::{NoRuntimeLimits, Resources},
2121
},
2222
constant,
23-
crd::{listener::v1alpha1::Listener, s3},
23+
crd::{containerdebug::ValidatedContainerdebugConfig, listener::v1alpha1::Listener, s3},
2424
database_connections::drivers::jdbc::JdbcDatabaseConnectionDetails,
2525
k8s_openapi::api::{
2626
apps::v1::StatefulSet,
@@ -115,6 +115,7 @@ pub type HiveRoleGroupConfig = stackable_operator::v2::role_utils::RoleGroupConf
115115
#[derive(Clone, Debug, PartialEq)]
116116
pub struct ValidatedMetaStoreConfig {
117117
pub affinity: StackableAffinity,
118+
pub containerdebug: ValidatedContainerdebugConfig,
118119
pub graceful_shutdown_timeout: Option<Duration>,
119120
pub logging: validate::ValidatedLogging,
120121
pub resources: Resources<crate::crd::MetastoreStorageConfig, NoRuntimeLimits>,
@@ -123,28 +124,40 @@ pub struct ValidatedMetaStoreConfig {
123124

124125
impl ValidatedMetaStoreConfig {
125126
/// Builds the validated config from the merged [`MetaStoreConfig`], swapping in the
126-
/// already-validated logging.
127-
fn from_merged(merged: MetaStoreConfig, logging: validate::ValidatedLogging) -> Self {
127+
/// already-validated `containerdebug` and logging configuration.
128+
fn from_merged(
129+
merged: MetaStoreConfig,
130+
containerdebug: ValidatedContainerdebugConfig,
131+
logging: validate::ValidatedLogging,
132+
) -> Self {
128133
Self {
129134
warehouse_dir: merged.warehouse_dir,
130135
resources: merged.resources,
131136
logging,
132137
affinity: merged.affinity,
138+
containerdebug,
133139
graceful_shutdown_timeout: merged.graceful_shutdown_timeout,
134140
}
135141
}
136142

137-
/// Wraps a merged [`MetaStoreConfig`] with trivial automatic logging, for builder tests
138-
/// that only exercise the non-logging parts of the config.
143+
/// Wraps a merged [`MetaStoreConfig`] with trivial automatic logging and its own validated
144+
/// `containerdebug` config, for builder tests that only exercise the non-logging parts of
145+
/// the config.
139146
#[cfg(test)]
140147
pub(crate) fn from_merged_for_test(merged: MetaStoreConfig) -> Self {
141148
use stackable_operator::{
142149
product_logging::spec::AutomaticContainerLogConfig,
143150
v2::product_logging::framework::ValidatedContainerLogConfigChoice,
144151
};
145152

153+
let containerdebug = merged
154+
.containerdebug
155+
.validate()
156+
.expect("the containerdebug config is valid");
157+
146158
Self::from_merged(
147159
merged,
160+
containerdebug,
148161
validate::ValidatedLogging {
149162
hive_container: ValidatedContainerLogConfigChoice::Automatic(
150163
AutomaticContainerLogConfig::default(),

‎rust/operator-binary/src/controller/build/properties/hive_site.rs‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,16 @@ pub fn build(
139139
mod tests {
140140
use super::*;
141141
use crate::{
142-
controller::build::properties::test_support::{derby_cluster_config, s3_cluster_config},
142+
controller::build::properties::test_support::{
143+
default_metastore_config, derby_cluster_config, s3_cluster_config,
144+
},
143145
crd::MetaStoreConfig,
144146
};
145147

146148
#[test]
147149
fn defaults_present_for_minimal_derby_cluster() {
148150
let cluster_config = derby_cluster_config();
149-
let merged = ValidatedMetaStoreConfig::from_merged_for_test(MetaStoreConfig::default());
151+
let merged = ValidatedMetaStoreConfig::from_merged_for_test(default_metastore_config());
150152

151153
let data = build(
152154
&cluster_config,
@@ -176,7 +178,7 @@ mod tests {
176178
let cluster_config = derby_cluster_config();
177179
let merged = ValidatedMetaStoreConfig::from_merged_for_test(MetaStoreConfig {
178180
warehouse_dir: Some("/custom/warehouse".to_string()),
179-
..MetaStoreConfig::default()
181+
..default_metastore_config()
180182
});
181183

182184
let data = build(
@@ -197,7 +199,7 @@ mod tests {
197199
#[test]
198200
fn s3_connection_emits_s3a_settings() {
199201
let cluster_config = s3_cluster_config();
200-
let merged = ValidatedMetaStoreConfig::from_merged_for_test(MetaStoreConfig::default());
202+
let merged = ValidatedMetaStoreConfig::from_merged_for_test(default_metastore_config());
201203

202204
let data = build(
203205
&cluster_config,
@@ -225,7 +227,7 @@ mod tests {
225227
#[test]
226228
fn s3_connection_registers_the_s3_scheme() {
227229
let cluster_config = s3_cluster_config();
228-
let merged = ValidatedMetaStoreConfig::from_merged_for_test(MetaStoreConfig::default());
230+
let merged = ValidatedMetaStoreConfig::from_merged_for_test(default_metastore_config());
229231

230232
let data = build(
231233
&cluster_config,
@@ -245,7 +247,7 @@ mod tests {
245247
#[test]
246248
fn no_s3_connection_leaves_the_s3_scheme_unregistered() {
247249
let cluster_config = derby_cluster_config();
248-
let merged = ValidatedMetaStoreConfig::from_merged_for_test(MetaStoreConfig::default());
250+
let merged = ValidatedMetaStoreConfig::from_merged_for_test(default_metastore_config());
249251

250252
let data = build(
251253
&cluster_config,
@@ -262,7 +264,7 @@ mod tests {
262264
#[test]
263265
fn user_override_wins_over_everything() {
264266
let cluster_config = derby_cluster_config();
265-
let merged = ValidatedMetaStoreConfig::from_merged_for_test(MetaStoreConfig::default());
267+
let merged = ValidatedMetaStoreConfig::from_merged_for_test(default_metastore_config());
266268
let overrides = [("hive.metastore.port".to_string(), "1234".to_string())]
267269
.into_iter()
268270
.collect();

‎rust/operator-binary/src/controller/build/properties/mod.rs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,27 @@ mod tests {
3939

4040
#[cfg(test)]
4141
pub(crate) mod test_support {
42-
use stackable_operator::crd::s3;
42+
use stackable_operator::{config::fragment, crd::s3};
4343

4444
use crate::{
4545
controller::{ValidatedClusterConfig, test_support::DERBY_YAML},
4646
crd::{
47+
HiveRole, MetaStoreConfig,
4748
databases::{MetadataDatabaseConnection, derby_driver_class},
4849
v1alpha1,
4950
},
5051
};
5152

53+
/// The merged [`MetaStoreConfig`] of a role group that configures nothing itself.
54+
pub fn default_metastore_config() -> MetaStoreConfig {
55+
fragment::validate(MetaStoreConfig::default_config(
56+
"simple-hive",
57+
&HiveRole::MetaStore,
58+
None,
59+
))
60+
.expect("the default config is complete")
61+
}
62+
5263
/// Build a minimal Derby-backed [`ValidatedClusterConfig`] for builder tests.
5364
pub fn derby_cluster_config() -> ValidatedClusterConfig {
5465
let hive: v1alpha1::HiveCluster =

‎rust/operator-binary/src/controller/build/resource/statefulset.rs‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
295295
{remove_vector_shutdown_file_command}
296296
prepare_signal_handlers
297297
mkdir --parents \"${file_log_directory}\" || true
298-
containerdebug --output={STACKABLE_LOG_DIR}/containerdebug-state.json --loop &
298+
{containerdebug_command}
299299
{start_command}
300300
wait_for_termination $!
301301
{create_vector_shutdown_file_command}
@@ -304,6 +304,10 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
304304
remove_vector_shutdown_file_command =
305305
remove_vector_shutdown_file_command(STACKABLE_LOG_DIR),
306306
file_log_directory = FILE_LOG_DIRECTORY.as_ref(),
307+
containerdebug_command = merged_config
308+
.containerdebug
309+
.background_command(STACKABLE_LOG_DIR)
310+
.unwrap_or_default(),
307311
create_vector_shutdown_file_command =
308312
create_vector_shutdown_file_command(STACKABLE_LOG_DIR),
309313
},
@@ -515,6 +519,11 @@ pub(crate) fn build_metastore_rolegroup_statefulset(
515519
mod tests {
516520
use std::str::FromStr;
517521

522+
use rstest::rstest;
523+
use stackable_operator::{
524+
crd::containerdebug::ValidatedContainerdebugConfig, shared::time::Duration,
525+
};
526+
518527
use super::*;
519528
use crate::{
520529
controller::test_support::{DERBY_YAML, minimal_hive, validated_cluster},
@@ -687,4 +696,51 @@ mod tests {
687696
[("KRB5_CONFIG".to_string(), "/custom/krb5.conf".to_string())]
688697
);
689698
}
699+
700+
/// The hive container starts `containerdebug` from the role group's validated config. The
701+
/// command itself is owned (and tested) by operator-rs, so only the wiring is checked here.
702+
#[rstest]
703+
#[case::enabled(ValidatedContainerdebugConfig::Enabled {
704+
interval: Duration::from_minutes_unchecked(10)
705+
})]
706+
#[case::disabled(ValidatedContainerdebugConfig::Disabled)]
707+
fn hive_container_starts_containerdebug_from_config(
708+
#[case] containerdebug: ValidatedContainerdebugConfig,
709+
) {
710+
let expected = containerdebug.background_command(STACKABLE_LOG_DIR);
711+
let hive = minimal_hive(DERBY_YAML);
712+
let cluster = validated_cluster(&hive);
713+
let role_group_name = RoleGroupName::from_str("default").expect("valid role group name");
714+
let mut rg = cluster.role_group_configs[&HiveRole::MetaStore][&role_group_name].clone();
715+
rg.config.containerdebug = containerdebug;
716+
717+
let stateful_set = build_metastore_rolegroup_statefulset(
718+
&HiveRole::MetaStore,
719+
&cluster,
720+
&role_group_name,
721+
&rg,
722+
)
723+
.expect("the StatefulSet builds");
724+
725+
let args = stateful_set
726+
.spec
727+
.expect("the StatefulSet has a spec")
728+
.template
729+
.spec
730+
.expect("the pod template has a spec")
731+
.containers
732+
.into_iter()
733+
.find(|container| container.name == Container::Hive.name().to_string())
734+
.expect("the hive container exists")
735+
.args
736+
.expect("the hive container has args")
737+
.join("\n");
738+
assert_eq!(
739+
args.lines()
740+
.map(str::trim)
741+
.find(|line| line.starts_with("containerdebug ")),
742+
expected.as_deref(),
743+
"args: {args}"
744+
);
745+
}
690746
}

0 commit comments

Comments
 (0)