dactor-discover-azure
Azure node discovery for the dactor distributed actor framework.
Discovery mechanisms
| Strategy | Struct | How it works |
|---|---|---|
| VMSS | VmssDiscovery |
Queries the Azure Instance Metadata Service (IMDS) to determine the current VM's VMSS, then lists all network interfaces in the scale set via the ARM API. |
| Azure Tags | AzureTagDiscovery |
Lists VMs with a specific tag key/value via the ARM API, then resolves their private IPs from the associated network interfaces. |
Both strategies implement the dactor::ClusterDiscovery trait.
How dactor uses discovery
The ClusterDiscovery trait provides a discover() method that returns peer node addresses. The dactor runtime uses this as follows:
- On startup: The runtime calls
discover()to find initial peers and connects to them viaAdapterCluster::connect(). - Periodic polling: The application is responsible for calling
discover()periodically (e.g., via a timer) to detect topology changes — new nodes joining or leaving the VMSS/cluster. - Diff and reconcile: Compare discovered peers with currently connected nodes. Connect to new peers, optionally disconnect removed ones.
- Events: The
ClusterEventEmitterfiresNodeJoined/NodeLeftevents that actors can subscribe to viaClusterEvents.
Example: polling loop
use HashSet;
use Duration;
let discovery = builder
.port
.build;
let mut known_peers: = new;
loop
Usage
VMSS discovery (auto-detect via IMDS)
use VmssDiscovery;
use ClusterDiscovery;
let discovery = builder
.port
.build;
let peers = discovery.discover.await?;
VMSS discovery (explicit config)
use VmssDiscovery;
let discovery = builder
.subscription_id
.resource_group
.vmss_name
.port
.use_imds
.build;
let peers = discovery.discover.await?;
Tag-based discovery
use AzureTagDiscovery;
use ClusterDiscovery;
let discovery = builder
.tag_key
.tag_value
.subscription_id
.port
.build;
let peers = discovery.discover.await?;
Azure RBAC / Managed Identity requirements
Both discovery strategies require a Managed Identity (system-assigned or user-assigned) with at least the Reader role on the relevant resources.
VMSS discovery
The Managed Identity needs:
Microsoft.Compute/virtualMachineScaleSets/read— to list VMSS instancesMicrosoft.Network/networkInterfaces/read— to read NIC IP configurations
The built-in Reader role covers both.
Tag-based discovery
The Managed Identity needs:
Microsoft.Compute/virtualMachines/read— to list VMs and their tagsMicrosoft.Network/networkInterfaces/read— to resolve NIC private IPs
Example role assignment (Azure CLI)
# Assign Reader role to the VMSS system-assigned identity on its own resource group
Instance Metadata Service (IMDS)
The Azure IMDS is a REST endpoint available at http://169.254.169.254 on every Azure VM. It provides information about the running instance without requiring authentication.
This crate uses IMDS to:
- Discover the current VM's identity — subscription ID, resource group, and VMSS name.
- Acquire a Managed Identity token — used to authenticate ARM API calls.
All IMDS requests include the Metadata: true header as required by Azure.
Environment variables
| Variable | Description |
|---|---|
DACTOR_VM_IP |
Override the current VM's private IP. |
AZURE_SUBSCRIPTION_ID |
Override the Azure subscription ID. |
AZURE_RESOURCE_GROUP |
Override the Azure resource group name. |
Helper functions vm_private_ip(), subscription_id(), and resource_group() read these variables.
License
MIT