Skip to content

Commit d16cef3

Browse files
Merge pull request #83 from CleverCloud/devel/fdubois/chore/deps
Update dependencies and use tracing crate instead of slog
2 parents 9b344bd + 3f84f36 commit d16cef3

File tree

19 files changed

+763
-509
lines changed

19 files changed

+763
-509
lines changed

Cargo.lock

Lines changed: 52 additions & 182 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ keywords = ["kubernetes", "operator", "clevercloud", "openshift"]
1616
async-trait = "^0.1.53"
1717
chrono = "^0.4.19"
1818
clap = { version = "^3.1.18", features = ["derive"] }
19-
clevercloud-sdk = { version = "^0.10.1", features = ["jsonschemas"] }
19+
clevercloud-sdk = { version = "^0.10.2", features = ["jsonschemas"] }
2020
config = "^0.13.1"
2121
futures = "^0.3.21"
2222
hostname = "^0.3.1"
2323
hyper = { version = "^0.14.18", features = ["server", "tcp", "http1"] }
2424
json-patch = "^0.2.6"
25-
kube = { version = "^0.72.0", default-features = false, features = [
25+
kube = { version = "^0.73.0", default-features = false, features = [
2626
"client",
2727
"rustls-tls",
2828
"ws",
2929
"gzip",
3030
"derive",
3131
"jsonpatch",
3232
] }
33-
kube-derive = "^0.72.0"
34-
kube-runtime = "^0.72.0"
35-
k8s-openapi = { version = "^0.14.0", default-features = false, features = [
33+
kube-derive = "^0.73.0"
34+
kube-runtime = "^0.73.0"
35+
k8s-openapi = { version = "^0.15.0", default-features = false, features = [
3636
"v1_21",
3737
] }
3838
lazy_static = { version = "^1.4.0", optional = true }
@@ -44,52 +44,41 @@ opentelemetry-jaeger = { version = "^0.16.0", features = [
4444
"collector_client",
4545
], optional = true }
4646
paw = "^1.0.0"
47-
prometheus = { version = "^0.13.0", optional = true }
47+
prometheus = { version = "^0.13.1", optional = true }
4848
schemars = { version = "^0.8.10", features = [
4949
"chrono",
5050
"indexmap1",
5151
"uuid1",
5252
"bytes",
5353
"url",
5454
] }
55-
sentry = { version = "^0.25.0", optional = true }
55+
sentry = { version = "^0.26.0", optional = true }
5656
serde = { version = "^1.0.137", features = ["derive"] }
5757
serde_json = { version = "^1.0.81", features = [
5858
"preserve_order",
5959
"float_roundtrip",
6060
] }
6161
serde_yaml = "^0.8.24"
62-
slog = { version = "^2.7.0" }
63-
slog-async = "^2.7.0"
64-
slog-term = "^2.9.0"
65-
slog-scope = "^4.4.0"
66-
slog-stdlog = { version = "^4.1.1", optional = true }
6762
thiserror = "^1.0.31"
6863
tokio = { version = "^1.18.2", features = ["full"] }
69-
tracing = { version = "^0.1.34", optional = true }
70-
tracing-subscriber = { version = "^0.3.11", optional = true }
64+
tracing = "^0.1.34"
65+
tracing-subscriber = { version = "^0.3.11", default-features = false, features = ["std", "ansi", "tracing-log"] }
7166
tracing-opentelemetry = { version = "^0.17.2", optional = true }
7267

7368
[features]
7469
default = [
7570
"metrics",
7671
"trace",
7772
"tracker",
78-
"slog/release_max_level_debug",
79-
"slog/max_level_trace",
8073
]
8174
logging = [
8275
"clevercloud-sdk/logging",
83-
"tracing-subscriber/tracing-log",
84-
"slog-stdlog",
8576
]
8677
metrics = ["clevercloud-sdk/metrics", "lazy_static", "prometheus"]
8778
tracker = ["sentry"]
8879
trace = [
8980
"clevercloud-sdk/trace",
9081
"clevercloud-sdk/tokio",
91-
"tracing",
92-
"tracing-subscriber",
9382
"tracing-opentelemetry",
9483
"opentelemetry",
9584
"opentelemetry-jaeger",

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ------------------------------------------------------------------------------
22
# Define variables
3+
PWD ?= $(shell pwd)
34
DIST ?= $(PWD)/target/release
45
BIN_DIR ?= $(HOME)/.local/bin
56

src/cmd/mod.rs

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use hyper::{
1818
Server,
1919
};
2020
use paw::ParseArgs;
21-
use slog_scope::{crit, error, info};
21+
use tracing::{error, info};
2222

2323
use crate::{
2424
cmd::crd::CustomResourceDefinitionError,
@@ -51,6 +51,14 @@ pub enum Error {
5151
Execution(String, Arc<Error>),
5252
#[error("failed to execute command, {0}")]
5353
CustomResourceDefinition(CustomResourceDefinitionError),
54+
#[error("failed to parse listen address '{0}', {1}")]
55+
Listen(String, AddrParseError),
56+
#[error("failed to handle termintion signal, {0}")]
57+
SigTerm(io::Error),
58+
#[error("failed to create kubernetes client, {0}")]
59+
Client(client::Error),
60+
#[error("failed to create clever cloud client, {0}")]
61+
CleverClient(clevercloud_sdk::oauth10a::proxy::Error),
5462
}
5563

5664
// -----------------------------------------------------------------------------
@@ -111,35 +119,15 @@ impl ParseArgs for Args {
111119
}
112120
}
113121

114-
// -----------------------------------------------------------------------------
115-
// DaemonError enum
116-
117-
#[derive(thiserror::Error, Debug)]
118-
pub enum DaemonError {
119-
#[error("failed to parse listen address '{0}', {1}")]
120-
Listen(String, AddrParseError),
121-
#[error("failed to handle termintion signal, {0}")]
122-
SigTerm(io::Error),
123-
#[error("failed to create kubernetes client, {0}")]
124-
Client(client::Error),
125-
#[error("failed to create clever cloud client, {0}")]
126-
CleverClient(clevercloud_sdk::oauth10a::proxy::Error),
127-
}
128-
129122
// -----------------------------------------------------------------------------
130123
// daemon function
131124

132125
#[cfg_attr(feature = "trace", tracing::instrument)]
133-
pub async fn daemon(
134-
kubeconfig: Option<PathBuf>,
135-
config: Arc<Configuration>,
136-
) -> Result<(), DaemonError> {
126+
pub async fn daemon(kubeconfig: Option<PathBuf>, config: Arc<Configuration>) -> Result<(), Error> {
137127
// -------------------------------------------------------------------------
138128
// Create a new kubernetes client from path if defined, or via the
139129
// environment or defaults locations
140-
let kube_client = client::try_new(kubeconfig)
141-
.await
142-
.map_err(DaemonError::Client)?;
130+
let kube_client = client::try_new(kubeconfig).await.map_err(Error::Client)?;
143131

144132
// -------------------------------------------------------------------------
145133
// Create a new clever-cloud client
@@ -155,14 +143,14 @@ pub async fn daemon(
155143
}),
156144
proxy.no.to_owned(),
157145
)
158-
.map_err(DaemonError::CleverClient)?;
146+
.map_err(Error::CleverClient)?;
159147

160148
ProxyConnectorBuilder::default()
161149
.with_proxy(proxy)
162150
.build(HttpsConnector::new())
163-
.map_err(DaemonError::CleverClient)?
151+
.map_err(Error::CleverClient)?
164152
}
165-
_ => ProxyConnectorBuilder::try_from_env().map_err(DaemonError::CleverClient)?,
153+
_ => ProxyConnectorBuilder::try_from_env().map_err(Error::CleverClient)?,
166154
};
167155

168156
let clever_client = Client::builder()
@@ -187,7 +175,10 @@ pub async fn daemon(
187175

188176
info!("Start to listen for events of postgresql addon custom resource");
189177
if let Err(err) = reconciler.watch(postgresql_state).await {
190-
crit!("Could not reconcile postgresql addon custom resource"; "error" => err.to_string());
178+
error!(
179+
"Could not reconcile postgresql addon custom resource, {}",
180+
err
181+
);
191182
}
192183

193184
abort();
@@ -197,7 +188,7 @@ pub async fn daemon(
197188

198189
info!("Start to listen for events of redis addon custom resource");
199190
if let Err(err) = reconciler.watch(redis_state).await {
200-
crit!("Could not reconcile redis addon custom resource"; "error" => err.to_string());
191+
error!("Could not reconcile redis addon custom resource, {}", err);
201192
}
202193

203194
abort();
@@ -207,7 +198,7 @@ pub async fn daemon(
207198

208199
info!("Start to listen for events of mysql addon custom resource");
209200
if let Err(err) = reconciler.watch(mysql_state).await {
210-
crit!("Could not reconcile mysql addon custom resource"; "error" => err.to_string());
201+
error!("Could not reconcile mysql addon custom resource, {}", err);
211202
}
212203

213204
abort();
@@ -217,7 +208,7 @@ pub async fn daemon(
217208

218209
info!("Start to listen for events of mongodb addon custom resource");
219210
if let Err(err) = reconciler.watch(mongodb_state).await {
220-
crit!("Could not reconcile mongodb addon custom resource"; "error" => err.to_string());
211+
error!("Could not reconcile mongodb addon custom resource, {}", err);
221212
}
222213

223214
abort();
@@ -227,7 +218,7 @@ pub async fn daemon(
227218

228219
info!("Start to listen for events of pulsar addon custom resource");
229220
if let Err(err) = reconciler.watch(pulsar_state).await {
230-
crit!("Could not reconcile plusar addon custom resource"; "error" => err.to_string());
221+
error!("Could not reconcile plusar addon custom resource, {}", err);
231222
}
232223

233224
abort();
@@ -237,7 +228,10 @@ pub async fn daemon(
237228

238229
info!("Start to listen for events of config-provider addon custom resource");
239230
if let Err(err) = reconciler.watch(config_provider_state).await {
240-
crit!("Could not reconcile config-provider addon custom resource"; "error" => err.to_string());
231+
error!(
232+
"Could not reconcile config-provider addon custom resource, {}",
233+
err
234+
);
241235
}
242236

243237
abort();
@@ -247,7 +241,10 @@ pub async fn daemon(
247241

248242
info!("Start to listen for events of elasticsearch addon custom resource");
249243
if let Err(err) = reconciler.watch(elasticsearch_state).await {
250-
crit!("Could not reconcile elasticsearch addon custom resource"; "error" => err.to_string());
244+
error!(
245+
"Could not reconcile elasticsearch addon custom resource, {}",
246+
err
247+
);
251248
}
252249

253250
abort();
@@ -260,13 +257,13 @@ pub async fn daemon(
260257
.operator
261258
.listen
262259
.parse()
263-
.map_err(|err| DaemonError::Listen(config.operator.listen.to_owned(), err))?;
260+
.map_err(|err| Error::Listen(config.operator.listen.to_owned(), err))?;
264261

265262
let server = tokio::spawn(async move {
266263
let builder = match Server::try_bind(&addr) {
267264
Ok(builder) => builder,
268265
Err(err) => {
269-
crit!("Could not bind http server"; "error" => err.to_string());
266+
error!("Could not bind http server, {}", err);
270267
abort();
271268
}
272269
};
@@ -277,17 +274,15 @@ pub async fn daemon(
277274

278275
info!("Start to listen for http request on {}", addr);
279276
if let Err(err) = server.await {
280-
crit!("Could not serve http server"; "error" => err.to_string());
277+
error!("Could not serve http server, {}", err);
281278
}
282279

283280
abort()
284281
});
285282

286283
// -------------------------------------------------------------------------
287284
// Wait for termination signal
288-
tokio::signal::ctrl_c()
289-
.await
290-
.map_err(DaemonError::SigTerm)?;
285+
tokio::signal::ctrl_c().await.map_err(Error::SigTerm)?;
291286

292287
// -------------------------------------------------------------------------
293288
// Cancel reconcilers
@@ -296,7 +291,7 @@ pub async fn daemon(
296291
for handle in handles {
297292
if let Err(err) = handle.await {
298293
if !err.is_cancelled() {
299-
error!("Could not wait for the task to complete"; "error" => err.to_string());
294+
error!("Could not wait for the task to complete, {}", err);
300295
}
301296
}
302297
}
@@ -306,7 +301,10 @@ pub async fn daemon(
306301
server.abort();
307302
if let Err(err) = server.await {
308303
if !err.is_cancelled() {
309-
error!("Could not wait for the http server to gracefully close"; "error" => err.to_string());
304+
error!(
305+
"Could not wait for the http server to gracefully close, {}",
306+
err
307+
);
310308
}
311309
}
312310

src/logging.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! # Logging module
2+
//!
3+
//! This module provides logging facilities and helpers
4+
5+
use tracing::Level;
6+
7+
// -----------------------------------------------------------------------------
8+
// Error enumeration
9+
10+
#[derive(thiserror::Error, Debug)]
11+
pub enum Error {
12+
#[error("failed to set global default subscriber, {0}")]
13+
GlobalDefaultSubscriber(tracing::subscriber::SetGlobalDefaultError),
14+
}
15+
16+
// -----------------------------------------------------------------------------
17+
// helpers
18+
19+
pub const fn level(verbosity: usize) -> Level {
20+
match verbosity {
21+
0 => Level::ERROR,
22+
1 => Level::WARN,
23+
2 => Level::INFO,
24+
3 => Level::DEBUG,
25+
_ => Level::TRACE,
26+
}
27+
}
28+
29+
pub fn initialize(verbosity: usize) -> Result<(), Error> {
30+
tracing::subscriber::set_global_default(
31+
tracing_subscriber::fmt()
32+
.with_max_level(level(verbosity))
33+
.with_thread_names(true)
34+
.with_line_number(true)
35+
.with_thread_ids(true)
36+
.with_target(true)
37+
.finish(),
38+
)
39+
.map_err(Error::GlobalDefaultSubscriber)
40+
}

0 commit comments

Comments
 (0)