Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Please refer to [HOWTO.md](HOWTO.md) for detailed instructions on running the sa
* `service_discovery/service`: Java/Go interoperability with Nacos using application-level service discovery (Dubbo3 model).
* `llm`: Example of integrating Large Language Models (LLMs) with Dubbo-go.
* `logger`: Logging examples for Dubbo-go applications.
* `metrics`: Shows how to collect and expose metrics from Dubbo-go services, supporting both Prometheus Push and Pull modes. Also includes the `pgw-cleaner` tool for cleaning zombie metrics in Push mode.
* `metrics`: Observability-related samples.
* `metrics/prometheus_grafana`: Shows how to collect and expose metrics from Dubbo-go services, supporting both Prometheus Push and Pull modes. Also includes the `pgw-cleaner` tool for cleaning zombie metrics in Push mode.
* `metrics/probe`: Demonstrates Dubbo-go Kubernetes probe endpoints (`/live`, `/ready`, `/startup`) and deployment usage.
* `mesh`: Proxy-based service mesh example showing how to deploy Dubbo-go services with Envoy on Kubernetes.
* `online_boutique`: Microservices “online boutique” demo built with Dubbo-go.
* `otel/tracing`: Distributed tracing examples using OpenTelemetry.
Expand Down
4 changes: 3 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
* `service_discovery/service`:基于 Nacos 的应用级服务发现(Dubbo3 模型)Java/Go 互操作示例。
* `llm`:将大模型(LLM)集成到 Dubbo-go 中的示例。
* `logger`:Dubbo-go 应用的日志使用示例。
* `metrics`:展示如何采集并暴露 Dubbo-go 服务的指标,支持 Prometheus Push 和 Pull 两种模式;同时包含用于清理 Push 模式僵尸指标的 `pgw-cleaner` 工具。
* `metrics`:可观测性相关示例。
* `metrics/prometheus_grafana`:展示如何采集并暴露 Dubbo-go 服务指标,支持 Prometheus Push 和 Pull 两种模式;同时包含用于清理 Push 模式僵尸指标的 `pgw-cleaner` 工具。
* `metrics/probe`:演示 Dubbo-go 在 Kubernetes 场景下的探针端点(`/live`、`/ready`、`/startup`)及部署方式。
* `mesh`:基于代理的服务网格示例,展示如何在 Kubernetes 上结合 Envoy 部署 Dubbo-go 服务。
* `online_boutique`:基于 Dubbo-go 构建的微服务 “在线商城” 演示项目。
* `otel/tracing`:使用 OpenTelemetry 的分布式链路追踪示例。
Expand Down
166 changes: 166 additions & 0 deletions metrics/probe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@

# Dubbo-Go Kubernetes Probe Sample

English | [中文](README_CN.md)

This example demonstrates how to integrate **Kubernetes liveness, readiness, and startup probes** with a Dubbo-Go Triple service.

It showcases how to expose dedicated probe endpoints and how Kubernetes reacts during application startup and warm-up.


## Project Layout

```
metrics/probe/
├── go-client/
│ └── cmd/main.go # Integration checker for ports/probes/RPC
├── go-server/
│ ├── cmd/main.go # Application entrypoint
│ ├── build.sh # Docker build script
│ └── Dockerfile # Container image definition
└── deploy/
└── server-deployment.yml # Kubernetes deployment
```


## Default Configuration

| Item | Value |
| ------------------- | ----------------------------- |
| Triple service port | `20000` |
| Probe HTTP port | `22222` |
| Probe endpoints | `/live`, `/ready`, `/startup` |
| Client target | `tri://127.0.0.1:20000` |

### Probe Semantics

* `GET /live`
Indicates whether the process is alive.

* `GET /ready`
Indicates whether the service is ready to receive traffic.

* `GET /startup`
Indicates whether the application startup phase has completed.


## Run Locally

### 1️Start the server

```bash
go run ./metrics/probe/go-server/cmd/main.go
```

### 2️Run the go-client integration checks

```bash
go run ./metrics/probe/go-client/cmd/main.go
```

The `go-client` validates:

* Triple port `20000` is reachable.
* Probe port `22222` is reachable.
* `/live` returns `200`.
* `/ready` and `/startup` eventually return `200` after warm-up.
* One `Greet` RPC call succeeds.

### 3️Monitor probe endpoints

```bash
watch -n 1 '
for p in live ready startup; do
url="http://127.0.0.1:22222/$p"

body=$(curl -sS --max-time 2 "$url" 2>&1)
code=$(curl -s -o /dev/null --max-time 2 -w "%{http_code}" "$url" 2>/dev/null)

printf "%-8s [%s] %s\n" "$p" "$code" "$body"
done
'
```

### Expected Behavior

| Phase | /live | /ready | /startup |
| -------------------- | ----- | ------ | -------- |
| Process started | 200 | 503 | 503 |
| During warm-up | 200 | 503 | 503 |
| After warm-up (~15s) | 200 | 200 | 200 |


## Kubernetes Probe Configuration

Example probe configuration:

```yaml
livenessProbe:
httpGet:
path: /live
port: 22222

readinessProbe:
httpGet:
path: /ready
port: 22222

startupProbe:
httpGet:
path: /startup
port: 22222
```


## Run on Kubernetes

### Build the image

From the repository root:

```bash
./metrics/probe/go-server/build.sh
```


### Load image into local cluster (if needed)

For example, with Minikube:

```bash
minikube image load dubbo-go-probe-server:latest
```


### Deploy to Kubernetes

```bash
kubectl apply -f metrics/probe/deploy/server-deployment.yml
kubectl rollout status deploy/dubbo-go-probe-server
kubectl get pod -l app=dubbo-go-probe-server
```


### Inspect probe status

```bash
kubectl describe pod -l app=dubbo-go-probe-server
```

### Expected Kubernetes Behavior

* Immediately after deployment:

* `Ready` = `False`
* `ContainersReady` = `False`

* After ~15 seconds (warm-up completed):

* `Ready` = `True`
* `ContainersReady` = `True`

This demonstrates proper separation of:

* Process liveness
* Service readiness
* Startup lifecycle completion
177 changes: 177 additions & 0 deletions metrics/probe/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@

# Dubbo-Go Kubernetes 探针示例

[English](README.md) | 中文


本示例演示如何在 Dubbo-Go Triple 服务中集成 **Kubernetes 的 liveness、readiness 和 startup 探针**。

通过暴露独立的探针端点,可以清晰地观察应用启动、预热以及就绪阶段在 Kubernetes 中的行为。


## 项目结构

```
metrics/probe/
├── go-client/
│ └── cmd/main.go # 集成测试客户端(端口/探针/RPC 校验)
├── go-server/
│ ├── cmd/main.go # 程序入口
│ ├── build.sh # Docker 构建脚本
│ └── Dockerfile # 镜像定义文件
└── deploy/
└── server-deployment.yml # Kubernetes 部署文件
```


## 默认配置

| 项目 | 默认值 |
| ----------- | ----------------------------- |
| Triple 服务端口 | `20000` |
| 探针 HTTP 端口 | `22222` |
| 探针路径 | `/live`, `/ready`, `/startup` |
| 客户端目标地址 | `tri://127.0.0.1:20000` |


## 探针语义说明

* `GET /live`
表示进程是否存活(进程级健康检查)。

* `GET /ready`
表示服务是否已准备好接收流量。

* `GET /startup`
表示应用是否完成启动阶段。


## 本地运行

### 启动服务

```bash
go run ./metrics/probe/go-server/cmd/main.go
```

### 运行 go-client 做集成检查

```bash
go run ./metrics/probe/go-client/cmd/main.go
```

`go-client` 会依次检查:

* Triple 端口 `20000` 可连接。
* 探针端口 `22222` 可连接。
* `/live` 返回 `200`。
* `/ready`、`/startup` 在预热完成后返回 `200`。
* 发起一次 `Greet` RPC,确认 Triple 服务可用。


### 观察探针状态

```bash
watch -n 1 '
for p in live ready startup; do
url="http://127.0.0.1:22222/$p"

body=$(curl -sS --max-time 2 "$url" 2>&1)
code=$(curl -s -o /dev/null --max-time 2 -w "%{http_code}" "$url" 2>/dev/null)

printf "%-8s [%s] %s\n" "$p" "$code" "$body"
done
'
```


### 预期行为

| 阶段 | /live | /ready | /startup |
| ------------ | ----- | ------ | -------- |
| 进程刚启动 | 200 | 503 | 503 |
| 预热阶段 | 200 | 503 | 503 |
| 预热完成(约 15 秒) | 200 | 200 | 200 |

说明:

* `/live` 只要进程未崩溃就返回 200。
* `/ready` 与 `/startup` 在应用完成预热前返回 503。
* 预热完成后,三个端点均返回 200。


## Kubernetes 探针配置示例

```yaml
livenessProbe:
httpGet:
path: /live
port: 22222

readinessProbe:
httpGet:
path: /ready
port: 22222

startupProbe:
httpGet:
path: /startup
port: 22222
```


## 在 Kubernetes 中运行

### 构建镜像

在仓库根目录执行:

```bash
./metrics/probe/go-server/build.sh
```


### 将镜像加载到本地集群

例如使用 Minikube:

```bash
minikube image load dubbo-go-probe-server:latest
```


### 部署到 Kubernetes

```bash
kubectl apply -f metrics/probe/deploy/server-deployment.yml
kubectl rollout status deploy/dubbo-go-probe-server
kubectl get pod -l app=dubbo-go-probe-server
```


### 查看探针状态

```bash
kubectl describe pod -l app=dubbo-go-probe-server
```


### 预期 Kubernetes 行为

* 刚部署时:

* `Ready` = `False`
* `ContainersReady` = `False`

* 约 15 秒后(预热完成):

* `Ready` = `True`
* `ContainersReady` = `True`

这体现了:

* 进程存活检查(Liveness)
* 服务可用性检查(Readiness)
* 启动阶段控制(Startup)

三者的职责分离。
Loading
Loading