fix(grafana): make YAML->NDJSON compile opt-in on native upload (#279) - #287
Conversation
…tic#279) The Grafana CLI unconditionally ran kb-dashboard-cli YAML->NDJSON compilation before every upload, but the default native Dashboards API upload maps YAML / NativeDashboard IR straight to API panels and never consumes that NDJSON. Dashboards the typed API rejects already recompile lazily inside the legacy fallback, so the pre-upload compile was pure overhead on the default path. The unified CLI also hard-coded --compile for Datadog, contradicting the Datadog dedicated CLI's opt-in behavior. Gate the Grafana compile step on an explicit --compile (or --upload --legacy-import, which imports the compiled saved objects), add --compile/--no-compile flags, and forward --compile conditionally from the unified CLI for both sources. Suppress the misleading "Compilation results: 0/0" line and "compilation not run" summaries when compilation was skipped, and add compile_attempted to the detailed report so automation can tell "skipped" from "compiled and failed". Scripts that consume the NDJSON (run_migration.sh, parity-rig upload-all.sh) now pass --compile explicitly. Docs updated to match.
3be3a1a to
b7d2a7b
Compare
giorgi-imerlishvili-elastic
left a comment
There was a problem hiding this comment.
I don't think this is ready to approve yet; two items need addressing:
-
observability_migration/app/cli.pyappends--compiletwice for the unified Grafana path when the flag is set (the new block around line 906 duplicates the existing block after--validate). The dedicated parser currently tolerates duplicatestore_trueflags, but the wrapper is forwarding the wrong argv and the regression is hidden becausetest_run_grafana_migration_forwards_compile_flagonly usesassertIn. Please remove one append and tighten the test to assert exactly one occurrence (or the complete expected argv). -
The canonical
docs/command-contract.mdstill says at lines 1393-1394 that dashboard YAML lint and compiled-layout validation run automatically inside everymigrate. With this change, default migration runs lint, but compiled-layout validation only runs when compilation is requested (--compileor--upload --legacy-import). Please update that statement to match the new behavior and the updated dashboards README.
The rest of the lazy-compile path looks consistent: Datadog no longer receives an unconditional --compile, skipped compilation is represented as not run in the updated summaries, and the NDJSON-consuming scripts opt in explicitly. CI is green, but it does not catch the duplicate because of the membership-only assertion above.
…astic#279) Address PR elastic#287 review feedback. The unified Grafana wrapper forwarded --compile twice (a new append before --validate plus a stale one after it); the membership-only test assertion hid the duplicate. Keep the single append before --validate to match the Datadog path and tighten the test to assert exactly one occurrence. Also correct docs/command-contract.md so it reflects the opt-in behavior: YAML lint runs on every migrate, while compiled-layout validation only runs when compilation is requested (--compile or --upload --legacy-import), matching the dashboards README.
giorgi-imerlishvili-elastic
left a comment
There was a problem hiding this comment.
Re-reviewed after b430ddc. Both prior findings are resolved: Grafana now forwards --compile exactly once with a regression assertion, and docs/command-contract.md correctly limits compiled-layout validation to compile-enabled runs. I found no remaining issues in the full PR, and all current CI checks pass. This is ready for approval by another reviewer (GitHub does not allow the PR author's account to submit an approval).
|
Thanks for the fix — the core reasoning is correct and the test coverage is solid. One thing worth flagging before this merges: the YAML→NDJSON compile path ( That means this PR's remaining value is the test coverage and reporting cleanup — both worthwhile — but the Recommendation: merge this as-is for the reporting/test fixes, but treat the |
Issue
Fixes #279 — the Grafana migration unconditionally compiled YAML → NDJSON via
kb-dashboard-clibefore every upload, even though the default native Dashboards API upload never consumes that NDJSON.Was the issue valid?
Yes. The default native Dashboards API upload maps YAML /
NativeDashboardIR straight to API panels and never reads the compiled NDJSON. Dashboards the typed API rejects already recompile lazily inside the legacy fallback (adapter._native_upload_file). So the pre-upload[5/7]compile was pure overhead on the default path. The unified CLI additionally hard-coded--compilefor Datadog, contradicting the Datadog dedicated CLI, which had already made compilation opt-in.Root cause
observability_migration/adapters/source/grafana/cli.pyran the[5/7] Compiling YAML -> Kibana NDJSONstep with no gate.observability_migration/app/cli.pyforwarded--compileinconsistently across sources (hard-coded for Datadog).Related code paths checked
targets/kibana/adapter.py— native upload + per-dashboard legacy compile fallback (_native_upload_file/_legacy_upload_file).targets/kibana/compile.py—compile_all/ layout validation.adapters/source/grafana/cli.py,adapters/source/datadog/cli.py(the reference opt-in implementation),app/cli.py.core/reporting/report.py,core/reporting/summary_md.py,adapters/source/datadog/report.py— compile status reporting.parity-rig/verifierT3 layer,parity-rig/upload-all.sh,scripts/run_migration.sh, and the local render-audit flow (already--uploadwith no--compile).Fix implemented
--compile/--no-compile; the compile step now runs only when--compileis set explicitly, or when--upload --legacy-importis used (that path imports the compiled saved objects and auto-enables compile). The default native path skips compilation and uploads directly.obs-migrate migrate: forwards--compileonly when explicitly supplied, for both Grafana and Datadog (removes the hard-coded Datadog--compile); still forwards--legacy-importso the dedicated CLIs auto-enable compile for legacy import.Compilation results: 0/0line; Markdown summaries rendercompilation not run(instead of0/0 compiled) and do not emit a false "Blocking errors" compile verdict when compilation was skipped; per-dashboard stdout uses—instead of?for not-run; detailed report gainscompile_attempted/compiled_totalso automation can distinguish "skipped" from "compiled and failed".scripts/run_migration.shandparity-rig/upload-all.shnow pass--compileexplicitly because they consume the compiled NDJSON.command-contract.md,architecture.md,dashboards/README.md,targets/kibana.md,sources/grafana.md,sources/datadog.mdupdated so compilation is documented as opt-in; YAML lint always runs, compiled-layout validation only runs when compilation runs.Side effects considered
not_run, neverfail; the Datadog Markdown summary no longer shows a false blocking verdict on default no-compile runs.--compile.obs-migrate compile/ the YAML→NDJSON path (tracked separately in Retire the bespoke YAML->NDJSON compile path once native Dashboards API coverage is proven #279); this is the incremental "make it lazy" step.Tests run
test_native_upload_default_skips_yaml_compile,--compile-without-upload,--upload --legacy-importauto-compile), unified--compileforwarding for both sources (incl. Datadog default-omit),parse_argsdefaults, report guards (compilation not run,compile_attempted), Datadog default no-compile summary, and doc-contract guards.pytest tests/ --ignore=tests/e2e/— pass (100%).ruff check .— pass.mypy— pass. Source-header + skill-mirror/structure checks — pass.Kibana visual verification
Ran the default command (
--upload --ensure-data-views, no--compile) against a local stack:[5/7] ... skipped (native Dashboards API upload consumes YAML directly...).Upload results: 1/1 dashboards uploaded successfully;dashboards/compiled/contained 0 files.