git.delta.rocks / jrsonnet / refs/commits / 754b45cdacd0

difftreelog

fix make indicatif optional

Yaroslav Bolyukin2024-03-24parent: #9b6d5bf.patch.diff
in: trunk

7 files changed

modifiedcmds/fleet/Cargo.tomldiffbeforeafterboth
26 "derive",
27 "env",
28 "wrap_help",
29 "unicode",
30] }
31tracing = "0.1"26tracing = "0.1"
32tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }27tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
33tokio-util = { version = "0.7", features = ["codec"] }28tokio-util = { version = "0.7", features = ["codec"] }
34async-trait = "0.1"29async-trait = "0.1"
35futures = "0.3"30futures = "0.3"
36tracing-indicatif = "0.3"
37indicatif = "0.17"
38itertools = "0.12"31itertools = "0.12"
39shlex = "1.3"32shlex = "1.3"
40tabled = { version = "0.15" }33tabled = { version = "0.15" }
41owo-colors = { version = "4.0", features = ["supports-color", "supports-colors"] }34owo-colors = { version = "4.0", features = [
35 "supports-color",
36 "supports-colors",
37] }
42r2d2 = "0.8.10"38r2d2 = "0.8.10"
43abort-on-drop = "0.2"39abort-on-drop = "0.2"
44unindent = "0.2"40unindent = "0.2"
45regex = "1.10"41regex = "1.10"
46openssh = "0.10"42openssh = "0.10"
43
44tracing-indicatif = { version = "0.3", optional = true }
47human-repr = "1.1"45human-repr = { version = "1.1", optional = true }
46indicatif = { version = "0.17", optional = true }
47
48[features]
49# Not quite stable
50indicatif = ["tracing-indicatif", "dep:indicatif", "human-repr", "better-command/indicatif"]
4851
modifiedcmds/fleet/src/main.rsdiffbeforeafterboth
26use futures::stream::FuturesUnordered;26use futures::stream::FuturesUnordered;
27use futures::TryStreamExt;27use futures::TryStreamExt;
28use host::{Config, FleetOpts};28use host::{Config, FleetOpts};
29#[cfg(feature = "indicatif")]
29use human_repr::HumanCount;30use human_repr::HumanCount;
31#[cfg(feature = "indicatif")]
30use indicatif::{ProgressState, ProgressStyle};32use indicatif::{ProgressState, ProgressStyle};
31use tracing::{error, info};33use tracing::{error, info};
32use tracing::{info_span, Instrument};34use tracing::{info_span, Instrument};
35#[cfg(feature = "indicatif")]
33use tracing_indicatif::IndicatifLayer;36use tracing_indicatif::IndicatifLayer;
34use tracing_subscriber::{prelude::*, EnvFilter};37use tracing_subscriber::{prelude::*, EnvFilter};
3538
108}111}
109112
110fn setup_logging() {113fn setup_logging() {
114 #[cfg(feature = "indicatif")]
111 let indicatif_layer = IndicatifLayer::new().with_progress_style(115 let indicatif_layer = IndicatifLayer::new().with_progress_style(
112 ProgressStyle::with_template(116 ProgressStyle::with_template(
113 "{color_start}{span_child_prefix} {span_name}{{{span_fields}}}{color_end} {wide_msg} {color_start}{download_progress} {elapsed}{color_end}",117 "{color_start}{span_child_prefix} {span_name}{{{span_fields}}}{color_end} {wide_msg} {color_start}{download_progress} {elapsed}{color_end}",
127 .with_key(131 .with_key(
128 "color_start",132 "color_start",
129 |state: &ProgressState, writer: &mut dyn std::fmt::Write| {133 |state: &ProgressState, writer: &mut dyn std::fmt::Write| {
134 use std::time::Duration;
130 let elapsed = state.elapsed();135 let elapsed = state.elapsed();
131136
132 if elapsed > Duration::from_secs(60) {137 if elapsed > Duration::from_secs(60) {
150155
151 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));156 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
152157
153 tracing_subscriber::registry()158 let reg = tracing_subscriber::registry().with({
154 .with(
155 tracing_subscriber::fmt::layer()159 let sub = tracing_subscriber::fmt::layer()
156 .without_time()160 .without_time()
157 .with_target(true)161 .with_target(true);
162 #[cfg(feature = "indicatif")]
158 .with_writer(indicatif_layer.get_stdout_writer())163 let sub = sub.with_writer(indicatif_layer.get_stdout_writer());
159 .with_filter(filter), // .withou,164 sub.with_filter(filter) // .withou,
160 )165 });
161 .with(indicatif_layer)166 // #[cfg(feature = "indicatif")]
162 .init();167 #[cfg(feature = "indicatif")]
168 let reg = reg.with(indicatif_layer);
169 reg.init();
163}170}
164171
165#[tokio::main]172#[tokio::main]
modifiedcmds/install-secrets/Cargo.tomldiffbeforeafterboth
6[dependencies]6[dependencies]
7age = { version = "0.10.0", features = ["ssh"] }7age = { version = "0.10.0", features = ["ssh"] }
8anyhow = "1.0.79"8anyhow = "1.0.79"
9tracing-subscriber = "0.3"9tracing-subscriber = { version = "0.3", features = ["env-filter"] }
10tracing = "0.1"10tracing = "0.1"
11nix = {version = "0.27.1", features = ["user", "fs"]}11nix = {version = "0.27.1", features = ["user", "fs"]}
12serde = { version = "1.0.196", features = ["derive"] }12serde = { version = "1.0.196", features = ["derive"] }
modifiedcrates/better-command/Cargo.tomldiffbeforeafterboth
10serde_json = "1.0"10serde_json = "1.0"
11tracing = "0.1"11tracing = "0.1"
12
12tracing-indicatif = "0.3"13tracing-indicatif = { version = "0.3", optional = true }
14
15[features]
16indicatif = ["tracing-indicatif"]
1317
modifiedcrates/better-command/src/handler.rsdiffbeforeafterboth
6use once_cell::sync::Lazy;6use once_cell::sync::Lazy;
7use regex::Regex;7use regex::Regex;
8use serde::Deserialize;8use serde::Deserialize;
9use tracing::{Span, info, warn, info_span};9use tracing::{info, info_span, warn, Span};
10#[cfg(feature = "indicatif")]
10use tracing_indicatif::span_ext::IndicatifSpanExt as _;11use tracing_indicatif::span_ext::IndicatifSpanExt as _;
1112
12pub trait Handler: Send {13pub trait Handler: Send {
141 }142 }
142 info!(target: "nix","building {}", drv);143 info!(target: "nix","building {}", drv);
143 let span = info_span!("build", drv);144 let span = info_span!("build", drv);
145 #[cfg(feature = "indicatif")]
144 span.pb_start();146 span.pb_start();
145 self.spans.insert(id, span);147 self.spans.insert(id, span);
146 } else {148 } else {
167 }169 }
168 info!(target: "nix","copying {} {} -> {}", drv, from, to);170 info!(target: "nix","copying {} {} -> {}", drv, from, to);
169 let span = info_span!("copy", from, to, drv);171 let span = info_span!("copy", from, to, drv);
172 #[cfg(feature = "indicatif")]
170 span.pb_start();173 span.pb_start();
171 self.spans.insert(id, span);174 self.spans.insert(id, span);
172 } else {175 } else {
183 && !(text.starts_with("copying '") && text.ends_with("' to the store"))186 && !(text.starts_with("copying '") && text.ends_with("' to the store"))
184 {187 {
185 let span = info_span!("job");188 let span = info_span!("job");
189 #[cfg(feature = "indicatif")]
190 {
186 span.pb_start();191 span.pb_start();
187 span.pb_set_message(&process_message(text.trim()));192 span.pb_set_message(&process_message(text.trim()));
193 }
188 self.spans.insert(id, span);194 self.spans.insert(id, span);
189 info!(target: "nix", "{}", text);195 info!(target: "nix", "{}", text);
190 }196 }
254 }260 }
255 }261 }
256 let span = info_span!("waiting on drv", drv);262 let span = info_span!("waiting on drv", drv);
263 #[cfg(feature = "indicatif")]
257 span.pb_start();264 span.pb_start();
258 self.spans.insert(id, span);265 self.spans.insert(id, span);
259 // Concurrent build of the same message266 // Concurrent build of the same message
264 NixLog::Result { fields, id, typ } if typ == 101 && !fields.is_empty() => {271 NixLog::Result { fields, id, typ } if typ == 101 && !fields.is_empty() => {
265 if let Some(span) = self.spans.get(&id) {272 if let Some(span) = self.spans.get(&id) {
266 if let LogField::String(s) = &fields[0] {273 if let LogField::String(s) = &fields[0] {
274 #[cfg(feature = "indicatif")]
267 span.pb_set_message(&process_message(s.trim()));275 span.pb_set_message(&process_message(s.trim()));
276 #[cfg(not(feature = "indicatif"))]
277 info!("{}", process_message(s));
268 } else {278 } else {
269 warn!("bad fields: {fields:?}");279 warn!("bad fields: {fields:?}");
270 }280 }
278 if let [LogField::Num(done), LogField::Num(expected), LogField::Num(_running), LogField::Num(_failed)] =288 if let [LogField::Num(done), LogField::Num(expected), LogField::Num(_running), LogField::Num(_failed)] =
279 &fields[..4]289 &fields[..4]
290 {
291 #[cfg(feature = "indicatif")]
280 {292 {
281 span.pb_set_length(*expected);293 span.pb_set_length(*expected);
282 span.pb_set_position(*done);294 span.pb_set_position(*done);
283 } else {295 }
296 let _ = (span, done, expected);
297 } else {
284 warn!("bad fields: {fields:?}");298 warn!("bad fields: {fields:?}");
285 }299 }
modifiedlib/fleetLib.nixdiffbeforeafterboth
34 then "${this}-${other}"34 then "${this}-${other}"
35 else "${other}-${this}";35 else "${other}-${this}";
3636
37 # mkDefault = mkOverride 1000
37 # For places, where fleet knows better than nixpkgs defaults38 # For places, where fleet knows better than nixpkgs defaults.
38 mkFleetDefault = mkOverride 999;39 mkFleetDefault = mkOverride 999;
40 # Some generators use mkDefault, but optionDefault is set by nixpkgs.
41 mkFleetGeneratorDefault = mkOverride 1001;
39}42}
4043
modifiedmodules/fleet/meta.nixdiffbeforeafterboth
34 type = unspecified;34 type = unspecified;
35 description = "Nixos configuration";35 description = "Nixos configuration";
36 };36 };
37 nixpkgs = mkOption {
38 type = unspecified;
39 description = "Nixpkgs override";
40 default = nixpkgs;
41 };
37 };42 };
38 config = {43 config = {
39 nixosSystem = nixpkgs.lib.nixosSystem {44 nixosSystem = hostConfig.config.nixpkgs.lib.nixosSystem {
40 inherit (hostConfig.config) system modules;45 inherit (hostConfig.config) system modules;
41 specialArgs = {46 specialArgs = {
42 inherit fleetLib;47 inherit fleetLib;
45 };50 };
46 modules = [51 modules = [
47 ({...}: {52 ({...}: {
48 networking.hostName = mkFleetDefault hostName;53 networking.hostName = mkFleetGeneratorDefault hostName;
49 })54 })
50 ];55 ];
51 };56 };