-
Notifications
You must be signed in to change notification settings - Fork 138
Architecture Breakdown
FabricWorkspace Class:
- The orchestration layer of
fabric-cicd. It manages the deployment lifecycle – Retrieval, Processing, and Deploying -
Retrieval:
- In this stage, the class retrieves the metadata of items and folders (repository and workspace), the parameters necessary for managing item deployment.
- The retrieved information is stored into separate dictionaries:
repository_items,deployed_items,repository_folders,deployed_folders, andenvironment_parameter
-
Processing:
- In this stage, the class processes item source control files in preparation for deployment via the Fabric REST APIs. This step is key to ensuring the item payload is valid for making a call to the item definition APIs
- Various file processing can take place including custom file processing (defined per item type), replacement of logical Ids, replacement of parameterized values, and replacement of default workspace ids
- Note: the only file that cannot be modified during processing is the
.platformfile to maintain item integrity
-
Deploying:
- In this stage, the Fabric Workspace Class performs publish/unpublish operation on each Fabric item through an API call which defines the actual deployment
Deployment Operations:
Deployment is coordinated through 2 kinds of operations: publishing and unpublishing. These operations are orchestrated by functions defined in publish.py.
publish.py contains 3 user-facing functions:
publish_all_items()unpublish_all_orphan_items()-
deploy_with_config()(a wrapper of the first 2 functions)
The specific order of Fabric item types during publish/unpublish is defined logically in the publish_all_items() and unpublish_all_orphan_items(), based on dependencies that exist between item types.
Item Dependency Management:
Types of Dependencies:
- Dependencies between item types, ex: Notebook dependent on Environment
- Dependencies within item types, ex: Pipeline dependent on Pipeline
Dependency Management during Deployment:
- Publish case:
- Item types published according to logical order of
publish_{itemtype-plural}()functions called inpublish_all_items() - Within item type, logic sits at item level (
publish_{itemtype-plural}()) to sort specific items within the given type.
- Item types published according to logical order of
- Unpublish case:
- Item types unpublished according to ordered list defined in
unpublish_all_orphan_items()(reverse order of the order set inpublish_all_items()) - Within item type, sorting based on dependencies is also managed within the
unpublish_all_orphan_items()function.
- Item types unpublished according to ordered list defined in
Constants:
- The constants file is where constants are centrally defined and used across various files including the
FabricWorkspaceandParameterclasses - The type of constants includes lists, regex patterns, dictionaries, strings
- Users have the option to override a constant value for a deployment instance
- The library version number is also defined in
constants.py
Changelog:
- The
changelog.mdfile is a markdown file that contains the change updates per release - Specific emojis are used to categorize the specific change
- Under the title which includes the release version and release date, the listed changes include a link to the associated GitHub issue
API Management:
-
FabricEndpointclass is the communication layer between fabric-cicd and Microsoft Fabric’s REST APIs - It handles
HTTPrequests to Fabric and manages authentication, retries, errors, and long-running operations automatically. Includes comprehensive logging. - Authentication Management:
- Uses the
azure-identitylibrary to manage the actual authentication whileFabricEndpointhandles Azure AD token acquisition, token expiration, and token refresh.
- Uses the
- Resilience:
- Fabric Endpoint includes retry logic, throttling handling, and error recovery.
- Long-Running Operations:
- Polls asynchronous operations until completion, specifically polling the location header URL with GET operation requests, checks the status (succeeded, failed, running) until completion.
- Comprehensive Logging:
- Provides detailed debug information for troubleshooting by printing API requests and responses to the terminal and also adds API traces to an error log file that gets created during each deployment run.
- Flow:
- The
FabricEndpointobject gets created within theFabricWorkspaceclass. The endpoint object then uses the passed in AzureTokenCredentialobject (upn,spn,mi) to authenticate when running the APIs. - Initialization:
- Stores the Azure
TokenCredentialobject (upn,spn,mi, etc.) - Immediately acquires an access token via
_refresh_token()method - Sets up the
requestsmodule - Initializes the
aad_token– the actual Bearer token sent with API requests,aad_token_expiration– when the token expires (automatically refreshed),token_credential– Azure credential object (from theazure-identitylibrary).
- Stores the Azure
-
invoke()Method:- The core method of the class – the method that is called in
FabricWorkspaceand in other files whenever calling an API - The method invokes an API call/sends an
HTTPrequest to the specified URL using the provided API method and body, if applicable - Accepts other optional parameters and kwargs.
-
invoke()executes the following steps:- Request Loop:
- Supports operations with multiple
HTTPrequests (LRO)
- Supports operations with multiple
- Build Headers:
- Header gets passed into API call which specifies the type of file content in the request body (usually
JSONcontent, but option to set other forms)
- Header gets passed into API call which specifies the type of file content in the request body (usually
- Send Request:
- Sends the
HTTPrequest using the requests library
- Sends the
- Handle Response:
- Different kinds of responses are handled based on the status code including LRO (regular and unique case), throttling, token expiration. Performs retries which use exponential backoff
- Return Standardized Response:
- Returns a dictionary as the response with the header, body, and status code information which can be extracted
- Request Loop:
- The core method of the class – the method that is called in
- The
- Token Management:
- Automatic token refresh (called within the invoke method) and uses helper function to decode the actual token to get token information including expiration, executing identity (
upn,appid,oid)
- Automatic token refresh (called within the invoke method) and uses helper function to decode the actual token to get token information including expiration, executing identity (
- Response Handling:
- Various responses can be returned by the
HTTPrequests which require specific handling. For example:- Long-Running Operations (202):
- Without polling (special case) – parameter of
invoke()set to specifically not poll until completion but instead exit the request loop - With polling (default behavior) – polls until completion, uses the
GEToperation to check status
- Without polling (special case) – parameter of
- Throttling (429):
- Does a retry up to 5 attempts, with exponential backoff to avoid overwhelming the API
- Item Name Conflicts:
- Does a retry up to 5 attempts, with exponential backoff
- Authorization Errors:
- Raises an exception, resulting in deployment failure
- Long-Running Operations (202):
- Various responses can be returned by the
Configuration Deployment Management:
Logic that is called within the deploy_with_config() function used in the Configuration Deployment approach.
Configuration utilities:
- Contains various functions responsible for loading a validated
config.ymlfile to a Python dictionary, extracting the settings provided, and handling config value overrides
ConfigValidator class:
- A class responsible for the validation of user inputs provided in the
config.ymlfile - Validates the
YAMLcontents and returns a Python dictionary
Formatting, Logging, and Error Handling:
- Color:
- Color formatting defined and used in the console
- Logging:
- Includes logging utilities
- Defines different logging levels through specific formatting based on log type, e.g., debug (grey), error (red), info (white), warning (yellow)
- Custom Exceptions:
- Custom exceptions specially defined for
fabric-cicd - Used in error-handling
- Custom exceptions specially defined for
Item Metadata Management:
Item class:
- Used to store item metadata and process items during deployment
File class:
- Used to store file metadata and process source control files of a given item during deployment
Validation:
- Group of validation functions used to validate user input, such as
workspace id,repository directory,environment, etc. - Group of functions to check file types and library version
- A file defined per Fabric item type supported in
fabric-cicd - Used specifically in the publishing of items to a Fabric workspace
- Contains a wrapper publish function which accepts a
FabricWorkspaceobject and calls the_publish_item()method fromFabricWorkspaceclass - The file may include custom logic for special handling of the given item type during deployment (pre/post-processing)
- The wrapper functions of the item types are called within the
publish_all_items()function in a defined order
Supported Parameters:
find_replacekey_value_replacespark_poolsemantic_model_binding
Parameter Utilities:
- Group of varying functions used in the
FabricWorkspaceandParameterclasses - Functionalities include: parameter value extraction, parameter validation, and parameter processing
Parameter Validation:
- Validation is managed by the
Parameterclass - Responsible for loading the
parameter.ymlfile to a Python dictionary and validating its contents - Validation areas include: file existence, YAML syntax, load, structure, data types, specific parameters (names, key/values, specific properties), environment keys, optional filters
Advanced Features:
- Include using regex pattern for
find_value, variables forreplace_value, file filters, etc. - See documentation here
Parameter Templates:
- Use multiple parameter files and choose to apply or not apply during a deployment
- Splitting large parameter file into smaller files
- Reference parameter template paths within the main
parameter.ymlfile - See documentation here