Skip to content

Add machine-readable JSON execution reports and execution metrics #73

Closed

Description

@ejboy

Purpose

Provide a machine-readable JSON execution report so agents, CI jobs, and other callers can determine execution outcome, inspect failures, and assess work performed without parsing console logs.

Report interface

  • Add an opt-in CLI option to write a report to a specified file. Final option naming is to be decided during implementation.
  • Expose equivalent report data to embedded Java callers, reusing existing execution statistics where possible.
  • Include a schema version, Scriptella version, execution identifier, outcome (success, failed, or cancelled), UTC start/end timestamps, and elapsed duration measured with a monotonic clock.
  • Produce reports for success, handled failures, and cooperative cancellation, including validation/setup failures where feasible. A hard process termination cannot guarantee a report.
  • Keep reports separate from console output. Preserve existing execution exit statuses; report-writing failure must be visible and must not mask the original execution error. Define the exit behavior when execution succeeds but the requested report cannot be written.
  • Publish the report atomically where supported so consumers do not mistake a partially written file for a completed report.

Metrics

Extend existing statistics with lightweight counters collected during normal execution. Include totals and, where meaningful, aggregates per ETL element/location and connection ID:

  • Successful and failed element execution counts.
  • Executed statement counts.
  • Query rows emitted to nested ETL elements (not an estimate of rows scanned by the source).
  • Affected-row counts reported by drivers, including batches flushed during finalization.
  • Batch execution counts and submitted batch entries where supported.
  • Element elapsed working time, with documented inclusive/exclusive semantics; nested durations must not be summed as total wall time.
  • Query-row and statement throughput derived from clearly defined counters and durations.
  • Observed warning counts, without retaining unbounded warning details.
  • Connection open/close counts and elapsed connection-initialization time where observable, to help identify repeated connection setup costs.

Define each metric precisely. Use null or an explicit availability indicator for unsupported/unknown measurements rather than reporting a misleading zero. JDBC unknown batch update counts must remain distinguishable from known affected-row counts. Report partial counts on failure and cancellation, and indicate completeness. Affected rows describe driver-reported work, not guaranteed committed rows; make transaction outcome explicit where known.

Error information

  • Provide a bounded structured error with category, ETL location, exception type, sanitized message, and SQLState/vendor error code where available.
  • Distinguish terminal failures from element failures handled by ETL error-handling rules.
  • Exclude credentials, connection URLs, SQL/script text, bound values, and input records by default. Driver messages may contain sensitive values and require sanitization; omit unsafe details where reliable sanitization is not possible.
  • Stack traces are outside the default report.

Acceptance criteria

  • Document the JSON schema, field units, metric semantics, availability, and compatibility policy.
  • Include examples for successful execution, partial failure, and cancellation.
  • Verify counter accuracy for nested queries, repeated scripts, batching/final partial batches, rollback, and handled errors.
  • Verify report behavior for setup errors, report-write failures, and unsupported driver statistics.
  • Keep memory bounded by ETL structure/connections, not row count; avoid per-row events and expensive profiling or resource sampling in this MVP.

Related: #18 (elapsed time on failure). This reporting feature is independent of the JSON data driver in #72.

Activity

  1. added this to the 1.7.0 milestone on Oct 21, 2026
  2. ejboy commented on Oct 21, 2026

    @ejboy
    MemberAuthor

    Quick implementation analysis: inexpensive metrics

    Source inspection of the current checkout suggests the following priority. These are implementation estimates, not measured overhead results; no code changes or tests were made.

    1. Reuse existing statistics first

    • Per-element successful/failed execution counts, statement counts, and working time: already collected by ExecutionStatisticsBuilder and exposed through ExecutionStatistics.ElementInfo. Working time excludes nested element execution time; retain and document that meaning. Failed-element counts are not necessarily independent errors: one failure can propagate through nested elements.
    • Run start/end timestamps: already exist. Add a monotonic run-duration measurement, and ensure failure/cancellation finalization populates it (Show execution time even if there was an error! #18).
    • Driver-reported affected rows: already aggregated by JdbcConnection.addUpdateCount, ConnectionManager.getUpdateCount, and ExecutionStatistics.getUpdateCount, including successful final batch flushes. This currently sums positive counts; it is not a committed-row count or a complete result for drivers returning unknown counts.
    • Throughput: derive from counters and documented durations at report generation, without extra runtime collection. Existing element throughput is statements per second of element working time; distinguish that from run-wide throughput using wall duration.

    2. Cheap additions worth including in the MVP

    • Query rows emitted, per query location: QueryExecutor.QueryCtxDecorator.processRow() is a common hook across drivers and already increments a row number. Add persistent long counters there (the current row number is an int local to one invocation). Count before nested execution so a row whose child fails still counts as emitted. Optionally count rows whose child processing completed separately. Preserve partial counts on exceptions; aggregating only after successful executeQuery() would lose them. Summing nested-query rows counts emissions at each level, not unique input records.
    • Connection initialization attempts/successes/failures and elapsed initialization time: wrap the two driver.connect() sites in ConnectionManager.getConnection() and newConnection(). Use monotonic timing in a finally block and retain aggregates before manager cleanup. This covers normal, lazy, and new-transaction connections without per-row timers.
    • Connection close attempts/successes/failures: collect at the existing manager close loop. Report these as Scriptella driver-connection operations; a driver may internally own more than one resource.
    • Commit/rollback call outcomes and timings: inexpensive at the JDBC operation boundaries, including implicit commits initiated by SqlExecutor. Distinguish unsupported/no-op operations from actual JDBC calls. These describe observed calls, not a global transaction guarantee. This is especially useful when a failed execution has already committed earlier work.

    3. Useful, but need explicit bookkeeping

    • JDBC batch attempts, submitted entries, successes/failures, and total batch-call duration: instrument StatementWrapper batch execution, retaining batch size before its finally block resets it. This must include flushes caused by batch thresholds, queries, final commit, and cache lifecycle.
    • Known affected rows versus unknown outcomes: StatementWrapper.executeBatch() currently sums positive results and discards JDBC SUCCESS_NO_INFO / EXECUTE_FAILED. Preserve separate counters and inspect BatchUpdateException.getUpdateCounts() for partial results. Do not infer exact affected rows from submitted entries. Per-connection aggregation is easier than correct per-element attribution when cached batches flush later; defer per-element batch attribution if necessary.
    • SQL warnings: SqlExecutor.logExecutedStatement() already obtains connection warnings, so no extra JDBC polling is necessary. However, traversal/clearing currently depends on the logging path. Count independently of log level, define warning-chain clearing semantics, and avoid counting the same retained warning repeatedly. Call the metric observed JDBC warnings, not all application warnings.
    • Availability indicators: the current connection SPI documents statement-count zero as either zero work or unsupported; affected-row reporting has similar ambiguity. Reliable null/unknown reporting needs an optional capability/statistics extension or explicit built-in-driver metadata. Do not guess availability from a numeric zero or break third-party drivers by adding required SPI methods.

    Suggested first implementation

    Start with existing statistics, monotonic run duration, query-row emissions, connection initialization/close metrics, and observed JDBC transaction operations. Add batch outcome counters next; include warning counts only with correct lifecycle handling. Keep aggregates bounded by ETL locations/connections, using primitive counters and timers around operations rather than per-row event objects.

    Defer CPU/heap/GC attribution, process-wide log interception, byte counts across all drivers, database/server metrics, and committed-row estimates. These require broader instrumentation or would be misleading for embedded execution. Per-connection totals should survive cleanup, and unavailable statistics should remain explicitly unknown.

  3. ejboy commented on Nov 3, 2026

    @ejboy
    MemberAuthor

    For 1.7.0, the implemented JSON execution report MVP in 05fd6ad is accepted: success, failure and cancellation reports with the documented available metrics. Batch, transaction, throughput, warning and other advanced metrics in this issue are deferred and are not implemented in 1.7.0. Keep this issue open for the remaining work, outside the 1.7.0 milestone; no later release is committed.

  4. removed this from the 1.7.0 milestone on Nov 3, 2026
  5. ejboy commented on Nov 3, 2026

    @ejboy
    MemberAuthor

    Closing as completed for the accepted 1.7.0 JSON execution-report MVP, which has been released and validated. The report covers success, failure and cooperative cancellation, the documented available metrics, partial results and sanitized errors.

    The original issue also described potential advanced metrics. Batch outcomes and timings, transaction telemetry, warning counts, provider-specific metrics, derived throughput and separate handled-error counters are not implemented in 1.7.0. They are deferred ideas, not commitments for a future release; if pursued, they should be scoped and tracked separately. The maintainer's private execution-report notes preserve the design context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions