question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configure Armeria to Return gRPC Status Code for Invalid Path

See original GitHub issue

Overview

For an Armeria server that is built with minimal settings and has a simple GrpcService, the server returns only HTTP status code 404 but not any gRPC status such as 12 (UNIMPLEMENTED) when an invalid path is given.

Is there a way to configure the Armeria server so that it returns gRPC status code along with HTTP status?

Examples

Below is an example server that uses http4s-armeria as backend:

import cats.effect.{ExitCode, IO, IOApp}
import org.http4s.armeria.server.ArmeriaServerBuilder

object Main extends IOApp {

  override def run(args: List[String]): IO[ExitCode] = {
    val grpcService = ??? // simple gRPC service defined somewhere else

    ArmeriaServerBuilder[IO]
      .bindHttp(9876, "0.0.0.0")
      .withHttpService(grpcService)
      .resource.useForever.as(ExitCode.Success)
  }
}

Example query command:

curl -v -H 'content-type: application/json' -d '{}' 'http://localhost:9876/io.test.NonExistentService/InvokeInvalidRpc'

In the output, only HTTP status 404 is available but there is no grpc-status in either the response headers or body.

Use Case

For gRPC clients that stick to the protobuf service definitions strictly, it is unlikely for them to send requests with invalid paths.

However, for gRPC servers deployed to AWS and sitting behind an application load balancer, AWS performs health checks against targets at path /AWS.ALB/healthcheck and expects gRPC status 12 (UNIMPLEMENTED) by default if gRPC is used as the protocol version (see reference here).

It’d be great if Armeria server could be configured to return gRPC status (such as 12) for invalid paths.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:1
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
ikhooncommented, Nov 23, 2022

Hello, https://github.com/http4s/http4s-armeria user! 😆 fallbackDecorator would be a good workaround. But I also think we can use the default headers of https://github.com/line/armeria/pull/4520 to set grpc-status 12 for 404 Not Found. Note: A conditional default headers depending on response headers hasn’t been implemented yet. I’d like to add the feature to the PR. Users might set the default headers to ServerBuilder:

Server.builder()
      .setHeader(HttpStatus.NOT_FOUND, "grpc-status", 12)
      // Or dynamically set depending on the status predicate
      .setHeader(status -> ..., "grpc-status", 12)
      // For more than this flexibility, it would be better to
      // use HTTP decorators
1reaction
ikhooncommented, Nov 25, 2022

I tried to implement the feature that dynamically sets/adds the default headers depending on an HTTP status. But it was tricky to handle addHeaders(). If we use a function to store the default value, we don’t know if a header is set by ResponseHeaders or the default headers until it is evaluated.

For that reason, please use the decorator pattern. The following pattern won’t be implemented.

.setHeader(HttpStatus.NOT_FOUND, "grpc-status", 12)
// Or dynamically set depending on the status predicate
.setHeader(status -> ..., "grpc-status", 12)
Read more comments on GitHub >

github_iconTop Results From Across the Web

armeria/GrpcStatus.java at master - GitHub
Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your...
Read more >
Annotated services — Armeria documentation
Armeria provides a way to write an HTTP service using annotations. It helps a user make his or her code simple and easy...
Read more >
Pattern for rich error handling in gRPC - Stack Overflow
It seems that in most client languages, an error results in an exception being thrown, with no way to grab the response. For...
Read more >
GRPC Core: Status codes and their use in gRPC
Code Number Description OK 0 Not an error; returned on success. FAILED_PRECONDITION 9 OUT_OF_RANGE 11
Read more >
io.grpc.Status.withDescription java code examples | Tabnine
origin: line/armeria. GrpcStatus.httpStatusToGrpcStatus(...) /** * Maps HTTP error response status codes to transport codes, as defined in <a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found