Files
fabric-cicd/devtools/debug_trace_deployment.py
T
a34899bded Closes #1134 - Add Cosmos DB Database item type support (#1135)
## Summary

Onboards the **Cosmos DB Database** (CosmosDBDatabase) item type to
fabric-cicd. Closes #1134.

Cosmos DB in Fabric is currently in **preview**. The Fabric REST API
supports full definition deployment (`definition.json` + `.platform`)
and service principal authentication, satisfying the deployment and auth
eligibility gates. It is not yet listed in the item definition overview,
which is documented as a preview limitation.

## Changes

- **`constants.py`**
- Add `COSMOS_DB_DATABASE = "CosmosDBDatabase"` to the `ItemType` enum.
- Insert it early in `SERIAL_ITEM_PUBLISH_ORDER` (position 6, grouped
with other data sources) since it is a data source with potential
dependents and no upstream dependencies.
- Add `ENABLE_COSMOSDBDATABASE_UNPUBLISH` feature flag and
`UNPUBLISH_FLAG_MAPPING` entry to gate destructive deletion (deleting
the item destroys data).
- **`_items/_cosmosdbdatabase.py`** (new) — simple full-definition
`CosmosDBDatabasePublisher`.
- **`_items/_base_publisher.py`** — register the publisher in the
factory.
- **`tests/test_publish.py`** — add a publish test and extend the
unpublish feature-flag test.
- **`docs/reference/item_types.md`** — new Cosmos DB Database section.

## Follow-ups (require a live workspace, not in this PR)

- Add a real exported sample item under `sample/workspace/`.
- Regenerate `tests/fixtures/http_trace.json.gz` and add the type to
`tests/test_integration_publish.py`.
- Specialized parameterization, if any, TBD during integration testing.

## Validation

- `uv run python -c "from fabric_cicd import FabricWorkspace"` — import
OK
- `uv run pytest` — passing
- `uv run ruff format --check` / `uv run ruff check` — clean for changed
files

---------

Co-authored-by: Shira Sassoon <shirasassoon@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-23 13:03:28 +03:00

85 lines
2.5 KiB
Python

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Captures route traces from a live Fabric workspace deployment into a JSON GZIP trace file.
import gzip
import os
import shutil
import sys
from pathlib import Path
from azure.identity import AzureCliCredential
root_directory = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(root_directory / "src"))
import fabric_cicd
def main():
"""Capture HTTP trace while publishing all items to Fabric workspace."""
os.environ["FABRIC_CICD_HTTP_TRACE_ENABLED"] = "1"
os.environ["FABRIC_CICD_HTTP_TRACE_FILE"] = str(root_directory / "http_trace.json")
workspace_id = os.environ.get("FABRIC_WORKSPACE_ID")
if not workspace_id:
msg = "FABRIC_WORKSPACE_ID environment variable must be set"
raise ValueError(msg)
environment = "PPE"
repository_directory = str(root_directory / "sample" / "workspace")
item_type_in_scope = [
"CosmosDBDatabase",
"DataBuildToolJob",
"Dataflow",
"DataPipeline",
"Environment",
"Eventhouse",
"Eventstream",
"KQLDatabase",
"KQLQueryset",
"Lakehouse",
"Map",
"MirroredDatabase",
"MLExperiment",
"Notebook",
"Ontology",
"PaginatedReport",
"Reflex",
"Report",
"SemanticModel",
"SparkJobDefinition",
"SQLDatabase",
"VariableLibrary",
"Warehouse",
]
token_credential = AzureCliCredential()
for flag in ["enable_shortcut_publish", "continue_on_shortcut_failure"]:
fabric_cicd.append_feature_flag(flag)
target_workspace = fabric_cicd.FabricWorkspace(
workspace_id=workspace_id,
environment=environment,
repository_directory=str(repository_directory),
item_type_in_scope=item_type_in_scope,
token_credential=token_credential,
)
fabric_cicd.publish_all_items(target_workspace)
print("Publish completed successfully")
# The raw JSON trace file is very large; GZIP compress it generate a compact version
# that can be used by tests. The raw trace file is still left in place for
# debugging purposes.
#
trace_file = root_directory / "http_trace.json"
compressed_file = root_directory / "http_trace.json.gz"
with trace_file.open("rb") as f_in, gzip.open(compressed_file, "wb") as f_out:
shutil.copyfileobj(f_in, f_out)
print(f"Compressed trace file to {compressed_file}")
if __name__ == "__main__":
main()