-
Notifications
You must be signed in to change notification settings - Fork 32
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
Fix progress display when using JSON, add None option; exhance progress schema #644
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 8 out of 18 changed files in this pull request and generated no comments.
Files not reviewed (10)
- dsc/tests/dsc_args.tests.ps1: Language not supported
- dsc/tests/dsc_config_get.tests.ps1: Language not supported
- dsc/tests/dsc_resource_list.tests.ps1: Language not supported
- dsc_lib/src/discovery/discovery_trait.rs: Evaluated as low risk
- dsc/src/args.rs: Evaluated as low risk
- dsc/src/subcommand.rs: Evaluated as low risk
- dsc_lib/src/discovery/mod.rs: Evaluated as low risk
- dsc_lib/src/util.rs: Evaluated as low risk
- dsc/src/main.rs: Evaluated as low risk
- dsc_lib/locales/en-us.toml: Evaluated as low risk
Comments suppressed due to low confidence (1)
dsc_lib/src/configure/mod.rs:250
- The
set_resource
method is used to set the resource details, but it is not always followed by anincrement
call. Ensure that the progress is incremented consistently after setting the resource details.
progress.set_resource(&resource.name, &resource.resource_type, None);
65d8629
to
93e52da
Compare
|
Looks like the |
Rather than try and muddle through figuring out where the issue is in the code, I will present a test case: --- $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
metadata:
winget:
processor: dscv3
resources:
- name: RegVal
type: Microsoft.Windows/Registry
properties:
keyPath: HKEY_CURRENT_USER\Software\Microsoft\WinGet
valueName: TestVal
valueData:
String: Value!
- name: RegVal2
type: Microsoft.Windows/Registry
properties:
keyPath: HKEY_CURRENT_USER\Software\Microsoft\WinGet
valueName: TestVal2
valueData:
String: Value2! --- {"id":"9d7ee3db-7cda-4726-b5a8-22cf7f5179f2","activity":"Searching for resources","percentComplete":0}
{"id":"9d7ee3db-7cda-4726-b5a8-22cf7f5179f2","activity":"Searching for resources","percentComplete":100}
{"id":"80e488c0-9ca0-49ae-a2d8-47e6c9c6dc5b","activity":"Test 'RegVal'","percentComplete":0}
{"id":"80e488c0-9ca0-49ae-a2d8-47e6c9c6dc5b","activity":"Test 'RegVal'","percentComplete":50,"resourceName":"RegVal","resourceType":"Microsoft.Windows/Registry","result":{"keyPath":"HKEY_CURRENT_USER\\Software\\Microsoft\\WinGet","valueName":"TestVal","valueData":{"String":"Value!"}}}
{"id":"80e488c0-9ca0-49ae-a2d8-47e6c9c6dc5b","activity":"Test 'RegVal2'","percentComplete":50,"resourceName":"RegVal","resourceType":"Microsoft.Windows/Registry","result":{"keyPath":"HKEY_CURRENT_USER\\Software\\Microsoft\\WinGet","valueName":"TestVal","valueData":{"String":"Value!"}}}
{"id":"80e488c0-9ca0-49ae-a2d8-47e6c9c6dc5b","activity":"Test 'RegVal2'","percentComplete":100,"resourceName":"RegVal2","resourceType":"Microsoft.Windows/Registry","result":{"keyPath":"HKEY_CURRENT_USER\\Software\\Microsoft\\WinGet","valueName":"TestVal2","valueData":{"String":"Value2!"}}} The first progress report for {
"id": "80e488c0-9ca0-49ae-a2d8-47e6c9c6dc5b",
"activity": "Test 'RegVal2'",
"percentComplete": 50,
"resourceName": "RegVal", // Resource name should be RegVal2
"resourceType": "Microsoft.Windows/Registry", // Ensure that this is also being update as this case was two of the same resources
"result": { // We shouldn't have a result yet as this is the "starting" progress line
"keyPath": "HKEY_CURRENT_USER\\Software\\Microsoft\\WinGet",
"valueName": "TestVal",
"valueData": { "String": "Value!" }
}
} |
Thanks! Looks like where it's setting the resource and result isn't not happening correctly per resource, will check. |
The results in the progress lines do not have the full fidelity information that the overall result has. For --- {
"id": "a85d6c05-961b-4003-9dad-da6158782eaf",
"activity": "Test 'RegVal'",
"percentComplete": 50,
"resourceName": "RegVal",
"resourceType": "Microsoft.Windows/Registry",
"result": { // This object
"keyPath": "HKEY_CURRENT_USER\\Software\\Microsoft\\WinGet",
"valueName": "TestVal",
"valueData": { "String": "Value!" }
}
} --- {
"metadata": { "Microsoft.DSC": { "duration": "PT1.1595442S" } },
"name": "RegVal",
"type": "Microsoft.Windows/Registry",
"result": { // Should equal this object
"desiredState": {
"keyPath": "HKEY_CURRENT_USER\\Software\\Microsoft\\WinGet",
"valueName": "TestVal",
"valueData": { "String": "Value!" }
},
"actualState": {
"keyPath": "HKEY_CURRENT_USER\\Software\\Microsoft\\WinGet",
"valueName": "TestVal",
"valueData": { "String": "Value!" }
},
"inDesiredState": true,
"differingProperties": []
}
} |
The current |
@JohnMcPMS fetch my changes and try again, the order of setting the progress content and writing it was incorrect and now fixed. Here's what the json looks like now: {"id":"ab122824-87b1-4f67-b7fb-479172dba0ce","activity":"Searching for resources","percentComplete":0}
{"id":"ab122824-87b1-4f67-b7fb-479172dba0ce","activity":"Searching for resources","percentComplete":100}
{"id":"2a714b94-d45a-42fb-8f36-a63db27eecb4","activity":"Get 'Echo 1'","percentComplete":0,"resourceName":"Echo 1","resourceType":"Microsoft.DSC.Debug/Echo"}
{"id":"2a714b94-d45a-42fb-8f36-a63db27eecb4","activity":"Get 'Echo 1'","percentComplete":50,"resourceName":"Echo 1","resourceType":"Microsoft.DSC.Debug/Echo","result":{"actualState":{"output":"hello"}}}
{"id":"2a714b94-d45a-42fb-8f36-a63db27eecb4","activity":"Get 'Echo 2'","percentComplete":50,"resourceName":"Echo 2","resourceType":"Microsoft.DSC.Debug/Echo"}
{"id":"2a714b94-d45a-42fb-8f36-a63db27eecb4","activity":"Get 'Echo 2'","percentComplete":100,"resourceName":"Echo 2","resourceType":"Microsoft.DSC.Debug/Echo","result":{"actualState":{"output":"world"}}} with this result metadata:
Microsoft.DSC:
version: 3.0.0
operation: Get
executionType: Actual
startDatetime: 2025-02-18T20:38:15.928505-08:00
endDatetime: 2025-02-18T20:38:15.979178-08:00
duration: PT0.050673S
securityContext: Restricted
results:
- metadata:
Microsoft.DSC:
duration: PT0.023614S
name: Echo 1
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: hello
- metadata:
Microsoft.DSC:
duration: PT0.005786S
name: Echo 2
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: world
messages: []
hadErrors: false |
I'm seeing both changes. 👍 This is somewhat tangential, but the error handling strategy seems to be difficult to work against. I changed my registry test to have the second instance target HKLM and ran from an unelevated console. It fails as expected, but the results are not as easy to consume programmatically. There is no output, only error:
In a simple example I can assume serial execution and place the error messages with the resource that was last reported as starting (via a progress line with a new identity no result). However, I just have some strings and no easy way to extract a specific error result. My thoughts:
{
"id":"7eccc602-0df7-4d38-8ac2-bdf5e9b2828e", // Required for full instance identity
"resourceName": "RegVal2",
"resourceType": "Microsoft.Windows/Registry",
"timestamp": "2025-02-19T17:22:42.922877Z",
"messageLevel": "ERROR",
"message": "Error: Command: Resource 'registry' [exit code 3] manifest description: Registry error"
}
{
"id": "7eccc602-0df7-4d38-8ac2-bdf5e9b2828e",
"activity": "Set 'RegVal2'",
"percentComplete": 100,
"resourceName": "RegVal2",
"resourceType": "Microsoft.Windows/Registry",
"result": {
"beforeState": {
"keyPath": "HKEY_CURRENT_USER\\Software\\Microsoft\\WinGet",
"valueName": "TestVal",
"valueData": { "String": "Value!" }
},
"errorCode": 3,
"errorDescription": "Registry error"
}
}
|
Co-authored-by: Tess Gauthier <[email protected]>
@JohnMcPMS for traces, you need to specify the trace format: dsc --progress-format json --trace-format json config get -f ./dsc/examples/osinfo_parameters.dsc.yaml |
@tgauth the |
Filed #654 to help with discoverability. Would you consider adding the identifying fields to traces as part of this PR, or should I open an issue to request it? Are you planning on adding a closing progress event for a resource error (my thought 2), or should I roll that into a larger issue along with thoughts 3 and 4? |
Any additions to traces should be a separate new issue. Do you need a closing progress event or can you just key off |
I don't need a closing progress event for the entire configuration, but I was hoping that there would be one for the currently running resource instance when an error occurs. But that might roll into the larger error handling issue that it looks like I will have to file. |
Ok, I see so to know a resource is complete when it errors and not just success. Let me think about that one. |
…failed property to progress
@JohnMcPMS due to the fact that tracing happens async and there can be multiple error traces written, there isn't a way to get the error message from the resource to put into the progress record. Instead, I added a I also removed the calculation of percent complete since that seems to be the role of the presentation layer and instead progress record includes the |
This is workable. I would prefer to also have some amount of detail on the failure be included in the progress report, but I can live without it for now. For example, I suspect you have the exit code (or how would know it failed) and could include the resource defined message (a caller can also find that with sufficient effort, but it is probably at your fingertips). In my example, the trace message with that data actually comes after the progress containing the |
@JohnMcPMS yes, do have the exit code so I could change it for now from |
@JohnMcPMS so latest change has a |
PR Summary
Based on discussion with WinGet team, they needed more information in the progress JSON. Changes:
ProgressBar
struct that is used to provide progress instead of calling the crate APIs directlyNone
option to--progress-format
json
option is used, no progress is written even when interactiveProgress
struct to have a uniqueid
which is only useful for JSON representation, but since nested progress is allowed, enables tool consuming the progress to know which one is being updatedresourceName
,resourceType
, andresult
optional members toProgress
so consuming tool can present it to userfailed
member toProgress
which is mutually exclusive toresult
if the resource failedExample:
$config_yaml
contains: