components-contrib icon indicating copy to clipboard operation
components-contrib copied to clipboard

Standardize behavior on component initialization failure

Open ItalyPaleAle opened this issue 3 years ago • 7 comments

Currently, when components fail to initialize (for example because of a misconfiguration or connection error), the behavior is undefined and depends on the component.

Some components cause the sidecar to crash; others print a warning or error message; others do nothing and try reconnecting again lazily.

To improve the user experience, we should look into standardizing this behavior.

In all cases we should print out an error message that describes the problem, at least saying that the component failed to start. If possible, then, provide more details, and it would be great to add a link to the Dapr docs to point people to the component's specs.

What happens next (crash or continue working without the component) is up for discussion.

Note that some components maintain a persistent connection, so connection failures can be determined in the "init" methods directly (e.g. databases). Other components are stateless (e.g. Azure Storage, S3), so we need to decide what to do with those: do we attempt to make a GET request in the "init" method to validate the connection parameters, or do we lazily wait for first use to report a connection issue? (Or that could be configurable?)

ItalyPaleAle avatar May 25 '22 15:05 ItalyPaleAle

I think we should make this behavior be verified by conformance tests - that is where standard behavior is validated.

Now, when it comes to what should be the standard behavior, I think it should be a combination of all above:

  1. Component should try to connect on init, optionally with built-in retries. If cannot connect, return error.
  2. Component can optionally have reconnection logic in the background, in case connection is lost post init (this is validated in certification tests)
  3. Dapr runtime will log error when a component cannot init.
  4. Dapr runtime should emit a metric for each component that failed/succeeded to initialize, but metric should include the component type and not the component name (since name will vary per customer setup) - this should be validated in conformance tests.

artursouza avatar May 25 '22 17:05 artursouza

That makes sense to me.

So, to confirm, we should not crash when a component fails to init. Instead, we'll let the app make API calls that will fail.

ItalyPaleAle avatar May 25 '22 17:05 ItalyPaleAle

I think we should make this behavior be verified by conformance tests - that is where standard behavior is validated.

Now, when it comes to what should be the standard behavior, I think it should be a combination of all above:

  1. Component should try to connect on init, optionally with built-in retries. If cannot connect, return error.
  2. Component can optionally have reconnection logic in the background, in case connection is lost post init (this is validated in certification tests)
  3. Dapr runtime will log error when a component cannot init.
  4. Dapr runtime should emit a metric for each component that failed/succeeded to initialize, but metric should include the component type and not the component name (since name will vary per customer setup) - this should be validated in conformance tests.

This makes sense to me.

yaron2 avatar May 25 '22 17:05 yaron2

That makes sense to me.

So, to confirm, we should not crash when a component fails to init. Instead, we'll let the app make API calls that will fail.

We have metadata to say if a component is required or optional. See https://docs.dapr.io/operations/components/component-schema/

artursouza avatar May 25 '22 17:05 artursouza

That makes sense to me.

So, to confirm, we should not crash when a component fails to init. Instead, we'll let the app make API calls that will fail.

No, that's not the desired behavior. If a component cannot connect after all retries were exhausted, we return an error and crash as we do today. Users have the option today to ignore crashing and continuing init with ignoreErrors: https://docs.dapr.io/operations/components/component-schema/#format

yaron2 avatar May 25 '22 17:05 yaron2

/assign

addjuarez avatar Aug 02 '22 14:08 addjuarez

related to https://github.com/dapr/components-contrib/issues/1916

mukundansundar avatar Aug 03 '22 04:08 mukundansundar