Signals and Receivers

Signals of the infrastructure app.

They are sent by the infrastructure services, smarter.apps.infrastructure.services, whichever cloud provider implements them, so that the platform can observe its infrastructure, e.g. to audit or meter the billable resources that it creates, without knowing which cloud it runs on. The sender is the service’s class.

Every signal has the arguments service, the name of the service, e.g. dns (see InfrastructureServiceNames), and provider, the name of the cloud provider, e.g. aws, plus those listed.

Resource signals also have resource_type, e.g. dns.zone, and resource_name, e.g. example.com, and resource_id once the provider has assigned one. The created and destroyed signals also have reconciled, which is True when the inventory (smarter.apps.infrastructure.services.inventory) records a resource that it found, or found gone, e.g. a node that the cluster’s autoscaler added, rather than one that a service created or destroyed.

Example:

from django.dispatch import receiver
from smarter.apps.infrastructure.signals import billable_resource_created

@receiver(billable_resource_created)
def meter(sender, service, provider, resource_type, resource_name, resource_id, **kwargs):
    ...
smarter.apps.infrastructure.signals.billable_resource_created = <django.dispatch.dispatcher.Signal object>

Sent after a service creates a resource that its provider bills for.

Arguments: service, provider, resource_type, resource_name, resource_id.

smarter.apps.infrastructure.signals.billable_resource_creating = <django.dispatch.dispatcher.Signal object>

Sent before a service creates a resource that its provider bills for, e.g. a DNS zone.

Arguments: service, provider, resource_type, resource_name.

smarter.apps.infrastructure.signals.billable_resource_destroyed = <django.dispatch.dispatcher.Signal object>

Sent after a service destroys a resource that its provider bills for.

Arguments: service, provider, resource_type, resource_name, resource_id.

smarter.apps.infrastructure.signals.billable_resource_destroying = <django.dispatch.dispatcher.Signal object>

Sent before a service destroys a resource that its provider bills for.

Arguments: service, provider, resource_type, resource_name, resource_id.

smarter.apps.infrastructure.signals.email_failed = <django.dispatch.dispatcher.Signal object>

Sent when an email cannot be sent.

Arguments: service, provider, subject (str), recipients (list[str]), error (str).

smarter.apps.infrastructure.signals.email_sent = <django.dispatch.dispatcher.Signal object>

Sent after an email is sent.

Arguments: service, provider, subject (str), recipients (list[str]).

smarter.apps.infrastructure.signals.infrastructure_authenticated = <django.dispatch.dispatcher.Signal object>

Sent when a provider authenticates with its cloud, the first time and after a failure.

Arguments: service, provider, identity (dict), the provider’s account identity, e.g. its account id.

smarter.apps.infrastructure.signals.infrastructure_authentication_failed = <django.dispatch.dispatcher.Signal object>

Sent when a provider cannot authenticate with its cloud, the first time and after a success.

Arguments: service, provider, error (str).

smarter.apps.infrastructure.signals.infrastructure_connected = <django.dispatch.dispatcher.Signal object>

Sent when a service connects to its backend, e.g. a Kubernetes cluster, or a cloud API.

Arguments: service, provider.

smarter.apps.infrastructure.signals.infrastructure_connection_failed = <django.dispatch.dispatcher.Signal object>

Sent when a service cannot connect to its backend.

Arguments: service, provider, error (str).

smarter.apps.infrastructure.signals.infrastructure_operation_failed = <django.dispatch.dispatcher.Signal object>

Sent when a service’s operation fails.

Arguments: service, provider, operation (str), e.g. apply_manifest, error (str).

smarter.apps.infrastructure.signals.resource_applied = <django.dispatch.dispatcher.Signal object>

Sent after Kubernetes resources are created or updated, from a manifest.

Arguments: service, provider, kinds (list[str]), the kinds of the manifest’s resources.

smarter.apps.infrastructure.signals.resource_created = <django.dispatch.dispatcher.Signal object>

Sent after a service creates, or updates, a resource that is not billed for on its own.

e.g. a DNS record, or a TLS certificate.

Arguments: service, provider, resource_type, resource_name, resource_id.

smarter.apps.infrastructure.signals.resource_destroyed = <django.dispatch.dispatcher.Signal object>

Sent after a service destroys a resource that is not billed for on its own.

Arguments: service, provider, resource_type, resource_name, resource_id.

Django Signal Receivers for the infrastructure app.

They log the infrastructure services’ signals, so that every change to the platform’s infrastructure is traceable, whichever cloud provider made it. Billable resources are logged at warning level, because they cost money, and failures at error level.

The resources that are created and destroyed are also recorded in the ledger, InfrastructureResource. A ledger that cannot be written is logged, and never fails the infrastructure operation.

smarter.apps.infrastructure.receivers.handle_billable_resource_created(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a billable resource was created, and record it in the ledger.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • resource_type – The resource’s type, e.g. dns.zone.

  • resource_name – The resource’s name, e.g. example.com.

  • resource_id – The resource’s cloud id, or None if the provider has not assigned one.

  • kwargs – The signal’s other arguments. reconciled is True when the inventory found the resource, or found it gone, rather than a service creating or destroying it.

smarter.apps.infrastructure.receivers.handle_billable_resource_creating(sender, service, provider, resource_type, resource_name, **kwargs)[source]

Log that a billable resource is about to be created.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • resource_type – The resource’s type, e.g. dns.zone.

  • resource_name – The resource’s name, e.g. example.com.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_billable_resource_destroyed(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a billable resource was destroyed, and record it in the ledger.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • resource_type – The resource’s type, e.g. dns.zone.

  • resource_name – The resource’s name, e.g. example.com.

  • resource_id – The resource’s cloud id, or None if the provider has not assigned one.

  • kwargs – The signal’s other arguments. reconciled is True when the inventory found the resource, or found it gone, rather than a service creating or destroying it.

smarter.apps.infrastructure.receivers.handle_billable_resource_destroying(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a billable resource is about to be destroyed.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • resource_type – The resource’s type, e.g. dns.zone.

  • resource_name – The resource’s name, e.g. example.com.

  • resource_id – The resource’s cloud id, or None if the provider has not assigned one.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_email_failed(sender, service, provider, subject=None, recipients=None, error=None, **kwargs)[source]

Log that an email could not be sent.

The recipients are logged masked, e.g. j****@example.com.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • subject – The email’s subject.

  • recipients – The email’s recipients.

  • error – Why it failed.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_email_sent(sender, service, provider, subject=None, recipients=None, **kwargs)[source]

Log that an email was sent.

The recipients are logged masked, e.g. j****@example.com.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • subject – The email’s subject.

  • recipients – The email’s recipients.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_infrastructure_authenticated(sender, service, provider, identity=None, **kwargs)[source]

Log that a provider authenticated with its cloud.

Only the last four characters of the cloud account id are logged. The id isn’t a secret, but job logs are emailed and shipped elsewhere, and the full id isn’t needed to tell accounts apart.

smarter.apps.infrastructure.receivers.handle_infrastructure_authentication_failed(sender, service, provider, error=None, **kwargs)[source]

Log that a provider could not authenticate with its cloud.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • error – Why it failed.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_infrastructure_connected(sender, service, provider, **kwargs)[source]

Log that a service connected to its backend.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_infrastructure_connection_failed(sender, service, provider, error=None, **kwargs)[source]

Log that a service could not connect to its backend.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • error – Why it failed.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_infrastructure_operation_failed(sender, service, provider, operation=None, error=None, **kwargs)[source]

Log that a service’s operation failed.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • operation – The operation that failed, e.g. apply_manifest.

  • error – Why it failed.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_resource_applied(sender, service, provider, kinds=None, **kwargs)[source]

Log that Kubernetes resources were applied.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • kinds – The kinds of the manifest’s resources, or None.

  • kwargs – The signal’s other arguments.

smarter.apps.infrastructure.receivers.handle_resource_created(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a resource was created or updated, and record it in the ledger.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • resource_type – The resource’s type, e.g. dns.zone.

  • resource_name – The resource’s name, e.g. example.com.

  • resource_id – The resource’s cloud id, or None if the provider has not assigned one.

  • kwargs – The signal’s other arguments. reconciled is True when the inventory found the resource, or found it gone, rather than a service creating or destroying it.

smarter.apps.infrastructure.receivers.handle_resource_destroyed(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a resource was destroyed, and record it in the ledger.

Parameters:
  • sender – The service’s class.

  • service – The service’s name, e.g. dns.

  • provider – The cloud provider’s name, e.g. aws.

  • resource_type – The resource’s type, e.g. dns.zone.

  • resource_name – The resource’s name, e.g. example.com.

  • resource_id – The resource’s cloud id, or None if the provider has not assigned one.

  • kwargs – The signal’s other arguments. reconciled is True when the inventory found the resource, or found it gone, rather than a service creating or destroying it.