Skip to content

feat!: Use stackable-telemetry #581

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

Merged
merged 8 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
543 changes: 406 additions & 137 deletions Cargo.lock

Large diffs are not rendered by default.

2,492 changes: 2,013 additions & 479 deletions Cargo.nix

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ edition = "2021"
repository = "https://github.com/stackabletech/secret-operator"

[workspace.dependencies]
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.89.1", features = ["time"] }
stackable-telemetry = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-telemetry-0.4.0" }

anyhow = "1.0"
async-trait = "0.1"
bindgen = "0.71"
Expand All @@ -19,10 +22,7 @@ byteorder = "1.5"
clap = "4.5"
futures = { version = "0.3", features = ["compat"] }
h2 = "0.4"
ldap3 = { version = "0.11", default-features = false, features = [
"gssapi",
"tls",
] }
ldap3 = { version = "0.11", default-features = false, features = ["gssapi", "tls"] }
libc = "0.2"
native-tls = "0.2"
openssl = "0.10"
Expand All @@ -37,7 +37,6 @@ serde_json = "1.0"
serde_yaml = "0.9"
snafu = "0.8"
socket2 = { version = "0.5", features = ["all"] }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "stackable-operator-0.87.0", features = ["time"] }
strum = { version = "0.27", features = ["derive"] }
sys-mount = { version = "3.0", default-features = false }
tempfile = "3.12"
Expand Down
7 changes: 4 additions & 3 deletions crate-hashes.json

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

4 changes: 3 additions & 1 deletion rust/olm-deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ repository.workspace = true
publish = false

[dependencies]
stackable-operator.workspace = true
stackable-telemetry.workspace = true

anyhow.workspace = true
clap.workspace = true
tokio.workspace = true
tracing.workspace = true
stackable-operator.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
Expand Down
80 changes: 63 additions & 17 deletions rust/olm-deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,29 @@ mod owner;
mod resources;
mod tolerations;

use std::ops::Deref as _;

use anyhow::{Context, Result, anyhow, bail};
use clap::{Parser, crate_description, crate_version};
use clap::Parser;
use stackable_operator::{
cli::Command,
cli::{Command, RollingPeriod, TelemetryArguments},
client,
k8s_openapi::api::{apps::v1::Deployment, rbac::v1::ClusterRole},
kube,
kube::{
self,
api::{Api, DynamicObject, ListParams, Patch, PatchParams, ResourceExt},
core::GroupVersionKind,
discovery::{ApiResource, Discovery, Scope},
},
logging, utils,
utils::cluster_info::KubernetesClusterInfoOpts,
};
use stackable_telemetry::{Tracing, tracing::settings::Settings};
use tracing::level_filters::LevelFilter;

pub const APP_NAME: &str = "stkbl-secret-olm-deployer";
pub const ENV_VAR_LOGGING: &str = "STKBL_SECRET_OLM_DEPLOYER_LOG";

// TODO (@NickLarsenNZ): Change the variable to `CONSOLE_LOG`
pub const ENV_VAR_CONSOLE_LOG: &str = "STKBL_SECRET_OLM_DEPLOYER_LOG";

mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
Expand Down Expand Up @@ -63,13 +68,16 @@ struct OlmDeployerRun {
help = "Name of ClusterServiceVersion object that owns this Deployment."
)]
csv: String,

#[arg(long, short, help = "Namespace of the ClusterServiceVersion object.")]
namespace: String,

#[arg(long, short, help = "Directory with manifests to patch and apply.")]
dir: std::path::PathBuf,
/// Tracing log collector system
#[arg(long, env, default_value_t, value_enum)]
pub tracing_target: logging::TracingTarget,

#[command(flatten)]
pub telemetry_arguments: TelemetryArguments,

#[command(flatten)]
pub cluster_info_opts: KubernetesClusterInfoOpts,
}
Expand All @@ -82,18 +90,56 @@ async fn main() -> Result<()> {
csv,
namespace,
dir,
tracing_target,
telemetry_arguments,
cluster_info_opts,
}) = opts.cmd
{
logging::initialize_logging(ENV_VAR_LOGGING, APP_NAME, tracing_target);
utils::print_startup_string(
crate_description!(),
crate_version!(),
built_info::GIT_VERSION,
built_info::TARGET,
built_info::BUILT_TIME_UTC,
built_info::RUSTC_VERSION,
let _tracing_guard = Tracing::builder()
.service_name("secret-operator-olm-deployer")
.with_console_output((
ENV_VAR_CONSOLE_LOG,
LevelFilter::INFO,
!telemetry_arguments.no_console_output,
))
// NOTE (@NickLarsenNZ): Before stackable-telemetry was used, the log directory was
// set via an env: `STKBL_SECRET_OLM_DEPLOYER_LOG_DIRECTORY`.
// See: https://github.com/stackabletech/operator-rs/blob/f035997fca85a54238c8de895389cc50b4d421e2/crates/stackable-operator/src/logging/mod.rs#L40
// Now it will be `ROLLING_LOGS` (or via `--rolling-logs <DIRECTORY>`).
.with_file_output(telemetry_arguments.rolling_logs.map(|log_directory| {
let rotation_period = telemetry_arguments
.rolling_logs_period
.unwrap_or(RollingPeriod::Never)
.deref()
.clone();

Settings::builder()
.with_environment_variable(ENV_VAR_CONSOLE_LOG)
.with_default_level(LevelFilter::INFO)
.file_log_settings_builder(log_directory, "tracing-rs.log")
.with_rotation_period(rotation_period)
.build()
}))
.with_otlp_log_exporter((
"OTLP_LOG",
LevelFilter::DEBUG,
telemetry_arguments.otlp_logs,
))
.with_otlp_log_exporter((
"OTLP_TRACE",
LevelFilter::DEBUG,
telemetry_arguments.otlp_logs,
))
.build()
.init()?;

tracing::info!(
built_info.pkg_version = built_info::PKG_VERSION,
built_info.git_version = built_info::GIT_VERSION,
built_info.target = built_info::TARGET,
built_info.built_time_utc = built_info::BUILT_TIME_UTC,
built_info.rustc_version = built_info::RUSTC_VERSION,
"Starting {description}",
description = built_info::PKG_DESCRIPTION
);

let client =
Expand Down
3 changes: 2 additions & 1 deletion rust/operator-binary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ publish = false
[dependencies]
stackable-krb5-provision-keytab = { path = "../krb5-provision-keytab" }
stackable-secret-operator-crd-utils = { path = "../crd-utils" }
stackable-operator.workspace = true
stackable-telemetry.workspace = true

anyhow.workspace = true
async-trait.workspace = true
Expand All @@ -27,7 +29,6 @@ serde_json.workspace = true
serde.workspace = true
snafu.workspace = true
socket2.workspace = true
stackable-operator.workspace = true
strum.workspace = true
sys-mount.workspace = true
tempfile.workspace = true
Expand Down
78 changes: 59 additions & 19 deletions rust/operator-binary/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{os::unix::prelude::FileTypeExt, path::PathBuf};
use std::{ops::Deref, os::unix::prelude::FileTypeExt, path::PathBuf};

use anyhow::Context;
use clap::{Parser, crate_description, crate_version};
use clap::Parser;
use csi_server::{
controller::SecretProvisionerController, identity::SecretProvisionerIdentity,
node::SecretProvisionerNode,
Expand All @@ -11,11 +11,15 @@ use grpc::csi::v1::{
controller_server::ControllerServer, identity_server::IdentityServer, node_server::NodeServer,
};
use stackable_operator::{
CustomResourceExt, logging::TracingTarget, utils::cluster_info::KubernetesClusterInfoOpts,
CustomResourceExt,
cli::{RollingPeriod, TelemetryArguments},
utils::cluster_info::KubernetesClusterInfoOpts,
};
use stackable_telemetry::{Tracing, tracing::settings::Settings};
use tokio::signal::unix::{SignalKind, signal};
use tokio_stream::wrappers::UnixListenerStream;
use tonic::transport::Server;
use tracing::level_filters::LevelFilter;
use utils::{TonicUnixStream, uds_bind_private};

mod backend;
Expand All @@ -29,6 +33,9 @@ mod utils;
pub const APP_NAME: &str = "secret";
pub const OPERATOR_NAME: &str = "secrets.stackable.tech";

// TODO (@NickLarsenNZ): Change the variable to `CONSOLE_LOG`
pub const ENV_VAR_CONSOLE_LOG: &str = "SECRET_PROVISIONER_LOG";

#[derive(clap::Parser)]
#[clap(author, version)]
struct Opts {
Expand All @@ -53,9 +60,8 @@ struct SecretOperatorRun {
#[clap(long, env)]
privileged: bool,

/// Tracing log collector system
#[arg(long, env, default_value_t, value_enum)]
pub tracing_target: TracingTarget,
#[command(flatten)]
pub telemetry_arguments: TelemetryArguments,

#[command(flatten)]
pub cluster_info_opts: KubernetesClusterInfoOpts,
Expand All @@ -75,22 +81,56 @@ async fn main() -> anyhow::Result<()> {
stackable_operator::cli::Command::Run(SecretOperatorRun {
csi_endpoint,
node_name,
tracing_target,
telemetry_arguments,
privileged,
cluster_info_opts,
}) => {
stackable_operator::logging::initialize_logging(
"SECRET_PROVISIONER_LOG",
APP_NAME,
tracing_target,
);
stackable_operator::utils::print_startup_string(
crate_description!(),
crate_version!(),
built_info::GIT_VERSION,
built_info::TARGET,
built_info::BUILT_TIME_UTC,
built_info::RUSTC_VERSION,
let _tracing_guard = Tracing::builder()
.service_name("secret-operator")
.with_console_output((
ENV_VAR_CONSOLE_LOG,
LevelFilter::INFO,
!telemetry_arguments.no_console_output,
))
// NOTE (@NickLarsenNZ): Before stackable-telemetry was used, the log directory was
// set via an env: `SECRET_PROVISIONER_LOG_DIRECTORY`.
// See: https://github.com/stackabletech/operator-rs/blob/f035997fca85a54238c8de895389cc50b4d421e2/crates/stackable-operator/src/logging/mod.rs#L40
// Now it will be `ROLLING_LOGS` (or via `--rolling-logs <DIRECTORY>`).
.with_file_output(telemetry_arguments.rolling_logs.map(|log_directory| {
let rotation_period = telemetry_arguments
.rolling_logs_period
.unwrap_or(RollingPeriod::Hourly)
.deref()
.clone();

Settings::builder()
.with_environment_variable(ENV_VAR_CONSOLE_LOG)
.with_default_level(LevelFilter::INFO)
.file_log_settings_builder(log_directory, "tracing-rs.log")
.with_rotation_period(rotation_period)
.build()
}))
.with_otlp_log_exporter((
"OTLP_LOG",
LevelFilter::DEBUG,
telemetry_arguments.otlp_logs,
))
.with_otlp_log_exporter((
"OTLP_TRACE",
LevelFilter::DEBUG,
telemetry_arguments.otlp_logs,
))
.build()
.init()?;

tracing::info!(
built_info.pkg_version = built_info::PKG_VERSION,
built_info.git_version = built_info::GIT_VERSION,
built_info.target = built_info::TARGET,
built_info.built_time_utc = built_info::BUILT_TIME_UTC,
built_info.rustc_version = built_info::RUSTC_VERSION,
"Starting {description}",
description = built_info::PKG_DESCRIPTION
);

let client = stackable_operator::client::initialize_operator(
Expand Down