Skip to content

Commit 587c379

Browse files
committed
Add child dsc process to pass-through traces to parent
1 parent d6d4b26 commit 587c379

9 files changed

+142
-25
lines changed

dsc/assertion.dsc.resource.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"get": {
88
"executable": "dsc",
99
"args": [
10+
"--trace-format",
11+
"pass-through",
1012
"config",
1113
"--as-group",
1214
"test",
@@ -17,6 +19,8 @@
1719
"set": {
1820
"executable": "dsc",
1921
"args": [
22+
"--trace-format",
23+
"pass-through",
2024
"config",
2125
"--as-group",
2226
"test"
@@ -28,6 +32,8 @@
2832
"test": {
2933
"executable": "dsc",
3034
"args": [
35+
"--trace-format",
36+
"pass-through",
3137
"config",
3238
"--as-group",
3339
"test",
@@ -45,19 +51,11 @@
4551
"5": "Resource instance failed schema validation",
4652
"6": "Command cancelled"
4753
},
48-
"schema": {
49-
"command": {
50-
"executable": "dsc",
51-
"args": [
52-
"schema",
53-
"--type",
54-
"configuration"
55-
]
56-
}
57-
},
5854
"validate": {
5955
"executable": "dsc",
6056
"args": [
57+
"--trace-format",
58+
"pass-through",
6159
"config",
6260
"validate"
6361
],

dsc/group.dsc.resource.json

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"get": {
88
"executable": "dsc",
99
"args": [
10+
"--trace-format",
11+
"pass-through",
1012
"config",
1113
"--as-group",
1214
"get"
@@ -16,6 +18,8 @@
1618
"set": {
1719
"executable": "dsc",
1820
"args": [
21+
"--trace-format",
22+
"pass-through",
1923
"config",
2024
"--as-group",
2125
"set"
@@ -27,6 +31,8 @@
2731
"test": {
2832
"executable": "dsc",
2933
"args": [
34+
"--trace-format",
35+
"pass-through",
3036
"config",
3137
"--as-group",
3238
"test"
@@ -46,6 +52,8 @@
4652
"validate": {
4753
"executable": "dsc",
4854
"args": [
55+
"--trace-format",
56+
"pass-through",
4957
"config",
5058
"validate"
5159
],

dsc/include.dsc.resource.json

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"get": {
88
"executable": "dsc",
99
"args": [
10+
"--trace-format",
11+
"pass-through",
1012
"config",
1113
"--as-include",
1214
"--as-group",
@@ -17,6 +19,8 @@
1719
"set": {
1820
"executable": "dsc",
1921
"args": [
22+
"--trace-format",
23+
"pass-through",
2024
"config",
2125
"--as-include",
2226
"--as-group",
@@ -29,6 +33,8 @@
2933
"test": {
3034
"executable": "dsc",
3135
"args": [
36+
"--trace-format",
37+
"pass-through",
3238
"config",
3339
"--as-include",
3440
"--as-group",
@@ -48,6 +54,8 @@
4854
"validate": {
4955
"executable": "dsc",
5056
"args": [
57+
"--trace-format",
58+
"pass-through",
5159
"config",
5260
"--as-include",
5361
"validate"

dsc/parallel.dsc.resource.json

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"get": {
88
"executable": "dsc",
99
"args": [
10+
"--trace-format",
11+
"pass-through",
1012
"config",
1113
"--parallel",
1214
"--as-group",
@@ -17,6 +19,8 @@
1719
"set": {
1820
"executable": "dsc",
1921
"args": [
22+
"--trace-format",
23+
"pass-through",
2024
"config",
2125
"--parallel",
2226
"--as-group",
@@ -29,6 +33,8 @@
2933
"test": {
3034
"executable": "dsc",
3135
"args": [
36+
"--trace-format",
37+
"pass-through",
3238
"config",
3339
"--parallel",
3440
"--as-group",
@@ -49,6 +55,8 @@
4955
"validate": {
5056
"executable": "dsc",
5157
"args": [
58+
"--trace-format",
59+
"pass-through",
5260
"config",
5361
"validate"
5462
],

dsc/src/args.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub enum TraceFormat {
1616
Default,
1717
Plaintext,
1818
Json,
19+
#[clap(hide = true)]
20+
PassThrough,
1921
}
2022

2123
#[derive(Debug, Clone, PartialEq, Eq, ValueEnum)]

dsc/src/tablewriter.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crossterm::terminal::{size};
1+
use crossterm::terminal::size;
22

33
pub struct Table {
44
header: Vec<String>,
@@ -8,13 +8,13 @@ pub struct Table {
88

99
impl Table {
1010
/// Create a new table.
11-
///
11+
///
1212
/// # Arguments
13-
///
13+
///
1414
/// * `header` - The header row
15-
///
15+
///
1616
/// # Returns
17-
///
17+
///
1818
/// * `Table` - The new table
1919
#[must_use]
2020
pub fn new(header: &[&str]) -> Table {
@@ -31,9 +31,9 @@ impl Table {
3131
}
3232

3333
/// Add a row to the table.
34-
///
34+
///
3535
/// # Arguments
36-
///
36+
///
3737
/// * `row` - The row to add
3838
pub fn add_row(&mut self, row: Vec<String>) {
3939
for (i, column) in row.iter().enumerate() {

dsc/src/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,15 @@ pub fn enable_tracing(trace_level: &Option<TraceLevel>, trace_format: &TraceForm
323323
.with_line_number(with_source)
324324
.boxed()
325325
},
326-
TraceFormat::Json => {
326+
TraceFormat::Json | TraceFormat::PassThrough => {
327327
layer
328328
.with_ansi(false)
329329
.with_level(true)
330330
.with_target(with_source)
331331
.with_line_number(with_source)
332332
.json()
333333
.boxed()
334-
}
334+
},
335335
};
336336

337337
let subscriber = tracing_subscriber::Registry::default().with(fmt).with(filter).with(indicatif_layer);

dsc_lib/src/dscresources/command_resource.rs

+95-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
use jsonschema::JSONSchema;
5+
use serde::Deserialize;
56
use serde_json::Value;
67
use std::{collections::HashMap, env, process::Stdio};
78
use crate::configure::{config_doc::ExecutionKind, config_result::{ResourceGetResult, ResourceTestResult}};
@@ -815,26 +816,114 @@ pub fn log_stderr_line<'a>(process_id: &u32, trace_line: &'a str) -> &'a str
815816
{
816817
if !trace_line.is_empty()
817818
{
818-
if let Result::Ok(json_obj) = serde_json::from_str::<Value>(trace_line) {
819+
if let Ok(trace_object) = serde_json::from_str::<Trace>(trace_line) {
820+
let mut include_target = trace_object.level == TraceLevel::Debug || trace_object.level == TraceLevel::Trace;
821+
let target = if let Some(t) = trace_object.target.as_deref() { t } else {
822+
include_target = false;
823+
""
824+
};
825+
let line_number = if let Some(l) = trace_object.line_number { l } else {
826+
include_target = false;
827+
0
828+
};
829+
match trace_object.level {
830+
TraceLevel::Error => {
831+
if include_target {
832+
error!("Process {process_id}: {target}: {line_number}: {}", trace_object.fields.message);
833+
}
834+
else {
835+
error!("Process {process_id}: {}", trace_object.fields.message);
836+
}
837+
},
838+
TraceLevel::Warning => {
839+
if include_target {
840+
warn!("Process {process_id}: {target}: {line_number}: {}", trace_object.fields.message);
841+
}
842+
else {
843+
warn!("Process {process_id}: {}", trace_object.fields.message);
844+
}
845+
},
846+
TraceLevel::Info => {
847+
if include_target {
848+
info!("Process {process_id}: {target}: {line_number}: {}", trace_object.fields.message);
849+
}
850+
else {
851+
info!("Process {process_id}: {}", trace_object.fields.message);
852+
}
853+
},
854+
TraceLevel::Debug => {
855+
if include_target {
856+
debug!("Process {process_id}: {target}: {line_number}: {}", trace_object.fields.message);
857+
}
858+
else {
859+
debug!("Process {process_id}: {}", trace_object.fields.message);
860+
}
861+
},
862+
TraceLevel::Trace => {
863+
if include_target {
864+
trace!("Process {process_id}: {target}: {line_number}: {}", trace_object.fields.message);
865+
}
866+
else {
867+
trace!("Process {process_id}: {}", trace_object.fields.message);
868+
}
869+
},
870+
}
871+
}
872+
else if let Ok(json_obj) = serde_json::from_str::<Value>(trace_line) {
819873
if let Some(msg) = json_obj.get("Error") {
820-
error!("Process id {process_id} : {}", msg.as_str().unwrap_or_default());
874+
error!("Process {process_id}: {}", msg.as_str().unwrap_or_default());
821875
} else if let Some(msg) = json_obj.get("Warning") {
822-
warn!("Process id {process_id} : {}", msg.as_str().unwrap_or_default());
876+
warn!("Process {process_id}: {}", msg.as_str().unwrap_or_default());
823877
} else if let Some(msg) = json_obj.get("Info") {
824-
info!("Process id {process_id} : {}", msg.as_str().unwrap_or_default());
878+
info!("Process {process_id}: {}", msg.as_str().unwrap_or_default());
825879
} else if let Some(msg) = json_obj.get("Debug") {
826-
debug!("Process id {process_id} : {}", msg.as_str().unwrap_or_default());
880+
debug!("Process {process_id}: {}", msg.as_str().unwrap_or_default());
827881
} else if let Some(msg) = json_obj.get("Trace") {
828-
trace!("Process id {process_id} : {}", msg.as_str().unwrap_or_default());
882+
trace!("Process {process_id}: {}", msg.as_str().unwrap_or_default());
829883
} else {
830884
// the line is a valid json, but not one of standard trace lines - return it as filtered stderr_line
885+
trace!("Process {process_id}: {trace_line}");
831886
return trace_line;
832887
};
833888
} else {
834889
// the line is not a valid json - return it as filtered stderr_line
890+
trace!("Process {process_id}: {}", trace_line);
835891
return trace_line;
836892
}
837893
};
838894

839895
""
840896
}
897+
898+
#[derive(PartialEq, Eq, Deserialize)]
899+
enum TraceLevel {
900+
#[serde(rename = "ERROR")]
901+
Error,
902+
#[serde(rename = "WARN")]
903+
Warning,
904+
#[serde(rename = "INFO")]
905+
Info,
906+
#[serde(rename = "DEBUG")]
907+
Debug,
908+
#[serde(rename = "TRACE")]
909+
Trace,
910+
}
911+
912+
#[derive(Deserialize)]
913+
struct Fields {
914+
message: String,
915+
}
916+
917+
#[derive(Deserialize)]
918+
struct Trace {
919+
#[serde(rename = "timestamp")]
920+
_timestamp: String,
921+
level: TraceLevel,
922+
fields: Fields,
923+
target: Option<String>,
924+
line_number: Option<u32>,
925+
#[serde(rename = "span")]
926+
_span: Option<HashMap<String, Value>>,
927+
#[serde(rename = "spans")]
928+
_spans: Option<Vec<HashMap<String, Value>>>,
929+
}

runcommandonset/RunCommandOnSet.dsc.resource.json

+4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
"get": {
77
"executable": "runcommandonset",
88
"args": [
9+
"--trace-format",
10+
"json",
911
"get"
1012
],
1113
"input": "stdin"
1214
},
1315
"set": {
1416
"executable": "runcommandonset",
1517
"args": [
18+
"--trace-format",
19+
"json",
1620
"set"
1721
],
1822
"input": "stdin",

0 commit comments

Comments
 (0)