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

API: Reflection Service Support #435

Merged
merged 1 commit into from
Nov 19, 2020

Conversation

Vigilans
Copy link
Contributor

@Vigilans Vigilans commented Nov 19, 2020

This PR implements a new service ReflectionService, which is a simple wrapper of grpc/reflection package:

  "api": {
    "tag": "api",
    "services": ["ReflectionService"]
  }

This service enables the clients to retrieve gRPC service's API list and signatures without prior access to its proto files. In this way, tools like grpcurl could easily interact with the API service:

# h2c
$ grpcurl -plaintext localhost:10086 list
grpc.reflection.v1alpha.ServerReflection
v2ray.core.app.proxyman.command.HandlerService
v2ray.core.app.stats.command.StatsService

# h2 with tls
$ grpcurl -insecure -cert cert.crt -key cert.key localhost:10086 v2ray.core.app.stats.command.StatsService/GetSysStats
{
  "NumGoroutine": 24,
  "NumGC": 25,
  "Alloc": "24095640",
  "TotalAlloc": "511473656",
  "Sys": "146657288",
  "Mallocs": "6909875",
  "Frees": "6464105",
  "LiveObjects": "445770",
  "PauseTotalNs": "1834456",
  "Uptime": 82
}

Without the reflection service, a proto file has to be provided to retreive service and API's signature information:

$ grpcurl -import-path core/app/stats/command -proto command.proto -plaintext localhost:10086 describe v2ray.core.app.stats.command.StatsService
v2ray.core.app.stats.command.StatsService is a service:
service StatsService {
  rpc GetStats ( .v2ray.core.app.stats.command.GetStatsRequest ) returns ( .v2ray.core.app.stats.command.GetStatsResponse );
  rpc GetSysStats ( .v2ray.core.app.stats.command.SysStatsRequest ) returns ( .v2ray.core.app.stats.command.SysStatsResponse );
  rpc QueryStats ( .v2ray.core.app.stats.command.QueryStatsRequest ) returns ( .v2ray.core.app.stats.command.QueryStatsResponse );
}

This service has to be specified in API config manually to take effect, since it exposes the detailed API information to clients without any prior knowledge.

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

2 participants