Skip to content

Consistent Use of Context #642

@devigned

Description

@devigned

Is your feature request related to a problem?/Why is this needed
Much of the context usage in the project is ineffectual. For example, the Azure DiskClient.Get uses a context, but the context provided to the method is largely ineffectual. As you can see here, a call to AttachDisk first calls getContextWithCancel, which simply constructs a context.Background with cancelation. The cancellation is only called in a defer when calling AzureDisk.Get. The cancellation provides no benefit as a way of cancelling processing further down the tree of execution.

Describe the solution you'd like in detail
Context should be used to time bound execution hierarchies, and are best when they start from the root of execution. Perhaps, having a context started at the CLI entry point where OS signals are used to establish the initial lifespan of the root context.

Further, context should be exposed upward from any I/O dependent task. If a network request or any other long running activity is called, the context should be required and passed in from higher up in the call hierarchy.

Additional context
By setting a consistent approach to passing context, the application will also be able to be more easily instrumented with tracing. For example, Cluster API Provider Azure uses OpenTelemetry to create a distributed trace of the entire reconciliation loop for all resources, https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/8a44c6d6f7b394b7929c3ae5b0e79730609c6cf1/controllers/azurecluster_controller.go#L114-L120. This makes it super easy to observe what the operator is doing and provides insight when trying to diagnosis issues. In fact, in CAPZ, we are exporting the traces to Application Insights to visualize the running operator. We'd love to be able to something similar in Cloud Provider Azure.

/cc @craiglpeters

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/frozenIndicates that an issue or PR should not be auto-closed due to staleness.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions