Repository navigation
fix(infra): inject GCP_PROJECT_ID/GCP_REGION into ingestion Job (D113) - #85
Merged
Merged
Conversation
Add a static_env_vars variable (map(string), default {}) and a parallel
dynamic env block in the cloud_run module, symmetric with the existing
secret_env_vars pattern. Modules consumers can now inject non-sensitive
runtime configuration that container code reads via os.environ, while
sensitive values keep going through secret_env_vars.
Remove the commented-out documentary env block (lines 26-30) now that
the real pattern exists in the module.
No behavioral change in production: instances that do not pass
static_env_vars get an empty map, which expands to a no-op for_each.
…D113) ingestion/main.py invokes the dbt Cloud Run Job at end of pipeline (D72, D108). _invoke_dbt() reads GCP_PROJECT_ID and GCP_REGION from os.environ to build the fully-qualified target resource name (projects/.../locations/.../jobs/datatalent-dbt), which is not auto-detectable from ADC. These two variables were missing from the container env, causing the environmental guard of _invoke_dbt() to skip the invocation silently with a warning-level log. Observed on the first real Scheduler run (2026-05-25 04:00 UTC): ingestion SUCCEEDED, dbt never triggered, marts stale (raw.* fresh / marts.fct_offres last_modified J-2). End-to-end validation post-apply: manual gcloud run jobs execute on datatalent-ingestion → event=dbt_invoked → datatalent-dbt-5tm7t SUCCEEDED → marts.fct_offres recreated at 08:58:48 UTC (11490 rows). Refs: D113, T9.17
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.
Contexte
Premier run Scheduler observé en conditions réelles (Phase 4 du chantier inter-bloc) le lundi 2026-05-25 04:00 UTC. L'ingestion s'est exécutée avec succès (exit 0, 8 sources OK), mais le Cloud Run Job
datatalent-dbtn'a pas été déclenché. Les marts sont restés stale (marts.fct_offres.last_modified_timefigé au 2026-05-23 10:03, jour de la validation manuelle de PR #83).Diagnostic en 4 steps (executions list / image deployed / logs structlog / BigQuery freshness) — voir section "Incident notable" ci-dessous.
Cause racine identifiée :
_invoke_dbt()(introduit en D108, PR #81) litGCP_PROJECT_IDetGCP_REGIONdepuisos.environpour construire le nom complet de la ressource Cloud Run cible. Le module Terraformcloud_run/n'injecte ces variables dans aucun container. La garde environnementale a court-circuité l'invocation avec un logdbt_invocation_skipped_missing_enven niveau warning, donc invisible côté monitoring Niveau 1.D113 ajoutée à
notes-projet.mdpour acter le choix d'implémentation et le pattern doctrinal (sixième occurrence du pattern "découverte à l'apply").Décisions techniques
var.static_env_vars(map) côté module Terraform, instanciée au root pourdatatalent-ingestionuniquementsys.exit(1)— durcissement de visibilité, pas fix de la cause)dynamic "env"parallèle ausecret_env_varsexistantcloud_run_dbt(map vide = no-op naturel viafor_each)_invoke_dbt()Changements
infra/modules/cloud_run/variables.tf— ajoutvariable "static_env_vars"(map(string), default{})infra/modules/cloud_run/main.tf— ajout blocdynamic "env"itérant surstatic_env_vars; suppression du blocenvstatique commenté ll. 26-30 (TODO-3 du rétro-todo absorbé : le pattern est désormais utilisé en vrai, plus besoin de la version documentaire)infra/main.tf— argumentstatic_env_vars = { GCP_PROJECT_ID, GCP_REGION }ajouté à l'instanciationmodule.cloud_run(ingestion). Aucune modification demodule.cloud_run_dbt.Incident notable durant l'observation Phase 4
Le run du 2026-05-25 04:00 UTC a produit l'asymétrie suivante en BigQuery :
Diagnostic des logs structlog de l'exécution
datatalent-ingestion-hj7gg:main.pya fait son travail (la garde a tracé pourquoi elle ne déclenchait pas dbt), mais le modewarning+ exit code 0 du Job ingestion (toutes sources OK) → aucune alerte D105 déclenchée. Mode de défaillance silencieux exactement contraire à D72, deuxième prolongation après D111.Validation
terraform planpost-editAucun diff sur
module.cloud_run_dbt(validation expérimentale du choix Voie A : map vide = no-op).terraform applyRun end-to-end post-apply
Invocation manuelle
gcloud run jobs execute datatalent-ingestion --wait:Logs structlog de l'exécution
t5zl4:(comparer avec le run cassé du matin qui émettait
dbt_invocation_skipped_missing_envavecgcp_project_id_set: False/gcp_region_set: False)Exécution dbt déclenchée :
sa-ingestioncommeRUN BYconfirme l'invocation programmatique depuismain.py(vs invocations manuelles du 2026-05-23 pargregory.martin.data).BigQuery
marts.fct_offresrafraîchi :(était figé à
2026-05-23 10:03:33/ 10269 rows avant le fix — soit J-2 et +1221 rows accumulés depuis)terraform planpost-applyRègle D31 respectée — zéro diff post-apply.
Décisions liées
GCP_PROJECT_ID/GCP_REGIONcôté Terraformmain.py→ dbt)vars.GCP_PROJECT_ID/vars.GCP_REGION) mais pas dans le runtime prod du containerRefs : T9.17 (origine de
_invoke_dbt()), TODO-3 absorbé (rétro-todo), TODO-8 créé (durcissement garde, Bloc 2).