Hotfix: Replace logical_date with dag_run.start_date - #143
Open
jayckaiser wants to merge 7 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hotfix: Replace
logical_datewithdag_run.start_dateDescription & motivation
In current
EdFiResourceDAGbehavior, there is unexpected behavior that affects timestamps recorded in Stadium between scheduled and manual runs. Timestamps placed into thepull_dateandpull_timestampcolumns inraw.edfi3.{resource}andraw.edfi3._meta_change_versiontables are derived from thelogical_dateattribute of a DAG Run. This variable reflects different things, depending on the type of run being completed:In practice, this means that if one runs the DAG manually, and then the DAG runs on its schedule later that night, the scheduled run timestamp will be recorded as occurring before the manual run. This means that if a given record is ingested to Stadium and then updated by that evening, the first version of the record will take precedence over the updated version by Stadium's staging dedupe rules.
This fix simply changes what variable is used as the timestamp record of the DAG run: the
dag_run.start_timevariable reflects the actual runtime of the DAG in all cases, never the start of the schedule interval. This change will prevent the misordering issue in almost all cases*.PR Merge Priority:
This is a longstanding bug that was somehow never discovered previously (but it may be responsible for some of our historic sync-drift in SC). It is uncommon to need to manually rerun the
EdFiResourceDAG, but we need to make sure that records are recorded in the correct timestamp-order in Snowflake. This issue was likely obscured through regular full-refreshes that have been completed in South Carolina and other Stadium implementations.Changes to existing files:
edu_edfi_airflow/callables/change_version.py: Retrievedag_run.start_dateinstead ofdsandts, and convert to date and timestamp isoformat respectively.edu_edfi_airflow/callables/total_counts.py: Retrievedag_run.start_dateinstead ofdsandts, and convert to date and timestamp isoformat respectively.edu_edfi_airflow/dags/edfi_resource_dag.py: Retrievedag_run.start_dateinstead ofds_nodashandts_nodash, and convert to ds_nodash and ts_nodash format respectively.Tests and QC done:
This change has been tested successfully in SC dev, specifically for the
copy_all_endpoints_to_snowflakeandupdate_change_versions_in_snowflaketasks. I have not tested this change in the total-counts taskgroup (as these are not enabled in dev), but the logic is identical to the update-change-versions task.Future ToDos & Questions:
*There is one case where misordering could still occur. When a task is cleared and rerun, the
dag_run.start_datevariable updates to that new task runtime. This is unexpected behavior, but I couldn't find a DagRun variable that represents actual DAG runtime that remains consistent across task reruns. If someone were to run the DAG, let either thecopy_all_endpoints_into_snowflakeorupdate_change_versions_in_snowflaketasks fail, then rerun the failed task after a subsequent run completes successfully, then we will still record timestamps in Stadium that do not reflect the original runtime of the run. This is an anti-pattern of this DAG, however (i.e., why rerun a task from the previous night when the subsequent run succeeded). I'd argue this is a reasonable concession, but if we can find a more consistent DagRun variable to use in place ofstart_date, that would remove any uncertainty.Additionally, I did not make changes to any other helpers or DAGs that those used by
EdFiResourceDAG. TheEarthbeamDAGand its helpers will be deprecated in the near future.