Skip to content

Commit

Permalink
refactor: adjust grpc health check
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Dec 27, 2024
1 parent 761f043 commit 1757aa7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ flowchart LR
- Configuration based on TOML format, the configuration is very simple, and can be saved to files or etcd
- Supports more than 10 Prometheus indicators, pull and push mode
- Opentelemetry supports w3c context trace and jaeger trace
- Frequently updated config: upstream, location and plugin, which adjustments take effect in 10 seconds, and other config is updated, program will be restarted gracefully without interruption
- All configurations except server configuration support hot reload, which adjustments take effect in 10 seconds. The service configuration takes effect after the application is restarted
- Templated configuration of access logs, which supports more than 30 related attribute configurations, and various parameters and indicators can be specified as needed
- Web UI for config, simple and easy to use
- Support let's encrypt, just set the domain of http server
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ flowchart LR
- 基于TOML格式的配置,配置方式非常简洁,可保存至文件或etcd
- 支持10多个Prometheus指标,可以使用pull与push的形式收集相关指标
- Opentelemetry支持w3c context trace与jaeger trace的形式
- 频繁更新的Upstream、Location以及Plugin相关配置调整准实时生效(10秒)且无任何中断请求,其它应用配置更新后,无中断式的优雅重启程序
- 除server的配置外,所有的配置均支持热更新(10秒内)且无任何中断请求,服务配置在应用重启后生效
- 访问日志的模板化配置,已支30多个相关属性的配置,可按需指定输出各种参数与指标
- WEB形式的管理后台界面,无需学习,简单易用
- 开箱即用的let's encrypttls证书,仅需配置对应域名即可,可在单一配置中使用多个子域名
Expand Down
5 changes: 5 additions & 0 deletions src/health/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ fn update_peer_options(
) -> PeerOptions {
let mut options = opt;
let timeout = Some(conf.connection_timeout);
options.verify_hostname = false;
options.verify_cert = false;
options.connection_timeout = timeout;
options.total_connection_timeout = timeout;
options.read_timeout = Some(conf.read_timeout);
Expand Down Expand Up @@ -261,6 +263,7 @@ pub struct GrpcHealthCheck {
pub consecutive_failure: usize,
/// A callback that is invoked when the `healthy` status changes for a [Backend].
pub health_changed_callback: Option<HealthObserveCallback>,
pub connection_timeout: Duration,
}

impl GrpcHealthCheck {
Expand All @@ -279,6 +282,7 @@ impl GrpcHealthCheck {
service: conf.service.clone(),
consecutive_success: conf.consecutive_success,
consecutive_failure: conf.consecutive_failure,
connection_timeout: conf.connection_timeout,
health_changed_callback: Some(
webhook::new_backend_observe_notification(name),
),
Expand All @@ -294,6 +298,7 @@ impl HealthCheck for GrpcHealthCheck {
let conn = tonic::transport::Endpoint::from_shared(uri)
.map_err(|e| util::new_internal_error(500, e.to_string()))?
.origin(self.origin.clone())
.connect_timeout(self.connection_timeout)
.connect()
.await
.map_err(|e| util::new_internal_error(500, e.to_string()))?;
Expand Down

0 comments on commit 1757aa7

Please sign in to comment.