Stork 参考指南
本指南是Stork 入门指南的配套文档。它解释了 SmallRye Stork 集成在 Quarkus 中的配置和使用。
可用的服务发现和选择
请查看 SmallRye Stork 网站,了解有关提供的服务发现和选择的更多信息。
在 Kubernetes 中使用 Stork
Stork 为 Kubernetes 提供了服务发现支持,这超越了 Kubernetes 默认提供的功能。它查找支持 Kubernetes 服务的所有 Pod,但它不会应用轮询(Kubernetes 会这样做),而是让您选择使用 Stork 负载均衡器的 Pod。
要使用此功能,请将以下依赖项添加到您的项目中
<dependency>
<groupId>io.smallrye.stork</groupId>
<artifactId>stork-service-discovery-kubernetes</artifactId>
</dependency>
implementation("io.smallrye.stork:stork-service-discovery-kubernetes")
对于每个期望作为 Kubernetes 服务公开的服务,配置查找
quarkus.stork.my-service.service-discovery.type=kubernetes
quarkus.stork.my-service.service-discovery.k8s-namespace=my-namespace
Stork 在指定的命名空间中查找具有给定名称(在前面的示例中为my-service
)的 Kubernetes 服务。Stork 不会直接使用 Kubernetes 服务 IP 并让 Kubernetes 处理选择和平衡,而是检查服务并检索提供服务的 Pod 列表。然后,它可以选择实例。
有关在 Kubernetes 中使用 Stork 的完整示例,请阅读使用 Stork with Kubernetes 指南。
配置 Stork 可观察性
启用指标
当应用程序也使用 quarkus-micrometer
扩展时,Stork 指标会自动启用。
Micrometer 收集使用 Stork 的 rest/grpc 客户端和以编程方式使用 Stork 的客户端的指标。
例如,如果您将指标导出到 Prometheus,您将得到
# 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
Stork 服务名称可以在标签中找到。
这些指标包含服务发现 (stork_service_discovery_*
) 和有关服务选择的指标 (stork_service_selection_*
),例如服务实例的数量、故障和持续时间。
配置参考
构建时固定的配置属性 - 所有其他配置属性都可以在运行时覆盖
配置属性 |
类型 |
默认 |
---|---|---|
类型 |
默认 |
|
配置服务发现类型,例如“consul”。必须提供该类型的 ServiceDiscoveryProvider 环境变量: 显示更多 |
字符串 |
必需 |
ServiceDiscovery 参数。查看所选服务发现类型的文档以获取可用参数。 环境变量: 显示更多 |
Map<String,String> |
|
配置负载均衡器类型,例如“round-robin”。必须提供该类型的 LoadBalancerProvider 环境变量: 显示更多 |
字符串 |
|
负载均衡器参数。查看所选负载均衡器类型的文档以获取可用参数 环境变量: 显示更多 |
Map<String,String> |
|
配置服务注册器类型,例如“consul”。必须提供该类型的 ServiceRegistrarProvider 环境变量: 显示更多 |
字符串 |
必需 |
服务注册器参数。查看所选注册器类型的文档以获取可用参数 环境变量: 显示更多 |
Map<String,String> |