Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Dapr Error Handling Codes #21

Merged
merged 10 commits into from
Jun 2, 2023

Conversation

robertojrojas
Copy link
Contributor

This is a proposal for Dapr Error Handling and Codes standarization.
Issue: dapr/dapr#6068

Signed-off-by: Roberto J Rojas <robertojrojas@gmail.com>
000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
Signed-off-by: Roberto J Rojas <robertojrojas@gmail.com>
Signed-off-by: Roberto J Rojas <robertojrojas@gmail.com>
Signed-off-by: Roberto J Rojas <robertojrojas@gmail.com>
Copy link
Contributor

@mukundansundar mukundansundar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first pass review.

000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Show resolved Hide resolved
| Dapr Module | Prefix |
| ----------- | ----------- |
| CLI | DAPR_CLI_INIT_* |
| Self-hosted | DAPR_SELF_HOSTED_INIT_* |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, these should be completely platform agnostic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

| Dapr Module | Prefix |
| ----------- | ----------- |
| CLI | DAPR_CLI_RUNTIME_* |
| Self-hosted | DAPR_SELF_HOSTED_RUNTIME_* |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove platform specific codes.

000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Show resolved Hide resolved
Copy link
Contributor

@ItalyPaleAle ItalyPaleAle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to see an example of how this is included in a HTTP response too.

### Error Status
The properties of the **google.rpc.Status** will be populated as following:

- **Code** - Protocol level error code. These could be either gRPC or HTTP error codes. See (gRPC Codes ProtoBuf)[https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be only gRPC codes? This way, developers get a consistent response with both HTTP and gRPC.
When the API is HTTP, the corresponding status code is returned as HTTP response status code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could address the HTTP error codes with a mapping like the one shown in the table: https://cloud.google.com/apis/design/errors#handling_errors

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are errors returned in HTTP, in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ItalyPaleAle Here what I did as part of my POC, but of course it could implemented better: https://github.com/robertojrojas/dapr/blob/a0760ea549b9a3da93af2bee96e88ad94db9b32b/pkg/http/api.go#L1017

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ItalyPaleAle Here is a sample HTTP output of the code above. Here you can see both the gRPC Unavailable and the HTTP 500 but that's because in my POC code I used fasthttp.StatusInternalServerError. We could have code mapping gRPC and HTTP based on the table in the handling errors page :

  curl -v -s http://localhost:3500/v1.0/state/statestore/name | jq .
dapr_redis
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3500 (#0)
> GET /v1.0/state/statestore/name HTTP/1.1
> Host: localhost:3500
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 16 May 2023 16:32:49 GMT
< Content-Type: application/json
< Content-Length: 269
< Traceparent: 00-a1b43cb07328721cc009960b070586b6-4d4a624d2ab86d00-01
< 
{ [269 bytes data]
* Connection #0 to host localhost left intact
* Closing connection 0
{
  "code": 14,
  "message": "fail to get name from state store statestore: dial tcp [::1]:6379: connect: connection refused",
  "details": [
    {
      "@type": "type.googleapis.com/google.rpc.ErrorInfo",
      "reason": "DAPR_RUNTIME_HTTP",
      "domain": "dapr.io",
      "metadata": {
        "storeName": "statestore"
      }
    }
  ]
}

000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
Comment on lines 140 to 146
- **ResourceType** - The building block type.

Example: "StateStore"

- **ResourceName** - The component name.

Example: "REDIS"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on making this the same key? For example state.redis/v1 which is how we refer to components in the Component YAMLs too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like state.redis/v1 for ResourceName.
@artursouza any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to the naming change.

Additionally Is there a place to add the componentName also?
There might be multiple state.redis/v1 used with different component names for different state stores within a single app. Would that be part of metadata?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great callout.

Either a different key or state.redis/v1/component-name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the gRPC schema for ResourceInfo, we should have:

resource_type: state.redis/v1
resource_name: component-name

| Dapr Module | Prefix |
| ----------- | ----------- |
| CLI | DAPR_CLI_INIT_* |
| Self-hosted | DAPR_SELF_HOSTED_INIT_* |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

000X-B-C-I-R-S-error-handling-codes.md Outdated Show resolved Hide resolved
},
{
"@type": "type.googleapis.com/google.rpc.ResourceInfo",
"resource_type": "StateStore",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some keys use camelCase, some use snake_case. We should be consistent

Also see my comment above. I think a single resource_name = state.redis/v1 may be more aligned with how we refer to the comoponents everywhere (note that some components have a dot in the name too, such as state.azure.cosmosdb, and we should include the version too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ItalyPaleAle The keys for the JSON payload are auto-generated as part of the Marshaling implemented by the Protobuf stub of the error_details.proto

if you look at the annotations, you'll see the resource_type as the JSON key to generate/read.

ResourceType string `protobuf:"bytes,1,opt,name=resource_type,json=resourceType,proto3" json:"resource_type,omitempty"`

robertojrojas and others added 5 commits May 16, 2023 12:17
Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com>
Signed-off-by: Roberto Rojas <robertojrojas@gmail.com>
Signed-off-by: Roberto J Rojas <robertojrojas@gmail.com>
Signed-off-by: Roberto J Rojas <robertojrojas@gmail.com>
Signed-off-by: Roberto J Rojas <robertojrojas@gmail.com>
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
@artursouza
Copy link
Member

I made some changes that reflect the latest discussions. Can we merge this? @mukundansundar @ItalyPaleAle

Copy link
Member

@yaron2 yaron2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 binding

Copy link
Member

@artursouza artursouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 binding

Copy link
Member

@daixiang0 daixiang0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 binding

@yaron2 yaron2 merged commit 94ec2f3 into dapr:main Jun 2, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants