sebs.azure package

Submodules

sebs.azure.azure module

Azure serverless platform implementation for SeBS benchmarking.

This module provides the Azure implementation of the SeBS serverless benchmarking system. It handles Azure Functions deployment, resource management, code packaging, and benchmark execution on Microsoft Azure.

Key features:
  • Azure Functions deployment and management

  • Azure Storage integration for code and data

  • CosmosDB support for NoSQL benchmarks

  • HTTP trigger configuration and invocation

  • Performance metrics collection via Application Insights

  • Resource lifecycle management

The main class Azure extends the base System class to provide Azure-specific functionality for serverless function benchmarking.

Example

Basic usage for Azure benchmarking:

from sebs.azure.azure import Azure
from sebs.azure.config import AzureConfig

# Initialize Azure system with configuration
azure_system = Azure(sebs_config, azure_config, cache, docker_client, handlers)
azure_system.initialize()

# Deploy and benchmark functions
function = azure_system.create_function(code_package, func_name, False, "")
result = function.invoke(payload)
class sebs.azure.azure.Azure(sebs_config: SeBSConfig, config: AzureConfig, cache_client: Cache, docker_client: DockerClient, logger_handlers: LoggingHandlers)[source]

Bases: System

Azure serverless platform implementation.

This class implements the Azure-specific functionality for the SeBS benchmarking suite. It handles Azure Functions deployment, resource management, and benchmark execution on Microsoft Azure platform.

logs_client

Azure logs client (currently unused)

storage

BlobStorage instance for Azure Blob Storage operations

Type:

sebs.azure.blob_storage.BlobStorage

cached

Flag indicating if resources are cached

Type:

bool

_config

Azure configuration containing credentials and resources

Type:

sebs.azure.config.AzureConfig

AZURE_RUNTIMES

Mapping of language names to Azure runtime identifiers

AZURE_RUNTIMES = {'java': 'java', 'nodejs': 'node', 'python': 'python'}
allocate_shared_resource() None[source]

Allocate shared data storage account.

Creates or retrieves the shared data storage account used for benchmark input/output data. This allows multiple deployment clients to share the same storage, simplifying regression testing.

cached: bool = False
cached_function(function: Function) None[source]

Initialize cached function with current configuration.

Sets up a cached function with current data storage account and logging handlers for all triggers.

Parameters:

function – Function instance loaded from cache

property cli_instance: AzureCLI

Get Azure CLI instance.

Returns:

Azure CLI instance for executing Azure commands.

property config: AzureConfig

Get Azure configuration.

Returns:

Azure configuration containing credentials and resources.

create_function(code_package: Benchmark, func_name: str, container_deployment: bool, container_uri: str | None) AzureFunction[source]

Create new Azure Function.

Creates a new Azure Function App and deploys the provided code package. Handles function app creation, storage account allocation, and initial deployment with proper configuration.

Parameters:
  • code_package – Benchmark code package to deploy

  • func_name – Name for the Azure Function App

  • container_deployment – Whether to use container deployment

  • container_uri – Container URI (unused for Azure)

Returns:

AzureFunction instance representing the created function.

Raises:
  • NotImplementedError – If container deployment is requested.

  • RuntimeError – If function creation fails.

create_trigger(function: Function, trigger_type: TriggerType) Trigger[source]

Create trigger for Azure Function.

Currently not implemented as HTTP triggers are automatically created for each function during deployment.

Parameters:
  • function – Function to create trigger for

  • trigger_type – Type of trigger to create

Raises:

NotImplementedError – Trigger creation is not supported.

default_function_name(code_package: Benchmark, resources: Resources | None = None) str[source]

Generate default function name for Azure.

Creates a globally unique function name based on resource ID, benchmark name, language, and version. Function app names must be globally unique across all of Azure.

Parameters:
  • code_package – Benchmark code package

  • resources – Optional resources (unused)

Returns:

Globally unique function name for Azure.

download_metrics(function_name: str, start_time: int, end_time: int, requests: Dict[str, ExecutionResult], metrics: Dict[str, dict]) None[source]

Download execution metrics from Azure Application Insights.

Retrieves performance metrics for function executions from Azure Application Insights and updates the execution results with provider-specific timing information.

Parameters:
  • function_name – Name of the Azure Function

  • start_time – Start timestamp for metrics collection

  • end_time – End timestamp for metrics collection

  • requests – Dictionary of execution results to update

  • metrics – Additional metrics dictionary (unused)

enforce_cold_start(functions: List[Function], code_package: Benchmark) None[source]

Enforce cold start for multiple functions.

Forces cold start behavior for all provided functions by updating environment variables and waiting for changes to propagate: sleep is added to allow changes to propagate.

Parameters:
  • functions – List of functions to enforce cold start for

  • code_package – Benchmark code package

find_deployments() List[str][source]

Find existing SeBS deployments by scanning resource groups.

Looks for Azure resource groups matching the SeBS naming pattern - sebs_resource_group_(.*) - to identify existing deployments that can be reused.

Returns:

List of deployment identifiers found in resource groups.

static function_type() Type[Function][source]

Get the function type for Azure.

Returns:

AzureFunction class type.

initialize(config: Dict[str, str] = {}, resource_prefix: str | None = None) None[source]

Initialize Azure system and start CLI container.

Initializes Azure resources and allocates shared resources like data storage account. Starts the Docker container with Azure CLI tools.

Parameters:
  • config – Additional configuration parameters

  • resource_prefix – Optional prefix for resource naming

logs_client = None
static name() str[source]

Get the platform name.

Returns:

Platform name ‘azure’.

package_code(directory: str, language: Language, language_version: str, architecture: str, benchmark: str, is_cached: bool) Tuple[str, int][source]

Package function code for Azure Functions deployment.

Creates the proper directory structure and configuration files required for Azure Functions deployment. The structure includes: - handler/ directory with source files and Azure wrappers - function.json with trigger and binding configuration - host.json with runtime configuration - requirements.txt or package.json with dependencies

Parameters:
  • directory – Directory containing the function code

  • language – Programming language (python, nodejs)

  • language_version – Language runtime version

  • architecture – Target architecture (currently unused)

  • benchmark – Name of the benchmark

  • is_cached – Whether the package is from cache

  • container_deployment – Whether to use container deployment

Returns:

Tuple of (directory_path, code_size_bytes, container_uri)

publish_function(function: Function, code_package: Benchmark, container_dest: str, repeat_on_failure: bool = False) str[source]

Publish function code to Azure Functions.

Deploys the packaged function code to Azure Functions using the Azure Functions CLI tools. Handles retries and URL extraction. Will repeat on failure, which is useful to handle delays in Azure cache updates - it can take between 30 and 60 seconds.

Parameters:
  • function – Function instance to publish

  • code_package – Benchmark code package to deploy

  • container_dest – Destination path in the CLI container

  • repeat_on_failure – Whether to retry on failure

Returns:

URL for invoking the published function.

Raises:

RuntimeError – If function publication fails or URL cannot be found.

shutdown() None[source]

Shutdown Azure system and cleanup resources.

Stops the Azure CLI container and performs cleanup of system resources.

storage: BlobStorage
update_envs(function: Function, code_package: Benchmark, env_variables: dict = {}) None[source]

Update environment variables for Azure Function.

Sets up environment variables required for benchmark execution, including storage connection strings and NoSQL database credentials. Preserves existing environment variables while adding new ones.

Parameters:
  • function – Function instance to update

  • code_package – Benchmark code package with requirements

  • env_variables – Additional environment variables to set

Raises:

RuntimeError – If environment variable operations fail.

update_function(function: Function, code_package: Benchmark, container_deployment: bool, container_uri: str | None) None[source]

Update existing Azure Function with new code.

Updates an existing Azure Function with new code package, including environment variables and function configuration. It also ensures an HTTP trigger is correctly associated with the function’s URL.

Parameters:
  • function – Function instance to update

  • code_package – New benchmark code package

  • container_deployment – Whether using container deployment

  • container_uri – Container URI (unused for Azure)

Raises:

NotImplementedError – If container deployment is requested.

update_function_configuration(function: Function, code_package: Benchmark) None[source]

Update Azure Function configuration.

Currently not implemented for Azure Functions as memory and timeout configuration is handled at the consumption plan level.

Parameters:
  • function – Function instance to configure

  • code_package – Benchmark code package with requirements

sebs.azure.blob_storage module

Azure Blob Storage implementation for SeBS benchmarking.

This module provides Azure Blob Storage integration for the SeBS benchmarking suite. It handles container management, file uploads/downloads, and storage operations required for serverless function benchmarking.

The BlobStorage class implements the PersistentStorage interface to provide Azure-specific storage operations including container creation, file management, and cleanup operations.

Example

Basic usage for Azure Blob Storage:

from sebs.azure.blob_storage import BlobStorage

# Initialize with connection string
storage = BlobStorage(region, cache, resources, connection_string, False)

# Upload benchmark data
storage.upload(container_name, filepath, key)
# Download results
storage.download(container_name, key, local_filepath)
class sebs.azure.blob_storage.BlobStorage(region: str, cache_client: Cache, resources: Resources, conn_string: str, replace_existing: bool)[source]

Bases: PersistentStorage

Azure Blob Storage implementation for benchmark data management.

This class provides Azure Blob Storage operations for storing and retrieving benchmark input data, function outputs, and temporary files. It manages containers (equivalent to S3 buckets) and handles file operations with proper error handling and logging.

client

Azure Blob Service client for storage operations

clean_bucket(bucket: str) None[source]

Clean all blobs from Azure Blob Storage container.

Removes all blobs from the specified container but keeps the container itself.

Parameters:

bucket – Name of the container to clean

correct_name(name: str) str[source]

Correct container name for Azure requirements.

Azure Blob Storage does not allow dots in container names, so they are replaced with hyphens.

Parameters:

name – Original container name

Returns:

Corrected container name with dots replaced by hyphens.

static deployment_name() str[source]

Get the deployment platform name.

Returns:

Platform name ‘azure’.

download(container_name: str, key: str, filepath: str) None[source]

Download file from Azure Blob Storage.

Downloads a blob from the specified container to a local file.

Parameters:
  • container_name – Name of the Azure Blob Storage container

  • key – Blob key/name in the container

  • filepath – Local file path to save the downloaded content

exists_bucket(container: str) bool[source]

Check if Azure Blob Storage container exists.

Parameters:

container – Name of the container to check

Returns:

True if container exists, False otherwise.

list_bucket(container: str, prefix: str = '') List[str][source]

List files in Azure Blob Storage container.

Returns list of blob names in the specified container, optionally filtered by prefix.

Parameters:
  • container – Name of the container to list

  • prefix – Optional prefix to filter blob names

Returns:

List of blob names. Empty list if container is empty.

list_buckets(bucket_name: str | None = None) List[str][source]

List Azure Blob Storage containers.

Lists all containers or those matching a prefix.

Parameters:

bucket_name – Optional prefix to filter container names

Returns:

List of container names.

remove_bucket(bucket: str) None[source]

Remove Azure Blob Storage container.

Deletes the entire container and all its contents.

Parameters:

bucket – Name of the container to remove

static typename() str[source]

Get the storage type name.

Returns:

Storage type identifier for Azure Blob Storage.

upload(container_name: str, filepath: str, key: str) None[source]

Upload file to Azure Blob Storage.

Uploads a local file to the specified container with the given key.

Parameters:
  • container_name – Name of the Azure Blob Storage container

  • filepath – Local file path to upload

  • key – Blob key/name in the container

uploader_func(container_idx: int, file: str, filepath: str) None[source]

Upload file to Azure Blob Storage container.

Uploads a file to the specified container with proper path handling and duplicate checking.

Parameters:
  • container_idx – Index of the container for file organization

  • file – Name of the file being uploaded

  • filepath – Local path to the file to upload

sebs.azure.cli module

Azure CLI Docker container management for SeBS benchmarking.

This module provides a wrapper around the Azure CLI running in a Docker container. It handles container lifecycle, command execution, file uploads, and Azure-specific operations required for serverless function deployment and management.

The AzureCLI class manages a Docker container with Azure CLI tools and provides methods for executing Azure commands, uploading function packages, and handling authentication.

Example

Basic usage for Azure CLI operations:

from sebs.azure.cli import AzureCLI

# Initialize CLI container
cli = AzureCLI(system_config, docker_client)

# Login to Azure
cli.login(app_id, tenant, password)
# Execute Azure CLI commands
result = cli.execute("az group list")

# Upload function package
cli.upload_package(local_dir, container_dest)
class sebs.azure.cli.AzureCLI(system_config: SeBSConfig, docker_client: DockerClient)[source]

Bases: LoggingBase

Azure CLI Docker container wrapper.

This class manages a Docker container running Azure CLI tools and provides methods for executing Azure commands, handling authentication, and managing file transfers for serverless function deployment.

docker_instance

Docker container running Azure CLI

_insights_installed

Flag indicating if Application Insights extension is installed

execute(cmd: str) bytes[source]

Execute Azure CLI command in Docker container.

Executes the given command in the Azure CLI container and returns the output. Raises an exception if the command fails.

Parameters:

cmd – Azure CLI command to execute

Returns:

Command output as bytes.

Raises:

RuntimeError – If command execution fails.

install_insights() None[source]

Install Azure Application Insights CLI extension.

Installs the Application Insights extension for Azure CLI if not already installed. Required for metrics collection.

login(appId: str, tenant: str, password: str) bytes[source]

Login to Azure using service principal credentials.

Authenticates with Azure using service principal credentials within the Docker container.

Parameters:
  • appId – Azure application (client) ID

  • tenant – Azure tenant (directory) ID

  • password – Azure client secret

Returns:

Login command output as bytes.

shutdown() None[source]

Shutdown Azure CLI Docker container.

Stops and removes the Docker container running Azure CLI tools.

static typename() str[source]

Get the CLI type name.

Returns:

Type identifier for Azure CLI.

upload_package(directory: str, dest: str) None[source]

Upload function package to Docker container.

Creates a compressed archive of the function package and uploads it to the specified destination in the Docker container.

Note

This implementation loads the entire archive into memory, This is an inefficient and memory-intensive implementation. So far, we didn’t have very large functions that require many gigabytes. docker-py does not support a straightforward copy and we can’t call put_archive with chunks.

For large packages, there are two potential solutions: (1) manually call docker cp and decompress (2) commit the docker container and restart with a new mounted volume.

Parameters:
  • directory – Local directory containing function package

  • dest – Destination path in the Docker container

sebs.azure.cloud_resources module

Azure cloud resource management for SeBS.

This module manages deployed special resources in Azure cloud, particularly CosmosDB accounts that require special handling for authentication and configuration management.

class sebs.azure.cloud_resources.CosmosDBAccount(account_name: str, url: str, credential: str)[source]

Bases: object

Azure CosmosDB account configuration and management.

Manages CosmosDB account information including account name, endpoint URL, and authentication credentials. Provides methods for querying account details from Azure and serialization for caching.

_account_name

Name of the CosmosDB account

Type:

str

_url

Document endpoint URL for the account

Type:

str

_credential

Primary master key for authentication

Type:

str

property account_name: str

Get the CosmosDB account name.

Returns:

The name of the CosmosDB account.

Return type:

str

property credential: str

Get the CosmosDB authentication credential.

Returns:

The primary master key for CosmosDB authentication.

Return type:

str

static deserialize(obj: Dict[str, str]) CosmosDBAccount[source]

Deserialize CosmosDB account configuration from dictionary.

Parameters:

obj (Dict[str, str]) – Dictionary containing account configuration with required keys: account_name, url, credential

Returns:

New instance with deserialized configuration.

Return type:

CosmosDBAccount

Raises:

KeyError – If required keys are missing from the dictionary.

static from_allocation(account_name: str, resource_group: str, cli_instance: AzureCLI, url: str | None = None) CosmosDBAccount[source]

Create CosmosDB account instance by querying Azure.

Queries Azure CLI to retrieve account configuration including endpoint URL and authentication credentials.

Parameters:
  • account_name (str) – Name of the CosmosDB account

  • resource_group (str) – Azure resource group containing the account

  • cli_instance (AzureCLI) – Azure CLI instance for executing commands

  • url (Optional[str]) – Pre-known URL, if None will query from Azure

Returns:

New instance with queried configuration.

Return type:

CosmosDBAccount

static from_cache(account_name: str, url: str, credential: str) CosmosDBAccount[source]

Create CosmosDB account instance from cached data.

Parameters:
  • account_name (str) – Name of the CosmosDB account

  • url (str) – Document endpoint URL for the account

  • credential (str) – Primary master key for authentication

Returns:

New instance with provided configuration.

Return type:

CosmosDBAccount

static query_credentials(account_name: str, resource_group: str, cli_instance: AzureCLI) str[source]

Query CosmosDB account authentication credentials from Azure.

Uses Azure CLI to retrieve the primary master key for the specified CosmosDB account.

Parameters:
  • account_name (str) – Name of the CosmosDB account

  • resource_group (str) – Azure resource group containing the account

  • cli_instance (AzureCLI) – Azure CLI instance for executing commands

Returns:

The primary master key for CosmosDB authentication.

Return type:

str

Raises:
  • RuntimeError – If Azure CLI command fails.

  • KeyError – If the expected response structure is not found.

static query_url(account_name: str, resource_group: str, cli_instance: AzureCLI) str[source]

Query CosmosDB account endpoint URL from Azure.

Uses Azure CLI to retrieve the document endpoint URL for the specified CosmosDB account.

Parameters:
  • account_name (str) – Name of the CosmosDB account

  • resource_group (str) – Azure resource group containing the account

  • cli_instance (AzureCLI) – Azure CLI instance for executing commands

Returns:

The document endpoint URL for the CosmosDB account.

Return type:

str

Raises:
  • RuntimeError – If Azure CLI command fails.

  • KeyError – If the expected response structure is not found.

serialize() Dict[str, str][source]

Serialize CosmosDB account configuration to dictionary.

Returns:

Dictionary containing account configuration with keys:
  • account_name: The CosmosDB account name

  • url: The document endpoint URL

  • credential: The primary master key

Return type:

Dict[str, str]

property url: str

Get the CosmosDB document endpoint URL.

Returns:

The document endpoint URL for the CosmosDB account.

Return type:

str

sebs.azure.config module

Configuration management for Azure serverless benchmarking.

This module provides configuration classes for Azure resources, credentials, and deployment settings. It handles Azure-specific configuration including service principal authentication, resource group management, storage accounts, and CosmosDB setup.

Key classes:

AzureCredentials: Manages Azure service principal authentication AzureResources: Manages Azure resource allocation and lifecycle AzureConfig: Combines credentials and resources for Azure deployment

class sebs.azure.config.AzureConfig(credentials: AzureCredentials, resources: AzureResources)[source]

Bases: Config

Complete Azure configuration for SeBS benchmarking.

Combines Azure credentials and resources into a single configuration object for managing Azure serverless function deployments.

_credentials

Azure service principal credentials

_resources

Azure resource management instance

property credentials: AzureCredentials

Get Azure credentials.

Returns:

AzureCredentials instance for authentication.

static deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) Config[source]

Deserialize complete Azure configuration.

Creates AzureConfig instance from configuration dictionary and cache, combining credentials and resources with region information.

Parameters:
  • config – Configuration dictionary

  • cache – Cache instance for storing/retrieving cached values

  • handlers – Logging handlers for error reporting

Returns:

AzureConfig instance with complete Azure configuration.

static initialize(cfg: Config, dct: dict) None[source]

Initialize configuration from dictionary data.

Parameters:
  • cfg – Config instance to initialize

  • dct – Dictionary containing configuration data

property resources: AzureResources

Get Azure resources manager.

Returns:

AzureResources instance for resource management.

serialize() dict[source]

Serialize complete configuration to dictionary.

Returns:

Dictionary containing all Azure configuration data.

update_cache(cache: Cache) None[source]

Update complete configuration in cache.

Persists region, credentials, and resources to filesystem cache.

Parameters:

cache – Cache instance for storing configuration

class sebs.azure.config.AzureCredentials(appId: str, tenant: str, password: str, subscription_id: str | None = None)[source]

Bases: Credentials

Azure service principal credentials for authentication.

This class manages Azure service principal credentials required for authenticating with Azure services. It handles app ID, tenant ID, password, and subscription ID validation and caching.

_appId

Azure application (client) ID

Type:

str

_tenant

Azure tenant (directory) ID

Type:

str

_password

Azure client secret

Type:

str

_subscription_id

Azure subscription ID (optional)

Type:

str | None

property appId: str

Get the Azure application (client) ID.

Returns:

Azure application ID string.

static deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) Credentials[source]

Deserialize credentials from config and cache.

Loads Azure credentials from either the configuration dictionary or environment variables, with subscription ID retrieved from cache.

Parameters:
  • config – Configuration dictionary

  • cache – Cache instance for storing/retrieving cached values

  • handlers – Logging handlers for error reporting

Returns:

AzureCredentials instance with loaded configuration.

Raises:

RuntimeError – If no valid credentials are found in config or environment.

property has_subscription_id: bool

Check if subscription ID is set.

Returns:

True if subscription ID is set, False otherwise.

static initialize(dct: dict, subscription_id: str | None) AzureCredentials[source]

Initialize credentials from dictionary.

Parameters:
  • dct – Dictionary containing credential information

  • subscription_id – Optional subscription ID to set

Returns:

New AzureCredentials instance.

property password: str

Get the Azure client secret.

Returns:

Azure client secret string.

serialize() dict[source]

Serialize credentials to dictionary.

We store only subscription ID to avoid unsecure storage of sensitive data.

Returns:

Dictionary containing serialized credential data.

property subscription_id: str

Get the Azure subscription ID.

Returns:

Azure subscription ID string.

Raises:

AssertionError – If subscription ID is not set.

property tenant: str

Get the Azure tenant (directory) ID.

Returns:

Azure tenant ID string.

update_cache(cache_client: Cache) None[source]

Update credentials in cache.

Parameters:

cache_client – Cache instance to update

class sebs.azure.config.AzureResources(resource_group: str | None = None, storage_accounts: List[Storage] | None = None, data_storage_account: Storage | None = None, cosmosdb_account: CosmosDBAccount | None = None)[source]

Bases: Resources

Azure resource management for SeBS benchmarking.

This class manages Azure cloud resources including storage accounts, resource groups, and CosmosDB accounts.

_resource_group

Name of the Azure resource group

_storage_accounts

List of storage accounts for function code

_data_storage_account

Storage account for benchmark data

_cosmosdb_account

CosmosDB account for NoSQL storage

class Storage(account_name: str, connection_string: str)[source]

Bases: object

Azure Storage Account wrapper.

Represents an Azure Storage Account with connection details for use in serverless function deployment and data storage.

account_name

Name of the Azure storage account

connection_string

Connection string for accessing the storage account

static deserialize(obj: dict) Storage[source]

Deserialize storage account from dictionary.

Parameters:

obj – Dictionary containing storage account data

Returns:

New Storage instance from dictionary data.

static from_allocation(account_name: str, cli_instance: AzureCLI) Storage[source]

Create Storage instance from newly allocated account.

Parameters:
  • account_name – Name of the storage account

  • cli_instance – Azure CLI instance for querying connection string

Returns:

New Storage instance with queried connection string.

static from_cache(account_name: str, connection_string: str) Storage[source]

Create Storage instance from cached data.

Parameters:
  • account_name – Name of the storage account

  • connection_string – Connection string for the account

Returns:

New Storage instance with the provided details.

Raises:

AssertionError – If connection string is empty.

static query_connection_string(account_name: str, cli_instance: AzureCLI) str[source]

Query connection string for storage account from Azure.

Parameters:
  • account_name – Name of the storage account

  • cli_instance – Azure CLI instance for executing queries

Returns:

Connection string for the storage account.

serialize() dict[source]

Serialize storage account to dictionary.

Returns:

Dictionary containing storage account information.

add_storage_account(cli_instance: AzureCLI) Storage[source]

Create new storage account for function code.

Creates a new storage account with a UUID-based name for storing function code packages and adds it to the managed accounts list.

Parameters:

cli_instance – Azure CLI instance for storage operations

Returns:

New Storage instance for function code storage.

cosmosdb_account(cli_instance: AzureCLI) CosmosDBAccount[source]

Get or create CosmosDB account for NoSQL storage.

Finds existing CosmosDB account or creates a new serverless one. Account names must be globally unique across Azure.

Parameters:

cli_instance – Azure CLI instance for CosmosDB operations

Returns:

CosmosDBAccount instance for NoSQL operations.

Raises:

RuntimeError – If CosmosDB account creation or parsing fails.

data_storage_account(cli_instance: AzureCLI) Storage[source]

Get or create storage account for benchmark data.

Retrieves existing or creates new storage account dedicated to storing benchmark input/output data. This is separate from function code storage.

Parameters:

cli_instance – Azure CLI instance for storage operations

Returns:

Storage instance for benchmark data operations.

delete_resource_group(cli_instance: AzureCLI, name: str, wait: bool = True) None[source]

Delete Azure resource group.

Removes the specified resource group and all contained resources.

Parameters:
  • cli_instance – Azure CLI instance for executing deletion

  • name – Name of resource group to delete

  • wait – Whether to wait for deletion to complete

Raises:

RuntimeError – If resource group deletion fails.

static deserialize(config: dict, cache: Cache, handlers: LoggingHandlers) Resources[source]

Deserialize resources from config and cache.

Loads Azure resources from cache if available, otherwise from configuration. If no data is present, then we initialize an empty resources object.

Parameters:
  • config – Configuration dictionary

  • cache – Cache instance for retrieving cached values

  • handlers – Logging handlers for error reporting

Returns:

AzureResources instance with loaded configuration.

static initialize(res: Resources, dct: dict) None[source]

Initialize resources from dictionary data.

Populates resource instance with data from configuration dictionary.

Parameters:
  • res – Resources instance to initialize

  • dct – Dictionary containing resource configuration

list_cosmosdb_accounts(cli_instance: AzureCLI) Dict[str, str][source]

List existing CosmosDB accounts in resource group.

Queries for CosmosDB accounts matching the SeBS naming pattern.

Parameters:

cli_instance – Azure CLI instance for executing queries

Returns:

Dictionary mapping account names to document endpoints.

Raises:

RuntimeError – If Azure CLI response cannot be parsed.

list_resource_groups(cli_instance: AzureCLI) List[str][source]

List SeBS resource groups in the current region.

Queries Azure for existing resource groups that match the SeBS naming pattern.

Parameters:

cli_instance – Azure CLI instance for executing queries

Returns:

List of resource group names matching SeBS pattern.

Raises:

RuntimeError – If Azure CLI response cannot be parsed.

list_storage_accounts(cli_instance: AzureCLI) List[str][source]

List storage accounts in the resource group.

Queries for all storage accounts within the managed resource group.

Parameters:

cli_instance – Azure CLI instance for executing queries

Returns:

List of storage account names.

Raises:

RuntimeError – If Azure CLI response cannot be parsed.

resource_group(cli_instance: AzureCLI) str[source]

Get or create Azure resource group.

Locates existing resource group or creates a new one with UUID-based name. The resource group is used to contain all SeBS-related Azure resources.

Parameters:

cli_instance – Azure CLI instance for resource operations

Returns:

Name of the resource group.

serialize() dict[source]

Serialize resources to dictionary.

Returns:

Dictionary containing all resource configuration data.

set_region(region: str) None[source]

Set the Azure region for resource allocation.

Parameters:

region – Azure region name (e.g., ‘westus2’)

property storage_accounts: List[Storage]

Get list of storage accounts for function code.

Returns:

List of Storage instances for function deployment.

update_cache(cache_client: Cache) None[source]

Update resource configuration in cache.

Persists current resource state including storage accounts, data storage accounts, and resource groups to filesystem cache.

Parameters:

cache_client – Cache instance for storing configuration

sebs.azure.cosmosdb module

Azure CosmosDB integration for SeBS NoSQL benchmarking.

This module provides Azure CosmosDB integration for NoSQL benchmarks in the SeBS benchmarking suite. It handles database and container management, data operations, and resource lifecycle for NoSQL-based benchmarks.

The module includes:
  • BenchmarkResources: Dataclass for managing benchmark-specific resources

  • CosmosDB: Main class for CosmosDB operations and management

Example

Basic usage for CosmosDB operations:

from sebs.azure.cosmosdb import CosmosDB

# Initialize CosmosDB with account
cosmosdb = CosmosDB(cache, resources, cosmosdb_account)

# Set up benchmark database and containers
db_name = cosmosdb.benchmark_database("my-benchmark")
tables = cosmosdb.get_tables("my-benchmark")

# Perform operations
credentials = cosmosdb.credentials()
class sebs.azure.cosmosdb.BenchmarkResources(database: str, containers: List[str], database_client: DatabaseProxy | None = None)[source]

Bases: object

Resource container for benchmark-specific CosmosDB resources.

This dataclass holds the database and container names allocated for a specific benchmark, along with the database client proxy.

database

Name of the CosmosDB database

Type:

str

containers

List of container names for the benchmark

Type:

List[str]

database_client

CosmosDB database proxy (allocated dynamically)

Type:

azure.cosmos.database.DatabaseProxy | None

containers: List[str]
database: str
database_client: DatabaseProxy | None = None
static deserialize(config: dict) BenchmarkResources[source]

Deserialize benchmark resources from dictionary.

Parameters:

config – Dictionary containing resource configuration

Returns:

BenchmarkResources instance with restored configuration.

serialize() dict[source]

Serialize benchmark resources to dictionary.

Returns:

Dictionary containing database and container names.

class sebs.azure.cosmosdb.CosmosDB(cli: AzureCLI, cache_client: Cache, resources: AzureResources, region: str)[source]

Bases: NoSQLStorage

Azure CosmosDB implementation for NoSQL storage in SeBS benchmarking.

This class provides Azure CosmosDB integration for NoSQL benchmarks, handling database and container management, data operations, and resource lifecycle. It supports benchmark-specific database allocation and container creation with proper caching and error handling.

Azure CosmosDB has the following model: - Each benchmark gets its own database - Container names match benchmark table names directly - No table mappings are required - Partition keys are configured per container

_cli_instance

Azure CLI instance for CosmosDB operations

_resource_group

Name of Azure resource group containing CosmosDB

_benchmark_resources

Dict mapping benchmark names to their resources

_cosmos_client

CosmosDB client for database operations

_cosmosdb_account

CosmosDB account configuration and credentials

benchmark_database(benchmark: str) str[source]

Get database name for benchmark.

Parameters:

benchmark – Name of the benchmark

Returns:

Name of the CosmosDB database for the benchmark.

Raises:

KeyError – If benchmark resources are not allocated.

clear_table(name: str) str[source]

Clear all data from a table.

Parameters:

name – Name of the table to clear

Returns:

Name of the cleared table.

Raises:

NotImplementedError – This operation is not yet implemented.

cosmos_client() CosmosClient[source]

Get or create CosmosDB client.

Initializes the CosmosDB client using the account credentials. The client is cached after first initialization.

Returns:

CosmosClient instance for database operations.

create_table(benchmark: str, name: str, primary_key: str, _: str | None = None) str[source]

Create CosmosDB container for benchmark table.

Creates a new CosmosDB database and container for the benchmark if they don’t exist. Each benchmark gets its own database, and containers are created within that database for each table.

Parameters:
  • benchmark – Name of the benchmark

  • name – Name of the container/table to create

  • primary_key – Partition key field name for the container

  • _ – Unused parameter for compatibility with base class

Returns:

Name of the created container.

Raises:

CosmosResourceNotFoundError – If database or container operations fail.

credentials() Tuple[str, str, str][source]

Get CosmosDB account credentials.

Retrieves the account name, URL, and credential for CosmosDB access. Initializes the CosmosDB account if not already done.

Returns:

Tuple containing (account_name, url, credential) for CosmosDB access.

static deployment_name() str[source]

Get the deployment platform name.

Returns:

String identifier for Azure deployment.

get_tables(benchmark: str) Dict[str, str][source]

Get table mappings for benchmark.

Azure requires no table mappings since container names match benchmark table names directly.

Parameters:

benchmark – Name of the benchmark

Returns:

Empty dictionary as no mappings are needed for Azure CosmosDB.

has_tables(benchmark: str) bool[source]

Check if benchmark has allocated tables.

Parameters:

benchmark – Name of the benchmark to check

Returns:

True if benchmark has allocated resources, False otherwise.

remove_table(name: str) str[source]

Remove a table completely.

Parameters:

name – Name of the table to remove

Returns:

Name of the removed table.

Raises:

NotImplementedError – This operation is not yet implemented.

retrieve_cache(benchmark: str) bool[source]

Retrieve benchmark resources from cache.

Attempts to load cached benchmark resources including database and container information from the filesystem cache.

Parameters:

benchmark – Name of the benchmark to retrieve from cache

Returns:

True if cache was found and loaded, False otherwise.

static typename() str[source]

Get the storage type name.

Returns:

String identifier for Azure CosmosDB storage type.

update_cache(benchmark: str) None[source]

Update benchmark resources in cache.

Persists current benchmark resources including database and container information to the filesystem cache.

Parameters:

benchmark – Name of the benchmark to cache

write_to_table(benchmark: str, table: str, data: dict, primary_key: Tuple[str, str], secondary_key: Tuple[str, str] | None = None) None[source]

Write data to CosmosDB container.

Inserts data into the specified container with required key fields. CosmosDB requires both a partition key and an ‘id’ field for documents.

Parameters:
  • benchmark – Name of the benchmark

  • table – Name of the container/table

  • data – Dictionary data to insert

  • primary_key – Tuple of (key_name, key_value) for partition key

  • secondary_key – Tuple of (key_name, key_value) for document id

Raises:

AssertionError – If table name cannot be resolved or secondary_key is None.

sebs.azure.function module

Azure Function implementation for SeBS benchmarking.

The AzureFunction class extends the base Function class and adds one Azure-specific property: storage account associated with this function.

class sebs.azure.function.AzureFunction(name: str, benchmark: str, code_hash: str, function_storage: Storage, cfg: FunctionConfig)[source]

Bases: Function

Azure Function implementation.

function_storage

Azure Storage account used for function code storage

static deserialize(cached_config: dict) Function[source]

Deserialize function from cached configuration.

Recreates an AzureFunction instance from cached data including function configuration, storage account, and triggers.

Parameters:

cached_config – Dictionary containing cached function data

Returns:

AzureFunction instance with restored configuration.

Raises:

AssertionError – If unknown trigger type is encountered.

serialize() dict[source]

Serialize function to dictionary.

Returns:

Dictionary containing function data including Azure-specific storage.

sebs.azure.system_resources module

Azure system resources management for SeBS.

This module provides Azure-specific system resource management including storage accounts, CosmosDB instances, and Azure CLI management for serverless benchmark execution.

class sebs.azure.system_resources.AzureSystemResources(system_config: SeBSConfig, config: AzureConfig, cache_client: Cache, docker_client: DockerClient, logger_handlers: LoggingHandlers)[source]

Bases: SystemResources

Azure system resources manager for SeBS benchmarking.

Manages Azure-specific system resources including Blob Storage, CosmosDB for NoSQL operations, and Azure CLI for resource management. Handles authentication, resource initialization, and lifecycle management.

_logging_handlers

Logging configuration handlers

Type:

LoggingHandlers

_storage

Azure Blob Storage instance

Type:

Optional[BlobStorage]

_nosql_storage

Azure CosmosDB instance

Type:

Optional[CosmosDB]

_cli_instance

Azure CLI Docker container instance

Type:

Optional[AzureCLI]

_system_config

SeBS system configuration

Type:

SeBSConfig

_cli_instance_stop

Flag to control CLI instance lifecycle

Type:

bool

property cli_instance: AzureCLI

Get or create Azure CLI instance.

Creates and initializes Azure CLI Docker container if not already created. Handles authentication automatically on first access.

Returns:

Azure CLI instance for executing Azure commands.

Return type:

AzureCLI

property config: AzureConfig

Get the Azure configuration.

Returns:

Azure-specific configuration instance.

Return type:

AzureConfig

get_nosql_storage() CosmosDB[source]

Get or create Azure CosmosDB instance.

Creates and configures CosmosDB instance for NoSQL benchmark operations. Handles authentication and database/container creation as needed.

Requires Azure CLI instance in Docker.

Returns:

Azure CosmosDB instance for NoSQL operations.

Return type:

CosmosDB

get_storage(replace_existing: bool | None = None) BlobStorage[source]

Get or create Azure Blob Storage instance.

Requires Azure CLI instance in Docker to obtain storage account details.

Parameters:

replace_existing (Optional[bool]) – When True, replace existing files in input buckets. If None, defaults to False.

Returns:

Azure Blob Storage instance for benchmark data management.

Return type:

BlobStorage

initialize_cli(cli: AzureCLI, login: bool = False) None[source]

Initialize with existing Azure CLI instance.

Allows using an external Azure CLI instance instead of creating a new one. Useful for sharing CLI instances across multiple resource managers.

Parameters:
  • cli (AzureCLI) – External Azure CLI instance to use

  • login (bool) – Whether to perform login with this CLI instance. Defaults to False.

shutdown() None[source]

Shutdown Azure system resources.

Cleans up Azure CLI Docker container and other resources. Only shuts down CLI if it was created by this instance. Does not terminate CLI instance attached to the class.

static typename() str[source]

Get the system resources type name.

Returns:

Type identifier for Azure system resources.

Return type:

str

sebs.azure.triggers module

Azure Function triggers for SeBS benchmarking.

This module provides Azure-specific trigger implementations for invoking serverless functions.

Example

Basic usage for HTTP trigger:

from sebs.azure.triggers import HTTPTrigger

# Create HTTP trigger with function URL
trigger = HTTPTrigger(function_url, data_storage_account)

# Synchronous invocation
result = trigger.sync_invoke(payload)

# Asynchronous invocation
future = trigger.async_invoke(payload)
result = future.result()
class sebs.azure.triggers.AzureTrigger(data_storage_account: Storage | None = None)[source]

Bases: Trigger

Base class for Azure Function triggers.

This abstract base class provides common functionality for Azure Function triggers, including data storage account management for benchmark data handling.

FIXME: do we still need to know the data storage account?

_data_storage_account

Azure storage account for benchmark data

property data_storage_account: Storage

Get the data storage account.

Returns:

Azure storage account for benchmark data.

Raises:

AssertionError – If data storage account is not set.

class sebs.azure.triggers.HTTPTrigger(url: str, data_storage_account: Storage | None = None)[source]

Bases: AzureTrigger

HTTP trigger for Azure Functions.

This class implements HTTP-based invocation of Azure Functions, supporting both synchronous and asynchronous execution patterns for benchmarking.

url

HTTP endpoint URL for the Azure Function

async_invoke(payload: dict) Future[source]

Asynchronously invoke Azure Function via HTTP.

Submits function invocation to a thread pool for parallel execution.

Parameters:

payload – Dictionary payload to send to the function

Returns:

Future object that can be used to retrieve the result.

static deserialize(obj: dict) Trigger[source]

Deserialize trigger from dictionary.

Parameters:

obj – Dictionary containing trigger data

Returns:

HTTPTrigger instance with restored configuration.

serialize() dict[source]

Serialize trigger to dictionary.

Returns:

Dictionary containing trigger type and URL.

sync_invoke(payload: dict) ExecutionResult[source]

Synchronously invoke Azure Function via HTTP.

Sends HTTP request to the function endpoint and waits for response.

Parameters:

payload – Dictionary payload to send to the function

Returns:

ExecutionResult containing response data and timing information.

static trigger_type() TriggerType[source]

Get the trigger type.

Returns:

HTTP trigger type identifier.

Module contents

Azure integration package for SeBS benchmarking.

This package provides comprehensive Azure integration for the Serverless Benchmarking Suite (SeBS). It includes all necessary components for deploying, managing, and benchmarking serverless functions on Microsoft Azure.

Main Components:

Azure: Main system class for Azure platform integration AzureFunction: Azure Function representation and management AzureConfig: Configuration management for Azure credentials and resources BlobStorage: Azure Blob Storage integration for data management

The package handles:
  • Azure Functions deployment and lifecycle management

  • Azure Storage integration for benchmark data

  • CosmosDB support for NoSQL benchmarks

  • Resource group and subscription management

  • Azure CLI integration via Docker containers

  • Performance metrics collection via Application Insights

Example

Basic usage for Azure benchmarking:

from sebs.azure import Azure, AzureConfig

# Load configuration
config = AzureConfig.deserialize(config_dict, cache, handlers)

# Initialize Azure system
azure = Azure(sebs_config, config, cache, docker_client, handlers)
azure.initialize()

# Deploy and benchmark functions
function = azure.create_function(code_package, func_name, False, "")
result = function.invoke(payload)