Skip to content

feat: add task result retrieval for workflow executions#72

Merged
discostu105 merged 6 commits intodynatrace-oss:mainfrom
davidHaunschmied:feat/wfe-task-result
Mar 18, 2026
Merged

feat: add task result retrieval for workflow executions#72
discostu105 merged 6 commits intodynatrace-oss:mainfrom
davidHaunschmied:feat/wfe-task-result

Conversation

@davidHaunschmied
Copy link
Contributor

@davidHaunschmied davidHaunschmied commented Mar 7, 2026

Closes #71

What this PR does

Adds support for reading the return value of individual task executions via the GET /platform/automation/v1/executions/{id}/tasks/{taskName}/result endpoint.

Changes

pkg/resources/workflow/execution.go

  • Add GetTaskResult(executionID, taskName string) (any, error) — thin wrapper around the task result API endpoint, consistent with the existing GetTaskLog() pattern.

cmd/get_wfe_task_result.go — new get sub-resource

dtctl get wfe-task-result <execution-id> --task <task-name>
dtctl get workflow-execution-task-result <execution-id> --task <task-name>

Requires --task. Respects -o json/yaml/table via the standard Printer.

Per feedback in #71, this lives under get (not a separate results verb) to stay consistent with existing patterns like dtctl get wfe and dtctl logs wfe.

cmd/exec_workflows.go — new --show-results flag

dtctl exec workflow <id> --wait --show-results

After the workflow completes, lists all tasks and prints each task's return value. Only valid with --wait.

docs/QUICK_START.md

  • Added --show-results example under Execute Workflows
  • Added "View Task Results" section with get wfe-task-result examples

pkg/resources/workflow/execution_test.go

  • Unit tests for GetTaskResult (success, 404, 500) using the repo's newExecTestHandler pattern

Example output

$ dtctl get wfe-task-result 8ffa5b11 --task rca_analysis -o json
{
  "results": [ ... ]
}
$ dtctl exec workflow eeca623c --wait --show-results

Workflow execution started
Execution ID: 8ffa5b11-...
State: RUNNING

Waiting for execution to complete...

Execution completed
Final State: SUCCESS
Duration: 7s

Task Results:

--- fetch_active_events [SUCCESS] ---
(DQL task — no structured return value)

--- rca_analysis [SUCCESS] ---
{
  "results": [
    {
      "serviceId": "SERVICE-BE4453718DDF0511",
      "eventStart": "2026-03-07T19:35:00.000Z"
    }
  ]
}

@dynatrace-cla-bot
Copy link

dynatrace-cla-bot commented Mar 7, 2026

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 10.20408% with 44 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@ed69c9c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
cmd/exec_workflows.go 5.55% 17 Missing ⚠️
cmd/results.go 19.04% 16 Missing and 1 partial ⚠️
pkg/resources/workflow/execution.go 0.00% 10 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #72   +/-   ##
=======================================
  Coverage        ?   38.64%           
=======================================
  Files           ?      162           
  Lines           ?    16345           
  Branches        ?        0           
=======================================
  Hits            ?     6317           
  Misses          ?     9606           
  Partials        ?      422           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

davidHaunschmied and others added 4 commits March 17, 2026 07:32
Add GET /platform/automation/v1/executions/{id}/tasks/{taskName}/result
support to surface the return value of individual tasks (e.g. the object
returned by a JavaScript task's default export function).

Changes:
- pkg/resources/workflow/execution.go: add GetTaskResult() method
- cmd/logs.go: add --result flag to 'logs wfe --task <name> --result'
- cmd/exec_workflows.go: add --show-results flag to 'exec workflow --wait'

Usage:
  # Fetch the return value of a specific task
  dtctl logs wfe <execution-id> --task <task-name> --result

  # Execute workflow and show all task return values on completion
  dtctl exec workflow <id> --wait --show-results

Fixes: without this, the only way to retrieve JavaScript task output was
to hit the automation REST API directly with curl/Bearer token.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove --result flag from 'logs wfe' (logs = stdout/stderr; results
  = structured return values — semantically distinct)
- Add new 'dtctl results workflow-execution' command (alias: wfe) with
  required --task flag and -o json/yaml output support
- Add --show-results flag to 'exec workflow --wait' for convenience
- Update QUICK_START.md with both new commands

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Per feedback in dynatrace-oss#71, move task result retrieval from the 'results' top-level
command group to 'get wfe-task-result', consistent with existing patterns
where 'get' is the verb for reading resources.

Before: dtctl results wfe <execution-id> --task <task-name>
After:  dtctl get wfe-task-result <execution-id> --task <task-name>
        dtctl get workflow-execution-task-result <execution-id> --task <task-name>

This mirrors the existing 'dtctl logs wfe' / 'dtctl get wfe' relationship
and maps directly to the API endpoint (.../result), leaving no ambiguity
between task results and task metadata.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Trim verbose godoc and Long description to match repo conventions
- Fix QUICK_START.md: update commands from 'results wfe' to 'get wfe-task-result'
- Add unit tests for GetTaskResult and ListTasks (table-driven, httptest)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidHaunschmied davidHaunschmied marked this pull request as ready for review March 17, 2026 07:53
@davidHaunschmied
Copy link
Contributor Author

Updated PR based on your feedback @discostu105 . Please have another look.

- Fix test indentation (was flush-left, now properly tabbed)
- Add agent envelope support to get wfe-task-result (enrichAgent + suggestions)
- Validate --show-results requires --wait (PreRunE check)
- Eliminate N+1 API calls in --show-results: use task.Result from
  ListTasks instead of calling GetTaskResult per task
- Move examples from Long to Example field in Cobra commands
- Fix help text grouping: place wfe-task-result near workflow-executions
- In agent mode (-A), exec workflow now produces a single structured
  JSON envelope instead of mixing fmt.Printf with printer output
- Extract helper functions (execWorkflowWait, execWorkflowShowResults,
  execWorkflowAgent) for clarity and to separate human/agent code paths
- Add enrichAgent call with verb=exec, resource=workflow, plus
  suggestions and duration context
- Add TestListTasks_WithResults to verify Result field deserialization
  (used by --show-results to avoid N+1 API calls)
@discostu105 discostu105 merged commit 9886f14 into dynatrace-oss:main Mar 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: expose task result retrieval for workflow executions

4 participants