Skip to content

Commit 6e004c6

Browse files
Remove existing guidance on health endpoint (#1617)
* Rewrote secrets management and health method sections Signed-off-by: Whit Waldo <[email protected]> * Update daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md Co-authored-by: Alice Gibbons <[email protected]> Signed-off-by: Whit Waldo <[email protected]> * Update daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md Co-authored-by: Alice Gibbons <[email protected]> Signed-off-by: Whit Waldo <[email protected]> * Update daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md Co-authored-by: Alice Gibbons <[email protected]> Signed-off-by: Whit Waldo <[email protected]> * Update daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md Co-authored-by: Alice Gibbons <[email protected]> Signed-off-by: Whit Waldo <[email protected]> * Update daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md Co-authored-by: Alice Gibbons <[email protected]> Signed-off-by: Whit Waldo <[email protected]> * Update daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md Co-authored-by: Alice Gibbons <[email protected]> Signed-off-by: Whit Waldo <[email protected]> * Update daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md Co-authored-by: Alice Gibbons <[email protected]> Signed-off-by: Whit Waldo <[email protected]> --------- Signed-off-by: Whit Waldo <[email protected]> Co-authored-by: Alice Gibbons <[email protected]>
1 parent 89168cf commit 6e004c6

File tree

1 file changed

+42
-41
lines changed
  • daprdocs/content/en/dotnet-sdk-docs/dotnet-client

1 file changed

+42
-41
lines changed

daprdocs/content/en/dotnet-sdk-docs/dotnet-client/_index.md

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,35 @@ await client.InvokeBindingAsync("send-email", "create", email);
174174
- For a full guide on output bindings visit [How-To: Use bindings]({{% ref howto-bindings.md %}}).
175175

176176
### Retrieve secrets
177+
Prior to retrieving secrets, it's important that the outbound channel be registered and ready or the SDK will be unable
178+
to communicate bidirectionally with the Dapr sidecar. The SDK provides a helper method intended to be used for this
179+
purpose called `CheckOutboundHealthAsync`. This isn't referring to outbound from the SDK to the runtime, so much as
180+
outbound from the Dapr runtime back into the client application using the SDK.
181+
182+
This method is simply opening a connection to the {{% ref health_api#wait-for-specific-health-check-against-outbound-path %}}
183+
endpoint in the Dapr Health API and evaluating the HTTP status code returned to determine the health of the endpoint
184+
as reported by the runtime.
185+
186+
It's important to note that this and the `WaitForSidecarAsync` methods perform nearly identical operations; `WaitForSidecarAsync`
187+
polls the `CheckOutboundHealthAsync` endpoint indefinitely until it returns a healthy status value. They are intended
188+
exclusively for situations like secrets or configuration retrieval. Using them in other scenarios will result in
189+
unintended behavior (e.g., the endpoint never being ready because there are no registered components that use an
190+
"outbound" channel).
191+
192+
This behavior will be changed in a future release and should only be relied on sparingly.
193+
177194

178195
{{< tabpane text=true >}}
179196

180197
{{% tab header="Multi-value-secret" %}}
181198

182199
```csharp
200+
// Get an instance of the DaprClient from DI
201+
var client = scope.GetRequiredService<DaprClient>();
202+
203+
// Wait for the outbound channel to be established - only use for this scenario and not generally
204+
await client.WaitForOutboundHealthAsync();
205+
183206
// Retrieve a key-value-pair-based secret - returns a Dictionary<string, string>
184207
var secrets = await client.GetSecretAsync("mysecretstore", "key-value-pair-secret");
185208
Console.WriteLine($"Got secret keys: {string.Join(", ", secrets.Keys)}");
@@ -190,6 +213,12 @@ Console.WriteLine($"Got secret keys: {string.Join(", ", secrets.Keys)}");
190213
{{% tab header="Single-value-secret" %}}
191214

192215
```csharp
216+
// Get an instance of the DaprClient from DI
217+
var client = scope.GetRequiredService<DaprClient>();
218+
219+
// Wait for the outbound channel to be established - only use for this scenario and not generally
220+
await client.WaitForOutboundHealthAsync();
221+
193222
// Retrieve a key-value-pair-based secret - returns a Dictionary<string, string>
194223
var secrets = await client.GetSecretAsync("mysecretstore", "key-value-pair-secret");
195224
Console.WriteLine($"Got secret keys: {string.Join(", ", secrets.Keys)}");
@@ -317,51 +346,23 @@ namespace LockService
317346

318347
## Sidecar APIs
319348
### Sidecar Health
320-
The .NET SDK provides a way to poll for the sidecar health, as well as a convenience method to wait for the sidecar to be ready.
321-
322-
#### Poll for health
323-
This health endpoint returns true when both the sidecar and your application are up (fully initialized).
324-
325-
```csharp
326-
var client = new DaprClientBuilder().Build();
327-
328-
var isDaprReady = await client.CheckHealthAsync();
329-
330-
if (isDaprReady)
331-
{
332-
// Execute Dapr dependent code.
333-
}
334-
```
349+
While the .NET SDK provides a way to poll for the sidecar health, it is not generally recommended that developer
350+
utilize this functionality unless they are explicitly using Dapr to also retrieve secrets or configuration values.
335351

336-
#### Poll for health (outbound)
337-
This health endpoint returns true when Dapr has initialized all its components, but may not have finished setting up a communication channel with your application.
352+
There are two methods available:
353+
- `CheckOutboundHealthAsync` which queries an outbound readiness endpoint in the Dapr Health API {{% ref health_api#wait-for-specific-health-check-against-outbound-path %}}
354+
for a successful HTTP status code and reports readiness based on this value.
355+
- `WaitForSidecarAsync` continuously polls `CheckOutboundHealthAsync` until it returns a successful status code.
338356

339-
This is best used when you want to utilize a Dapr component in your startup path, for instance, loading secrets from a secretstore.
340-
341-
```csharp
342-
var client = new DaprClientBuilder().Build();
357+
The "outbound" direction refers to the communication outbound from the Dapr runtime to your application. If your
358+
application doesn't use actors, secret management, configuration retrieval or workflows, the runtime will not attempt
359+
to create an outbound connection. This means that if your application takes a dependency on `WaitForSidecarAsync`
360+
without using any of these Dapr components, it will indefinitely lock up during startup as the endpoint will never be established.
343361

344-
var isDaprComponentsReady = await client.CheckOutboundHealthAsync();
362+
A future release will remove these methods altogether and perform this as an internal SDK operation, so neither
363+
method should be relied on in general. Reach out in the Discord #dotnet-sdk channel for more clarification as
364+
to whether your scenario may necessitate using this, but in most situations, these methods should not be required.
345365

346-
if (isDaprComponentsReady)
347-
{
348-
// Execute Dapr component dependent code.
349-
}
350-
```
351-
352-
#### Wait for sidecar
353-
The `DaprClient` also provides a helper method to wait for the sidecar to become healthy (components only). When using this method, it is recommended to include a `CancellationToken` to
354-
allow for the request to timeout. Below is an example of how this is used in the `DaprSecretStoreConfigurationProvider`.
355-
356-
```csharp
357-
// Wait for the Dapr sidecar to report healthy before attempting use Dapr components.
358-
using (var tokenSource = new CancellationTokenSource(sidecarWaitTimeout))
359-
{
360-
await client.WaitForSidecarAsync(tokenSource.Token);
361-
}
362-
363-
// Perform Dapr component operations here i.e. fetching secrets.
364-
```
365366

366367
### Shutdown the sidecar
367368
```csharp

0 commit comments

Comments
 (0)