Stork Reference Guide
本指南是 Stork Getting Started Guide 的配套指南。它解释了 Quarkus 中 SmallRye Stork 集成的配置和用法。
This guide is the companion from the Stork Getting Started Guide. It explains the configuration and usage of SmallRye Stork integration in Quarkus. Unresolved directive in stork-reference.adoc - include::{includes}/extension-status.adoc[]
Supported clients
Stork 的当前集成支持:
The current integration of Stork supports:
-
the REST Client
-
the gRPC clients (using the Vert.x gRPC client is recommended)
警告:gRPC 客户端集成不支持基于统计数据的负载平衡器。
Warning: The gRPC client integration does not support statistic-based load balancers.
Available service discovery and selection
查看 SmallRye Stork website 以了解有关提供的服务发现和选择的更多信息。
Check the SmallRye Stork website to find more about the provided service discovery and selection.
Using Stork in Kubernetes
Stork 为 Kubernetes 提供服务发现支持,超出了 Kubernetes 默认提供的功能。它将在 Kubernetes 服务的备份中查找所有 pod,但不会像 Kubernetes 所做的那样应用循环负载均衡,而是允许您使用 Stork 负载平衡器选择 pod。
Stork provides a service discovery support for Kubernetes, which goes beyond what Kubernetes provides by default. It looks for all the pods backing up a Kubernetes service, but instead of applying a round-robin (as Kubernetes would do), it gives you the option to select the pod using a Stork load-balancer.
要使用此功能,请将以下依赖项添加到项目中:
To use this feature, add the following dependency to your project:
<dependency>
<groupId>io.smallrye.stork</groupId>
<artifactId>stork-service-discovery-kubernetes</artifactId>
</dependency>
implementation("io.smallrye.stork:stork-service-discovery-kubernetes")
为希望作为 Kubernetes 服务公开的每项服务配置查找:
For each service expected to be exposed as a Kubernetes Service, configure the lookup:
quarkus.stork.my-service.service-discovery.type=kubernetes
quarkus.stork.my-service.service-discovery.k8s-namespace=my-namespace
Stork 在指定命名空间中查找给定名称的 Kubernetes 服务(前面示例中的 my-service
)。Stork 不直接使用 Kubernetes 服务 IP,也不让 Kubernetes 来处理选择和平衡,而是检查服务并检索提供服务的 pod 列表。然后,它可以选择该实例。
Stork looks for the Kubernetes Service with the given name (my-service
in the previous example) in the specified namespace.
Instead of using the Kubernetes Service IP directly and let Kubernetes handle the selection and balancing, Stork inspects the service and retrieves the list of pods providing the service. Then, it can select the instance.
有关使用 Kubernetes 的 Stork 的完整示例,请阅读 Using Stork with Kubernetes guide。
For a full example of using Stork with Kubernetes, please read the Using Stork with Kubernetes guide.
Extending Stork
Stork 是可扩展的。您可以实现自己的服务发现或服务选择提供程序。
Stork is extensible. You can implement your own service discovery or service selection provider.
要了解自定义服务发现和服务选择,请查看:
To learn about custom service discovery and service selection, check:
Configure Stork observability
Enable metrics
当应用程序还使用quarkus-micrometer
扩展时,会自动启用 Stork 指标。
Stork metrics are automatically enabled when the application also uses the quarkus-micrometer
extension.
Micrometer 通过 Stork 以及使用 Stork 进行编程的客户端来收集 rest/grpc 客户端的指标。
Micrometer collects the metrics of rest/grpc clients using Stork and the client using Stork programmatically.
比如,如果你将指标导出到 Prometheus,你将得到:
As an example, if you export the metrics to Prometheus, you will get:
# HELP stork_service_selection_failures_total The number of failures during service selection.
# TYPE stork_service_selection_failures_total counter
stork_service_selection_failures_total{service_name="hello-service",} 0.0
# HELP stork_service_selection_duration_seconds The duration of the selection operation
# TYPE stork_service_selection_duration_seconds summary
stork_service_selection_duration_seconds_count{service_name="hello-service",} 13.0
stork_service_selection_duration_seconds_sum{service_name="hello-service",} 0.001049291
# HELP stork_service_selection_duration_seconds_max The duration of the selection operation
# TYPE stork_service_selection_duration_seconds_max gauge
stork_service_selection_duration_seconds_max{service_name="hello-service",} 0.0
# HELP stork_overall_duration_seconds_max The total duration of the Stork service discovery and selection operations
# TYPE stork_overall_duration_seconds_max gauge
stork_overall_duration_seconds_max{service_name="hello-service",} 0.0
# HELP stork_overall_duration_seconds The total duration of the Stork service discovery and selection operations
# TYPE stork_overall_duration_seconds summary
stork_overall_duration_seconds_count{service_name="hello-service",} 13.0
stork_overall_duration_seconds_sum{service_name="hello-service",} 0.001049291
# HELP stork_service_discovery_failures_total The number of failures during service discovery
# TYPE stork_service_discovery_failures_total counter
stork_service_discovery_failures_total{service_name="hello-service",} 0.0
# HELP stork_service_discovery_duration_seconds_max The duration of the discovery operation
# TYPE stork_service_discovery_duration_seconds_max gauge
stork_service_discovery_duration_seconds_max{service_name="hello-service",} 0.0
# HELP stork_service_discovery_duration_seconds The duration of the discovery operation
# TYPE stork_service_discovery_duration_seconds summary
stork_service_discovery_duration_seconds_count{service_name="hello-service",} 13.0
stork_service_discovery_duration_seconds_sum{service_name="hello-service",} 6.585046209
# HELP stork_service_discovery_instances_count_total The number of service instances discovered
# TYPE stork_service_discovery_instances_count_total counter
stork_service_discovery_instances_count_total{service_name="hello-service",} 26.0
可以在_tags_中找到 Stork 服务名称。
The Stork service name can be found in the tags.
指标包含服务发现(stork_service_discovery_*
)和有关服务选择(stork_service_selection_*
)的指标,例如服务实例数、失败和持续时间。
The metrics contain both the service discovery (stork_service_discovery_*
) and the metrics about the service selection (stork_service_selection_*
) such as the number of service instances, failures, and durations.