diff --git a/.github/actions/run_event_validation/action.yml b/.github/actions/run_event_validation/action.yml index c969b20d..5b2d028a 100644 --- a/.github/actions/run_event_validation/action.yml +++ b/.github/actions/run_event_validation/action.yml @@ -26,6 +26,10 @@ inputs: component: description: "Component name to use" required: true + run-status-file: + description: "status.json of the producer run ([{scenario, state, job_id}]); scenarios whose job isn't DONE fail" + default: "" + required: false outputs: @@ -70,4 +74,6 @@ runs: --component="${{ inputs.component }}" \ --producer_dir=${{ inputs.producer-dir }} \ --openlineage_version=${{ inputs.release_tags }} \ - --component_version=${{ inputs.component_release }} \ No newline at end of file + --component_version=${{ inputs.component_release }} \ + ${{ inputs.ol_release && format('--openlineage_release={0}', inputs.ol_release) || '' }} \ + ${{ inputs.run-status-file && format('--run_status={0}', inputs.run-status-file) || '' }} \ No newline at end of file diff --git a/.github/workflows/check_scenarios.yml b/.github/workflows/check_scenarios.yml index 3a42bba2..48361c3a 100644 --- a/.github/workflows/check_scenarios.yml +++ b/.github/workflows/check_scenarios.yml @@ -59,6 +59,7 @@ jobs: name: scenarios-report path: reports/scenarios-report.json retention-days: 1 + if-no-files-found: error - name: fail for failures in report id: fail-for-failures diff --git a/.github/workflows/consumer_dataplex.yml b/.github/workflows/consumer_dataplex.yml index 551a7604..e401e2ba 100644 --- a/.github/workflows/consumer_dataplex.yml +++ b/.github/workflows/consumer_dataplex.yml @@ -50,4 +50,5 @@ jobs: name: dataplex-report path: dataplex-report.json retention-days: 1 + if-no-files-found: error diff --git a/.github/workflows/producer_dbt.yml b/.github/workflows/producer_dbt.yml index 724b813c..6d32d562 100644 --- a/.github/workflows/producer_dbt.yml +++ b/.github/workflows/producer_dbt.yml @@ -89,14 +89,25 @@ jobs: set -e IFS=';' read -ra scenarios <<< "${{ steps.init.outputs.scenarios }}" + # one entry per scenario, [{scenario, state, job_id}]; a failed run.sh fails its scenario in validation + status_file="${{ steps.set-producer-output.outputs.event_dir }}/status.json" + mkdir -p "${{ steps.set-producer-output.outputs.event_dir }}" + echo '[]' > "$status_file" + for scenario in "${scenarios[@]}" do echo "Running dbt scenario: $scenario" mkdir -p "${{ steps.set-producer-output.outputs.event_dir }}/$scenario" - bash producer/dbt/scenarios/$scenario/test/run.sh "${{ steps.set-producer-output.outputs.event_dir }}/$scenario" - - echo "Finished running scenario: $scenario" + if bash producer/dbt/scenarios/$scenario/test/run.sh "${{ steps.set-producer-output.outputs.event_dir }}/$scenario"; then + state=DONE + echo "Finished running scenario: $scenario" + else + state=FAILED + echo "::warning::dbt scenario $scenario failed" + fi + jq --arg scenario "$scenario" --arg state "$state" '. + [{scenario: $scenario, state: $state, job_id: ""}]' \ + "$status_file" > "$status_file.tmp" && mv "$status_file.tmp" "$status_file" done echo "Finished running all scenarios" @@ -119,6 +130,7 @@ jobs: component_release: ${{ inputs.dbt_release }} event-directory: ${{ steps.set-producer-output.outputs.event_dir }} target-path: 'dbt-${{inputs.dbt_release}}-${{inputs.ol_release}}-report.json' + run-status-file: ${{ steps.set-producer-output.outputs.event_dir }}/status.json - uses: actions/upload-artifact@v4 if: ${{ steps.init.outputs.scenarios }} @@ -126,3 +138,4 @@ jobs: name: dbt-${{inputs.dbt_release}}-${{inputs.ol_release}}-report path: dbt-${{inputs.dbt_release}}-${{inputs.ol_release}}-report.json retention-days: 1 + if-no-files-found: error diff --git a/.github/workflows/producer_hive_dataproc.yml b/.github/workflows/producer_hive_dataproc.yml index 54941c55..6b436f10 100644 --- a/.github/workflows/producer_hive_dataproc.yml +++ b/.github/workflows/producer_hive_dataproc.yml @@ -66,6 +66,7 @@ jobs: skip-s3: 'true' skip-gcp-lineage: 'true' skip-sql: 'true' + skip-gcs: 'true' # see GCS_TRANSPORT_JAR below - name: Upload openlineage hive integration to GCS id: upload-hive-integration @@ -76,15 +77,6 @@ jobs: gcs-path: "gs://open-lineage-e2e/jars" credentials: ${{ steps.gcp-auth.outputs.credentials_file_path }} - - name: Upload openlineage GCS transport to GCS - id: upload-gcs-transport - if: ${{ steps.init.outputs.scenarios }} - uses: ./.github/actions/upload_artifacts - with: - local-file-path: ${{ steps.get-ol-artifacts.outputs.gcs }} - gcs-path: "gs://open-lineage-e2e/jars" - credentials: ${{ steps.gcp-auth.outputs.credentials_file_path }} - - name: Upload initialization actions to GCS id: upload-initialization-actions if: ${{ steps.init.outputs.scenarios }} @@ -106,7 +98,7 @@ jobs: run: | python -m pip install --upgrade pip pip install flake8 pytest - if [ -f producer/hive_dataproc/runner/requirements.txt ]; then pip install -r producer/spark_dataproc/runner/requirements.txt; fi + if [ -f producer/hive_dataproc/runner/requirements.txt ]; then pip install -r producer/hive_dataproc/runner/requirements.txt; fi - name: Start producer @@ -119,7 +111,10 @@ jobs: region: us-west1 create-command: | metadata='' - metadata+='GCS_TRANSPORT_JAR=${{ steps.upload-gcs-transport.outputs.uploaded-file }}' + # Temporary: released transports-gcs 1.40.0-1.55.0 break Hive on Dataproc (half-relocated Woodstox stops + # HiveServer2, the bundled Conscrypt native library aborts the Tez AM). This snapshot has both fixed; go back + # to uploading the matching transport (get-ol-artifacts' gcs output) once a release has the fix (1.56.0?). + metadata+='GCS_TRANSPORT_JAR=gs://open-lineage-e2e/jars/transports-gcs-1.56.0-SNAPSHOT-conscrypt-fix.jar' metadata+=',OPENLINEAGE_HIVE_URL=${{ steps.upload-hive-integration.outputs.uploaded-file }}' properties='' @@ -158,6 +153,12 @@ jobs: properties+=',hive.openlineage.transport.type=gcs' properties+=',hive.scenario.suffix=${{steps.init.outputs.component_cluster_suffix}}-${{steps.init.outputs.openlineage_cluster_suffix}}' + # one entry per scenario, [{scenario, state, job_id}] as written by the spark runner; a failed query fails + # its scenario in validation instead of stopping the other scenarios + status_file="${{ steps.set-producer-output.outputs.event_dir }}/status.json" + mkdir -p "${{ steps.set-producer-output.outputs.event_dir }}" + echo '[]' > "$status_file" + for scenario in "${scenarios[@]}" do echo "Getting script for scenario $scenario" @@ -171,7 +172,7 @@ jobs: properties+=",hive.openlineage.transport.bucketName=open-lineage-e2e" properties+=",hive.openlineage.transport.fileNamePrefix=events/$scenario/$(date +%s%3N)/" - if ! python producer/hive_dataproc/runner/dataproc_workflow.py run-hive-query \ + if python producer/hive_dataproc/runner/dataproc_workflow.py run-hive-query \ --project-id gcp-open-lineage-testing \ --region us-west1 \ --cluster-name "hive-dataproc-producer-test-${{steps.init.outputs.component_cluster_suffix}}-${{ steps.init.outputs.openlineage_cluster_suffix }}-${{ github.run_id }}" \ @@ -180,11 +181,14 @@ jobs: --output-directory "${{ steps.set-producer-output.outputs.event_dir }}/$scenario" \ --properties "$properties" then - echo "Error: hive job failed for scenario: $scenario" - exit 1 + state=DONE + echo "Finished running hive job for scenario: $scenario" + else + state=FAILED + echo "::warning::hive job failed for scenario $scenario" fi - - echo "Finished running hive job for scenario: $scenario" + jq --arg scenario "$scenario" --arg state "$state" '. + [{scenario: $scenario, state: $state, job_id: ""}]' \ + "$status_file" > "$status_file.tmp" && mv "$status_file.tmp" "$status_file" done echo "Finished running all scenarios" @@ -198,7 +202,8 @@ jobs: ol_release: ${{ inputs.ol_release }} component_release: ${{ inputs.component_release }} event-directory: ${{ steps.set-producer-output.outputs.event_dir }} - target-path: 'hive-dataproc-${{inputs.hive_release}}-${{inputs.ol_release}}-report.json' + target-path: 'hive-dataproc-${{inputs.component_release}}-${{inputs.ol_release}}-report.json' + run-status-file: ${{ steps.set-producer-output.outputs.event_dir }}/status.json # the events PR checks re-validate when validation code changes (revalidate_stored_events.yml) - name: Update baseline events @@ -213,3 +218,4 @@ jobs: name: hive-dataproc-${{inputs.component_release}}-${{inputs.ol_release}}-report path: hive-dataproc-${{inputs.component_release}}-${{inputs.ol_release}}-report.json retention-days: 1 + if-no-files-found: error diff --git a/.github/workflows/producer_spark_dataproc.yml b/.github/workflows/producer_spark_dataproc.yml index 0a80e4d8..13434118 100644 --- a/.github/workflows/producer_spark_dataproc.yml +++ b/.github/workflows/producer_spark_dataproc.yml @@ -213,8 +213,8 @@ jobs: --credentials-file "${{ steps.gcp-auth.outputs.credentials_file_path }}" \ || echo "::warning::Some scenarios failed for OpenLineage $ol_release" - # check-spark-jobs fails the workflow for every scenario not in DONE state, so a runner crash - # that left no status.json must still be recorded + # validation fails every scenario whose job isn't in DONE state; a runner crash that left no status.json + # is recorded as RUNNER_FAILED for every scenario, which validation treats as "the pair didn't run" if [[ ! -f "/tmp/driver-logs/$ol_release/status.json" ]]; then mkdir -p "/tmp/driver-logs/$ol_release" jq -n --arg s "$scenarios" '$s | split(";") | map({scenario: ., state: "RUNNER_FAILED", job_id: ""})' \ @@ -225,8 +225,13 @@ jobs: || echo "::warning::No driver logs for OpenLineage $ol_release" done 3< /tmp/ol_scenarios + # runs for every pair whose Spark jobs ran, even when the cluster of another Spark release failed; + # a pair that didn't run produces no report, so the release check retries it (pending_runs.json) validate: - needs: run-spark-tests + needs: + - stage-openlineage-jars + - run-spark-tests + if: ${{ !cancelled() && needs.stage-openlineage-jars.result == 'success' }} runs-on: ubuntu-latest strategy: fail-fast: false @@ -243,7 +248,6 @@ jobs: scenarios=$(./scripts/get_valid_test_scenarios.sh "producer/spark_dataproc/scenarios/" ${{ matrix.spark_release }} ${{ matrix.ol_release }} ) [[ "$scenarios" == "" ]] || echo "scenarios=$scenarios" >> $GITHUB_OUTPUT echo "event_dir=/tmp/producer-$(date +%s%3N)" >> $GITHUB_OUTPUT - echo "gcs_suffix=${RUN_KEY}/${{ matrix.spark_release }}/${{ matrix.ol_release }}" >> $GITHUB_OUTPUT - name: GCP authorization if: ${{ steps.init.outputs.scenarios }} @@ -251,19 +255,50 @@ jobs: with: credentials_json: '${{ secrets.gcpKey }}' + # status.json is written by the run step for every openlineage version it ran; without it, or when the runner + # itself crashed for every scenario, the pair didn't run: an infra problem, not a result, so the job fails + # without a report (the release check retries the pair, see pending_runs.json) + # "Re-run failed jobs" reruns this job but not a run job that passed, so the pair's files can be under an earlier + # attempt: the newest attempt that has a status.json is the pair's latest run + - name: Check that the pair ran + id: ran + if: ${{ steps.init.outputs.scenarios }} + run: | + pair="spark ${{ matrix.spark_release }}, openlineage ${{ matrix.ol_release }}" + status_file=/tmp/status-${{ matrix.spark_release }}-${{ matrix.ol_release }}.json + gcs_suffix="" + for (( attempt = ${{ github.run_attempt }}; attempt >= 1; attempt-- )); do + suffix="${{ github.run_id }}-$attempt/${{ matrix.spark_release }}/${{ matrix.ol_release }}" + if gcloud storage cp "gs://${GCS_BUCKET}/logs/$suffix/status.json" "$status_file" 2> /dev/null; then + gcs_suffix="$suffix" + break + fi + done + if [[ -z "$gcs_suffix" ]]; then + echo "::error title=Pair did not run::$pair has no status.json, its Spark jobs never ran" + exit 1 + fi + [[ "$attempt" == "${{ github.run_attempt }}" ]] || echo "Using the results of run attempt $attempt" + echo "gcs_suffix=$gcs_suffix" >> "$GITHUB_OUTPUT" + if jq -e 'all(.[]; .state == "RUNNER_FAILED")' "$status_file" > /dev/null; then + echo "::error title=Pair did not run::$pair: the runner failed before running any scenario" + exit 1 + fi + echo "status_file=$status_file" >> "$GITHUB_OUTPUT" + # every scenario gets a directory, so a scenario without events fails validation instead of being skipped - name: Download events - if: ${{ steps.init.outputs.scenarios }} + if: ${{ steps.ran.outputs.status_file }} run: | IFS=';' read -ra scenarios <<< "${{ steps.init.outputs.scenarios }}" for scenario in "${scenarios[@]}"; do mkdir -p "${{ steps.init.outputs.event_dir }}/$scenario" done - gcloud storage cp -r "gs://${GCS_BUCKET}/events/${{ steps.init.outputs.gcs_suffix }}/*" "${{ steps.init.outputs.event_dir }}/" \ + gcloud storage cp -r "gs://${GCS_BUCKET}/events/${{ steps.ran.outputs.gcs_suffix }}/*" "${{ steps.init.outputs.event_dir }}/" \ || echo "::warning::No events found" - name: Validation - if: ${{ steps.init.outputs.scenarios }} + if: ${{ steps.ran.outputs.status_file }} uses: ./.github/actions/run_event_validation with: component: 'spark_dataproc' @@ -272,70 +307,41 @@ jobs: component_release: ${{ matrix.spark_release }} event-directory: ${{ steps.init.outputs.event_dir }} target-path: 'spark-dataproc-${{matrix.spark_release}}-${{matrix.ol_release}}-report.json' + run-status-file: ${{ steps.ran.outputs.status_file }} # the events PR checks re-validate when validation code changes (revalidate_stored_events.yml) - name: Update baseline events - if: ${{ inputs.update-baseline && steps.init.outputs.scenarios }} + if: ${{ inputs.update-baseline && steps.ran.outputs.status_file }} run: | baseline="gs://${GCS_BUCKET}/baseline-events/spark_dataproc/${{ matrix.spark_release }}/${{ matrix.ol_release }}" gcloud storage rsync -r --delete-unmatched-destination-objects "${{ steps.init.outputs.event_dir }}" "$baseline" - gcloud storage cp "gs://${GCS_BUCKET}/logs/${{ steps.init.outputs.gcs_suffix }}/status.json" "$baseline/status.json" \ - || echo "::warning::No status.json for spark ${{ matrix.spark_release }}, openlineage ${{ matrix.ol_release }}" + gcloud storage cp "${{ steps.ran.outputs.status_file }}" "$baseline/status.json" - uses: actions/upload-artifact@v4 - if: ${{ steps.init.outputs.scenarios }} + if: ${{ steps.ran.outputs.status_file }} with: name: spark-dataproc-${{matrix.spark_release}}-${{matrix.ol_release}}-report path: spark-dataproc-${{matrix.spark_release}}-${{matrix.ol_release}}-report.json retention-days: 1 + if-no-files-found: error - # scenarios that failed validation or whose Dataproc job didn't finish in DONE state + # scenarios that failed validation, including those whose Dataproc job didn't finish in DONE state - name: Get driver logs of failed scenarios - if: ${{ steps.init.outputs.scenarios }} + if: ${{ steps.ran.outputs.status_file }} run: | mkdir -p failure-logs - failed_scenarios=$( { - jq -r '.[].scenarios[] | select(.status == "FAILURE") | .name' 'spark-dataproc-${{matrix.spark_release}}-${{matrix.ol_release}}-report.json' - gcloud storage cat "gs://${GCS_BUCKET}/logs/${{ steps.init.outputs.gcs_suffix }}/status.json" 2> /dev/null \ - | jq -r '.[] | select(.state != "DONE") | .scenario' - } | sort -u ) + failed_scenarios=$(jq -r '.[].scenarios[] | select(.status == "FAILURE") | .name' 'spark-dataproc-${{matrix.spark_release}}-${{matrix.ol_release}}-report.json') for scenario in $failed_scenarios; do - gcloud storage cp "gs://${GCS_BUCKET}/logs/${{ steps.init.outputs.gcs_suffix }}/$scenario.log" \ + gcloud storage cp "gs://${GCS_BUCKET}/logs/${{ steps.ran.outputs.gcs_suffix }}/$scenario.log" \ "failure-logs/$scenario-${{matrix.spark_release}}-${{matrix.ol_release}}-driver.log" \ || echo "::warning::No driver log for scenario $scenario" done - uses: actions/upload-artifact@v4 - if: ${{ steps.init.outputs.scenarios }} + if: ${{ steps.ran.outputs.status_file }} with: name: spark-dataproc-${{matrix.spark_release}}-${{matrix.ol_release}}-failure-logs path: failure-logs/ retention-days: 7 if-no-files-found: ignore - # validation only sees events, so a job that failed after emitting the expected events (e.g. a dependency - # conflict) would pass; this fails the workflow for every Dataproc job that didn't finish in DONE state - check-spark-jobs: - needs: - - run-spark-tests - - validate - if: ${{ !cancelled() && needs.run-spark-tests.result == 'success' }} - runs-on: ubuntu-latest - steps: - - name: GCP authorization - uses: 'google-github-actions/auth@v2' - with: - credentials_json: '${{ secrets.gcpKey }}' - - - name: Fail if any Spark job didn't finish - run: | - failed=0 - for status in $(gcloud storage ls "gs://${GCS_BUCKET}/logs/${RUN_KEY}/**/status.json" 2> /dev/null); do - pair=${status#gs://${GCS_BUCKET}/logs/${RUN_KEY}/} - pair=${pair%/status.json} - while IFS=$'\t' read -r scenario state job_id; do - echo "::error title=Spark job failed::$scenario (spark ${pair%%/*}, openlineage ${pair##*/}) ended in state $state, job '$job_id'. Driver log: artifact spark-dataproc-${pair/\//-}-failure-logs" - failed=1 - done < <(gcloud storage cat "$status" | jq -r '.[] | select(.state != "DONE") | [.scenario, .state, .job_id] | @tsv') - done - exit $failed diff --git a/.github/workflows/revalidate_stored_events.yml b/.github/workflows/revalidate_stored_events.yml index 7c397ec2..2c4e10c6 100644 --- a/.github/workflows/revalidate_stored_events.yml +++ b/.github/workflows/revalidate_stored_events.yml @@ -79,8 +79,10 @@ jobs: for pair_dir in baseline/*/*/; do pair=${pair_dir#baseline/}; pair=${pair%/} cv=${pair%%/*}; ol=${pair##*/} + run_status=() + [[ -f "baseline/$pair.status.json" ]] && run_status=(--run_status="baseline/$pair.status.json") echo "::group::${{ matrix.component }} $cv, openlineage $ol" - python scripts/validate_ol_events.py \ + python scripts/validate_ol_events.py "${run_status[@]}" \ --event_base_dir="$pair_dir" \ --spec_base_dir=specs \ --target="pair-reports/$cv-$ol.json" \ diff --git a/producer/hive_dataproc/runner/get_hive_openlineage_jars.sh b/producer/hive_dataproc/runner/get_hive_openlineage_jars.sh index d223fa29..0e753785 100755 --- a/producer/hive_dataproc/runner/get_hive_openlineage_jars.sh +++ b/producer/hive_dataproc/runner/get_hive_openlineage_jars.sh @@ -7,7 +7,9 @@ set -euxo pipefail readonly VM_HADOOP_LIB_DIR=/usr/lib/hadoop/lib readonly VM_DATAPROC_VM_HADOOP_LIB_DIR_DIR=/usr/local/share/google/dataproc/lib readonly OPENLINEAGE_HIVE_URL=$(/usr/share/google/get_metadata_value attributes/OPENLINEAGE_HIVE_URL || echo "") -readonly GCS_TRANSPORT_JAR_URL=$(/usr/share/google/get_metadata_value attributes/GCS_TRANSPORT_JAR_URL || echo "") +# the workflow sets GCS_TRANSPORT_JAR; GCS_TRANSPORT_JAR_URL is the old name, still read as a fallback +readonly GCS_TRANSPORT_JAR_URL=$(/usr/share/google/get_metadata_value attributes/GCS_TRANSPORT_JAR \ + || /usr/share/google/get_metadata_value attributes/GCS_TRANSPORT_JAR_URL || echo "") if [[ -d ${VM_DATAPROC_VM_HADOOP_LIB_DIR_DIR} ]]; then vm_lib_dir=${VM_DATAPROC_VM_HADOOP_LIB_DIR_DIR} diff --git a/producer/hive_dataproc/scenarios/aggregate_job/events/columnLineage.json b/producer/hive_dataproc/scenarios/aggregate_job/events/columnLineage.json index df2307a6..17705bf6 100644 --- a/producer/hive_dataproc/scenarios/aggregate_job/events/columnLineage.json +++ b/producer/hive_dataproc/scenarios/aggregate_job/events/columnLineage.json @@ -6,17 +6,17 @@ }, "outputs": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.monthly_transaction_summary", "facets": { "columnLineage": { - "_producer": "https://github.com/OpenLineage/OpenLineage/tree/1.34.0/integration/hive", + "_producer": "{{ match(result, 'https://github.com/OpenLineage/OpenLineage/tree/.*/integration/hive') }}", "_schemaURL": "https://openlineage.io/spec/facets/1-2-0/ColumnLineageDatasetFacet.json#/$defs/ColumnLineageDatasetFacet", "fields": { "month": { "inputFields": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.transactions", "field": "submissiondate", "transformations": [ @@ -33,7 +33,7 @@ "transactiontype": { "inputFields": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.transactions", "field": "transactiontype", "transformations": [ @@ -50,7 +50,7 @@ "totalamount": { "inputFields": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.transactions", "field": "transactionamount", "transformations": [ @@ -67,10 +67,10 @@ }, "dataset": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.transactions", "field": "submissiondate", - "transformations": [ + "{{ unordered_list(result, 'transformations') }}": [ { "type": "INDIRECT", "subtype": "GROUP_BY", @@ -86,10 +86,10 @@ ] }, { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.transactions", "field": "transactiontype", - "transformations": [ + "{{ unordered_list(result, 'transformations') }}": [ { "type": "INDIRECT", "subtype": "GROUP_BY", diff --git a/producer/hive_dataproc/scenarios/aggregate_job/events/hive_properties.json b/producer/hive_dataproc/scenarios/aggregate_job/events/hive_properties.json index 73d8842e..93bdd3b0 100644 --- a/producer/hive_dataproc/scenarios/aggregate_job/events/hive_properties.json +++ b/producer/hive_dataproc/scenarios/aggregate_job/events/hive_properties.json @@ -7,7 +7,7 @@ "run": { "facets": { "hive_properties": { - "_producer": "https://github.com/OpenLineage/OpenLineage/tree/1.34.0/integration/hive", + "_producer": "{{ match(result, 'https://github.com/OpenLineage/OpenLineage/tree/.*/integration/hive') }}", "_schemaURL": "https://openlineage.io/spec/2-0-2/OpenLineage.json#/$defs/RunFacet", "properties": { "hive.query.id": "{{ match(result, 'hive_.*') }}", diff --git a/producer/hive_dataproc/scenarios/aggregate_job/events/run_event.json b/producer/hive_dataproc/scenarios/aggregate_job/events/run_event.json index 78eeac75..10f72c01 100644 --- a/producer/hive_dataproc/scenarios/aggregate_job/events/run_event.json +++ b/producer/hive_dataproc/scenarios/aggregate_job/events/run_event.json @@ -12,7 +12,7 @@ }, "inputs": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.transactions", "facets": {}, "inputFacets": {} @@ -20,7 +20,7 @@ ], "outputs": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.monthly_transaction_summary", "facets": {}, "outputFacets": {} diff --git a/producer/hive_dataproc/scenarios/aggregate_job/events/schema.json b/producer/hive_dataproc/scenarios/aggregate_job/events/schema.json index 7240ef01..25f6c903 100644 --- a/producer/hive_dataproc/scenarios/aggregate_job/events/schema.json +++ b/producer/hive_dataproc/scenarios/aggregate_job/events/schema.json @@ -6,7 +6,7 @@ }, "inputs": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.transactions", "facets": { "schema": { @@ -30,7 +30,7 @@ ], "outputs": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.monthly_transaction_summary", "facets": { "schema": { diff --git a/producer/hive_dataproc/scenarios/aggregate_job/events/sql.json b/producer/hive_dataproc/scenarios/aggregate_job/events/sql.json index b21f09d1..2a0cf121 100644 --- a/producer/hive_dataproc/scenarios/aggregate_job/events/sql.json +++ b/producer/hive_dataproc/scenarios/aggregate_job/events/sql.json @@ -5,7 +5,7 @@ "name": "createtable_as_select.default.monthly_transaction_summary", "facets": { "sql": { - "query": "CREATE TABLE monthly_transaction_summary STORED AS PARQUET AS SELECT TRUNC(submissiondate, 'MM') AS Month, transactiontype, SUM(transactionamount) AS TotalAmount, COUNT(*) AS TransactionCount FROM transactions GROUP BY TRUNC(submissiondate, 'MM'), transactiontype ORDER BY Month, transactiontype" + "query": "CREATE TABLE monthly_transaction_summary\n STORED AS PARQUET\n AS\n SELECT\n TRUNC(submissiondate, 'MM') AS Month,\n transactiontype,\n SUM(transactionamount) AS TotalAmount,\n COUNT(*) AS TransactionCount\n FROM\n transactions\n GROUP BY\n TRUNC(submissiondate, 'MM'),\n transactiontype\n ORDER BY\n Month,\n transactiontype" } } } diff --git a/producer/hive_dataproc/scenarios/aggregate_job/events/symlinks.json b/producer/hive_dataproc/scenarios/aggregate_job/events/symlinks.json index 57c5d567..7cd7b63a 100644 --- a/producer/hive_dataproc/scenarios/aggregate_job/events/symlinks.json +++ b/producer/hive_dataproc/scenarios/aggregate_job/events/symlinks.json @@ -6,14 +6,14 @@ }, "inputs": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.transactions", "facets": { "symlinks": { "identifiers": [ { - "namespace": "gs://open-lineage-e2e", - "name": "warehouse/transactions", + "namespace": "{{ match(result, 'hdfs://[^/]+-m') }}", + "name": "/user/hive/warehouse/transactions", "type": "LOCATION" } ] @@ -23,13 +23,13 @@ ], "outputs": [ { - "namespace": "hive://hive-ol-cluster-m:9083", + "namespace": "{{ match(result, 'hive://[^/]+-m:9083') }}", "name": "default.monthly_transaction_summary", "facets": { "symlinks": { "identifiers": [ { - "namespace": "hdfs://hive-ol-cluster-m", + "namespace": "{{ match(result, 'hdfs://[^/]+-m') }}", "name": "/user/hive/warehouse/monthly_transaction_summary", "type": "LOCATION" } diff --git a/scripts/compare_events.py b/scripts/compare_events.py index e358098f..cf960384 100644 --- a/scripts/compare_events.py +++ b/scripts/compare_events.py @@ -1,6 +1,7 @@ # Copyright 2018-2024 contributors to the OpenLineage project # SPDX-License-Identifier: Apache-2.0 +import builtins import json import logging import os @@ -115,7 +116,8 @@ def diff(expected, result, prefix="", function=None) -> list: else: if function == "unordered_list": for i, x in enumerate(expected): - if not any(r for r in result if diff(x, r, f"{prefix}.[{i}]") is []): + # builtins.any: this module defines its own any() as a jinja helper + if not builtins.any(diff(x, r, f"{prefix}.[{i}]") == [] for r in result): errors.append(f"In {prefix}.[{i}], no matching elements") else: for i, x in enumerate(expected): diff --git a/scripts/tests/test_compare_events.py b/scripts/tests/test_compare_events.py new file mode 100644 index 00000000..77cb246e --- /dev/null +++ b/scripts/tests/test_compare_events.py @@ -0,0 +1,21 @@ +from compare_events import diff + +UNORDERED = "{{ unordered_list(result, 'transformations') }}" + + +def test_unordered_list_matches_in_any_order(): + expected = {UNORDERED: [{"subtype": "GROUP_BY"}, {"subtype": "SORT"}]} + result = {"transformations": [{"subtype": "SORT", "type": "INDIRECT"}, {"subtype": "GROUP_BY", "type": "INDIRECT"}]} + assert diff(expected, result) == [] + + +def test_unordered_list_reports_a_missing_element(): + expected = {UNORDERED: [{"subtype": "GROUP_BY"}, {"subtype": "SORT"}]} + result = {"transformations": [{"subtype": "SORT"}, {"subtype": "FILTER"}]} + assert diff(expected, result) == ["In .transformations.[0], no matching elements"] + + +def test_plain_lists_stay_ordered(): + expected = {"transformations": [{"subtype": "GROUP_BY"}, {"subtype": "SORT"}]} + result = {"transformations": [{"subtype": "SORT"}, {"subtype": "GROUP_BY"}]} + assert len(diff(expected, result)) == 2 diff --git a/scripts/tests/test_report.py b/scripts/tests/test_report.py new file mode 100644 index 00000000..e7c0b2f6 --- /dev/null +++ b/scripts/tests/test_report.py @@ -0,0 +1,40 @@ +from report import Report, Scenario, Test as ReportTest + +TAGS = {"facets": ["sql"], "lineage_level": {"bigquery": ["dataset"]}} + + +def scenario(*tests): + return Scenario.simplified("s", list(tests)) + + +def make_test(name, status, tags=None): + return ReportTest(name, status, "semantics", "openlineage", [] if status == "SUCCESS" else ["detail"], tags or {}) + + +def report(*tests, component_version="1.0.0", ol="1.40.0"): + return Report.from_dict([{ + "name": "p", "component_type": "producer", "component_version": component_version, + "openlineage_version": ol, "scenarios": [scenario(*tests).to_dict()]}]) + + +def test_skipped_and_warning_keep_the_scenario_green(): + assert scenario(make_test("a", "SUCCESS"), make_test("semantics", "WARNING")).status == "SUCCESS" + assert scenario(make_test("a", "SUCCESS"), make_test("semantics", "SKIPPED")).status == "SUCCESS" + assert scenario(make_test("a", "FAILURE"), make_test("semantics", "SKIPPED")).status == "FAILURE" + + +def test_skipped_and_warning_are_not_new_failures(): + new = report(make_test("a", "SUCCESS"), make_test("semantics", "WARNING")) + assert new.get_new_failures(None).to_dict() == [] + + +def test_skipped_and_warning_are_not_counted_in_tag_summaries(): + summary = report(make_test("a", "SUCCESS", TAGS), make_test("semantics", "WARNING", TAGS), + make_test("skipped", "SKIPPED", {"facets": ["other"]})).get_producer_tag_summary() + [producer] = summary + assert producer.component_versions["1.0.0"]["1.40.0"]["facets"] == {"sql"} + + +def test_round_trip_keeps_new_statuses(): + original = report(make_test("a", "SUCCESS"), make_test("semantics", "SKIPPED")) + assert Report.from_dict(original.to_dict()).to_dict() == original.to_dict() diff --git a/scripts/tests/test_validate_ol_events.py b/scripts/tests/test_validate_ol_events.py new file mode 100644 index 00000000..13e09508 --- /dev/null +++ b/scripts/tests/test_validate_ol_events.py @@ -0,0 +1,228 @@ +"""End-to-end tests of scripts/validate_ol_events.py through its command line, on small generated fixtures.""" +import json +import subprocess +import sys + +import pytest + +from conftest import REPO_ROOT, SCRIPTS_DIR + +COMPONENT = "fake_producer" +CV = "1.0.0" +OL = "1.40.0" + + +def write_json(path, content): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(content)) + + +def run_event(job_name="job", event_type="COMPLETE", run_facets=None): + return { + "eventType": event_type, + "eventTime": "2026-01-01T00:00:00Z", + "producer": "https://example.com/producer", + "schemaURL": "https://openlineage.io/spec/2-0-2/OpenLineage.json#/$defs/RunEvent", + "run": {"runId": "0190a4b2-0000-7000-8000-000000000000", "facets": run_facets or {}}, + "job": {"namespace": "ns", "name": job_name, "facets": {}}, + "inputs": [], + "outputs": [], + } + + +@pytest.fixture +def env(tmp_path): + """A spec dir, a producer dir and an event dir; returns a helper namespace.""" + specs = tmp_path / "specs" / OL + write_json(specs / "OpenLineage.json", {"$id": "https://openlineage.io/spec/2-0-2/OpenLineage.json", "type": "object", + "required": ["eventType", "job"]}) + # a facet schema whose $ref points nowhere: jsonschema raises while validating, like a broken schema in a release + write_json(specs / "BoomRunFacet.json", {"$id": "https://openlineage.io/spec/facets/1-0-0/BoomRunFacet.json", + "properties": {"boom": {"$ref": "#/$defs/missing"}}}) + + class Env: + root = tmp_path + producer = tmp_path / "producer" + events = tmp_path / "events" + + @staticmethod + def scenario(name, tests=None, component_versions=None, openlineage_versions=None, expected=None): + config = {"tests": tests or []} + if component_versions: + config["component_versions"] = component_versions + if openlineage_versions: + config["openlineage_versions"] = openlineage_versions + base = tmp_path / "producer" / COMPONENT / "scenarios" / name + write_json(base / "config.json", config) + for file_name, body in (expected or {}).items(): + write_json(base / "events" / file_name, body) + + @staticmethod + def emitted(scenario, file_name, body): + target = tmp_path / "events" / scenario / file_name + target.parent.mkdir(parents=True, exist_ok=True) + target.write_text(body if isinstance(body, str) else json.dumps(body)) + + @staticmethod + def validate(*extra, ol=OL): + Env.events.mkdir(exist_ok=True) + target = tmp_path / "report.json" + result = subprocess.run( + [sys.executable, str(SCRIPTS_DIR / "validate_ol_events.py"), + f"--event_base_dir={Env.events}", f"--spec_base_dir={tmp_path / 'specs'}", + f"--producer_dir={Env.producer}", f"--component={COMPONENT}", f"--component_version={CV}", + f"--openlineage_version={ol}", f"--target={target}", *extra], + cwd=REPO_ROOT, capture_output=True, text=True) + assert result.returncode == 0, result.stdout + result.stderr + [component] = json.loads(target.read_text()) + return {s["name"]: s for s in component["scenarios"]} + + return Env + + +def by_name(scenario): + return {t["name"]: t for t in scenario["tests"]} + + +def semantic_test(name, job_name="job"): + return {"name": name, "path": f"events/{name}.json", "tags": {}} + + +def test_validator_error_fails_that_scenario_and_keeps_the_others(env): + env.scenario("broken") + env.scenario("fine") + env.emitted("broken", "e.json", run_event(run_facets={"boom": {"_producer": "x", "_schemaURL": "y"}})) + env.emitted("fine", "e.json", run_event()) + + scenarios = env.validate() + + assert scenarios["broken"]["status"] == "FAILURE" + [syntax] = [t for t in scenarios["broken"]["tests"] if t["validation_type"] == "syntax"] + assert syntax["status"] == "FAILURE" + assert any("validator error" in d and "boom" in d for d in syntax["details"]) + assert scenarios["fine"]["status"] == "SUCCESS" + + +def test_scenario_valid_for_the_version_without_events_fails(env): + env.scenario("silent") + + scenarios = env.validate() + + events = by_name(scenarios["silent"])["events"] + assert scenarios["silent"]["status"] == "FAILURE" + assert events["status"] == "FAILURE" + assert events["details"] == ["scenario produced no events"] + + +def test_empty_event_directory_fails(env): + env.scenario("empty") + (env.events / "empty").mkdir(parents=True) + + scenarios = env.validate() + + assert by_name(scenarios["empty"])["events"]["status"] == "FAILURE" + + +def test_scenario_gated_out_without_events_is_not_reported(env): + env.scenario("future", openlineage_versions={"min": "9.0.0"}) + env.scenario("now") + env.emitted("now", "e.json", run_event()) + + scenarios = env.validate() + + assert "future" not in scenarios + assert "now" in scenarios + + +def test_syntax_failure_adds_a_note_instead_of_skipping_semantics_silently(env): + expected = run_event() + env.scenario("bad_syntax", tests=[semantic_test("run_test")], expected={"run_test.json": expected}) + bad = run_event() + del bad["eventType"] + env.emitted("bad_syntax", "e.json", bad) + + scenarios = env.validate() + + semantics = by_name(scenarios["bad_syntax"])["semantics"] + assert semantics["status"] == "SKIPPED" + assert semantics["details"] == ["semantic checks skipped because syntax validation failed"] + assert scenarios["bad_syntax"]["status"] == "FAILURE" + + +def test_no_semantic_test_for_the_version_is_a_warning(env): + gated = dict(semantic_test("run_test"), openlineage_versions={"min": "9.0.0"}) + env.scenario("gated_tests", tests=[gated], expected={"run_test.json": run_event()}) + env.emitted("gated_tests", "e.json", run_event()) + + scenarios = env.validate() + + semantics = by_name(scenarios["gated_tests"])["semantics"] + assert semantics["status"] == "WARNING" + assert semantics["details"] == [f"no semantic tests apply to {COMPONENT} {CV} / OpenLineage {OL}"] + assert scenarios["gated_tests"]["status"] == "SUCCESS" + + +def test_semantic_tests_still_run(env): + env.scenario("ok", tests=[semantic_test("run_test")], expected={"run_test.json": run_event()}) + env.emitted("ok", "e.json", run_event()) + + scenarios = env.validate() + + assert by_name(scenarios["ok"])["run_test"]["status"] == "SUCCESS" + assert "semantics" not in by_name(scenarios["ok"]) + + +def test_run_status_marks_unfinished_producer_jobs(env, tmp_path): + env.scenario("crashed") + env.scenario("done") + env.emitted("crashed", "e.json", run_event()) + env.emitted("done", "e.json", run_event()) + status = tmp_path / "status.json" + write_json(status, [{"scenario": "crashed", "state": "ERROR", "job_id": "job-123"}, + {"scenario": "done", "state": "DONE", "job_id": "job-456"}]) + + scenarios = env.validate(f"--run_status={status}") + + job = by_name(scenarios["crashed"])["producer job"] + assert job["status"] == "FAILURE" + assert job["details"] == ["producer job ended in state ERROR, job 'job-123'"] + assert scenarios["crashed"]["status"] == "FAILURE" + assert "producer job" not in by_name(scenarios["done"]) + assert scenarios["done"]["status"] == "SUCCESS" + + +def test_invalid_event_file_fails_only_its_scenario(env): + env.scenario("garbled") + env.scenario("fine") + env.emitted("garbled", "e.json", "{not json") + env.emitted("fine", "e.json", run_event()) + + scenarios = env.validate() + + validation = by_name(scenarios["garbled"])["validation"] + assert validation["status"] == "FAILURE" + assert validation["details"][0].startswith("validation failed:") + assert scenarios["fine"]["status"] == "SUCCESS" + + +def test_openlineage_release_gates_when_the_spec_tag_is_not_a_version(env, tmp_path): + (tmp_path / "specs" / OL).rename(tmp_path / "specs" / "main") + env.scenario("future", openlineage_versions={"min": "9.0.0"}) + env.scenario("now", openlineage_versions={"min": "1.0.0"}) + + scenarios = env.validate(f"--openlineage_release={OL}", ol="main") + + assert set(scenarios) == {"now"} + + +def test_unreadable_config_fails_only_its_scenario(env): + env.scenario("fine") + env.emitted("fine", "e.json", run_event()) + broken = env.producer / COMPONENT / "scenarios" / "broken_config" + broken.mkdir(parents=True) + (broken / "config.json").write_text("{oops") + + scenarios = env.validate() + + assert by_name(scenarios["broken_config"])["validation"]["status"] == "FAILURE" + assert scenarios["fine"]["status"] == "SUCCESS" diff --git a/scripts/validate_ol_events.py b/scripts/validate_ol_events.py index 99f1dc93..53d41847 100644 --- a/scripts/validate_ol_events.py +++ b/scripts/validate_ol_events.py @@ -87,8 +87,10 @@ def validate_entity(self, instance, schema_type, name): return [] else: return [f"$.{schema_type} facet type {schema_type} not recognized"] - except Exception: + except Exception as e: + # a validator that can't check the facet must fail the event, not drop the result print(f"when validating {schema_type}, for instance of {name} following exception occurred \n {traceback.format_exc()}") + return [f"validator error while checking {schema_type}: {type(e).__name__}: {e}"] def should_skip_facet(self, facet_name): if not self.unchecked_facets or not self.openlineage_version: @@ -242,6 +244,11 @@ def get_arguments(): parser.add_argument('--component_version', type=str, help="component release used in generating events") parser.add_argument('--openlineage_version', type=str, help="Comma separated list of Openlineage versions") parser.add_argument('--target', type=str, help="target file") + parser.add_argument('--openlineage_release', type=str, default=None, + help="OpenLineage release used for version gating when --openlineage_version is a spec tag " + "that isn't a version (e.g. main for snapshots)") + parser.add_argument('--run_status', type=str, default=None, + help="status.json of the producer run: [{scenario, state, job_id}], state DONE when the job finished") args = parser.parse_args() @@ -253,7 +260,8 @@ def get_arguments(): openlineage_version = args.openlineage_version spec_base_dir = args.spec_base_dir - return event_base_dir, producer_dir, target, spec_base_dir, component, component_version, openlineage_version + return (event_base_dir, producer_dir, target, spec_base_dir, component, component_version, openlineage_version, + args.openlineage_release, args.run_status) def check_versions(component_version, openlineage_version, config): @@ -264,39 +272,124 @@ def check_versions(component_version, openlineage_version, config): release_between(openlineage_version, openlineage_versions.get("min"), openlineage_versions.get("max"))) -def main(): - base_dir, producer_dir, target, spec_dirs, component, component_version, openlineage_version = get_arguments() +def failure(name, validation_type, detail): + return Test(name, 'FAILURE', validation_type, 'openlineage', [detail], {}) + + +def last_line_of_exception(): + return traceback.format_exc().strip().splitlines()[-1] + + +def load_run_status(path): + """Producer job states by scenario, from the status.json written by the producer run (if any).""" + if path is None: + return {} + if not isfile(path): + print(f"WARNING: run status file {path} not found, producer job states are not checked") + return {} + return {entry['scenario']: entry for entry in load_json(path)} + + +def load_events(scenario_path): + if not isdir(scenario_path): + return {} + return {file: load_json(path) for file in listdir(scenario_path) if isfile(path := join(scenario_path, file))} + + +def valid_scenarios(producer_dir, component, component_version, openlineage_version): + """Scenarios defined for the component whose version ranges include the validated versions.""" + scenarios_dir = join(producer_dir, component, 'scenarios') + if not isdir(scenarios_dir): + return [] + names = [] + for name in listdir(scenarios_dir): + if not isdir(join(scenarios_dir, name)): + continue + try: + if check_versions(component_version, openlineage_version, get_config(producer_dir, component, name)): + names.append(name) + except Exception: + # an unreadable config is reported as that scenario's validation failure + names.append(name) + return names + + +def validate_producer_scenario(base_dir, producer_dir, spec_dirs, component, component_version, openlineage_version, + gating_version, scenario_name): + config = get_config(producer_dir, component, scenario_name) + result_events = load_events(get_path(base_dir, component, scenario_name)) + if not result_events: + return {'events': failure('events', 'syntax', 'scenario produced no events')} + + validator = OLSyntaxValidator.get_validator(spec_path=spec_dirs, tag=openlineage_version, + unchecked_facets=config.get('unchecked_facets')) + tests = validate_scenario_syntax(result_events, validator, config) + expected = get_expected_events(producer_dir, component, scenario_name, config, component_version, gating_version) + if not all_tests_succeeded(tests): + tests['semantics'] = Test('semantics', 'SKIPPED', 'semantics', 'openlineage', + ['semantic checks skipped because syntax validation failed'], {}) + elif len(expected) == 0: + tests['semantics'] = Test('semantics', 'WARNING', 'semantics', 'openlineage', + [f"no semantic tests apply to {component} {component_version} / OpenLineage {gating_version}"], {}) + else: + tests.update(OLSemanticValidator(expected).validate(result_events)) + return tests + + +def validate_producer(base_dir, producer_dir, spec_dirs, component, component_version, openlineage_version, + openlineage_release, run_status): + # the scenarios come from their definitions, so a scenario without events is reported instead of vanishing + gating_version = openlineage_release or openlineage_version + scenario_names = set(valid_scenarios(producer_dir, component, component_version, gating_version)) + scenario_names.update(name for name in listdir(base_dir) if isdir(join(base_dir, name))) + job_states = load_run_status(run_status) + + scenarios = {} + for scenario_name in sorted(scenario_names): + try: + tests = validate_producer_scenario(base_dir, producer_dir, spec_dirs, component, component_version, + openlineage_version, gating_version, scenario_name) + except Exception: + print(f"validation of scenario {scenario_name} failed:\n{traceback.format_exc()}") + tests = {'validation': failure('validation', 'syntax', f"validation failed: {last_line_of_exception()}")} + + job = job_states.get(scenario_name) + if job is not None and job.get('state') != 'DONE': + tests['producer job'] = failure('producer job', 'run', + f"producer job ended in state {job.get('state')}, job '{job.get('job_id', '')}'") + scenarios[scenario_name] = Scenario.simplified(scenario_name, tests) + return Report({component: Component(component, 'producer', scenarios, component_version, openlineage_version)}) + + +def validate_consumer_scenarios(base_dir, producer_dir, spec_dirs, component, openlineage_version): + validators = OLSyntaxValidator.get_validators(spec_path=spec_dirs, tags=openlineage_version.split(',')) scenarios = {} + for scenario_name in listdir(base_dir): + scenario_path = get_path(base_dir, component, scenario_name) + if not isdir(scenario_path): + continue + try: + config = get_config(producer_dir, component, scenario_name) + validator = validators.get(config.get('openlineage_version')) + if 'unchecked_facets' in config: + validator.unchecked_facets = config['unchecked_facets'] + print(f"for scenario {scenario_name} validation version is {config.get('openlineage_version')}") + tests = validate_scenario_syntax(load_events(scenario_path), validator, config) + except Exception: + print(f"validation of scenario {scenario_name} failed:\n{traceback.format_exc()}") + tests = {'validation': failure('validation', 'syntax', f"validation failed: {last_line_of_exception()}")} + scenarios[scenario_name] = Scenario.simplified(scenario_name, tests) + return Report({component: Component(component, 'producer', scenarios, "", "")}) + + +def main(): + (base_dir, producer_dir, target, spec_dirs, component, component_version, openlineage_version, + openlineage_release, run_status) = get_arguments() if component == 'scenarios': - validators = OLSyntaxValidator.get_validators(spec_path=spec_dirs, tags=openlineage_version.split(',')) - for scenario_name in listdir(base_dir): - scenario_path = get_path(base_dir, component, scenario_name) - if isdir(scenario_path): - config = get_config(producer_dir, component, scenario_name) - validator = validators.get(config.get('openlineage_version')) - if 'unchecked_facets' in config: - validator.unchecked_facets = config['unchecked_facets'] - print(f"for scenario {scenario_name} validation version is {config.get('openlineage_version')}") - result_events = {file: load_json(path) for file in listdir(scenario_path) if - isfile(path := join(scenario_path, file))} - tests = validate_scenario_syntax(result_events, validator, config) - scenarios[scenario_name] = Scenario.simplified(scenario_name, tests) - report = Report({component: Component(component, 'producer', scenarios, "", "")}) + report = validate_consumer_scenarios(base_dir, producer_dir, spec_dirs, component, openlineage_version) else: - for scenario_name in listdir(base_dir): - config = get_config(producer_dir, component, scenario_name) - unchecked_facets = config.get('unchecked_facets') - validator = OLSyntaxValidator.get_validator(spec_path=spec_dirs, tag=openlineage_version, unchecked_facets=unchecked_facets) - scenario_path = get_path(base_dir, component, scenario_name) - expected = get_expected_events(producer_dir, component, scenario_name, config, component_version, openlineage_version) - result_events = {file: load_json(path) for file in listdir(scenario_path) if - isfile(path := join(scenario_path, file))} - tests = validate_scenario_syntax(result_events, validator, config) - if all_tests_succeeded(tests) and expected is not None: - for name, res in OLSemanticValidator(expected).validate(result_events).items(): - tests[name] = res - scenarios[scenario_name] = Scenario.simplified(scenario_name, tests) - report = Report({component: Component(component, 'producer', scenarios, component_version, openlineage_version)}) + report = validate_producer(base_dir, producer_dir, spec_dirs, component, component_version, openlineage_version, + openlineage_release, run_status) with open(target, 'w') as f: jsonc.dump(report.to_dict(), f, indent=2)