Skip to content

Commit a6f3c28

Browse files
committed
fix panic when MySQL Router is stopped
1 parent d2dff1d commit a6f3c28

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

hack/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
If you want to run InnoDB Cluster with http and https REST API, run this command.
2+
3+
```shell
4+
$ git clone [email protected]:rluisr/mysqlrouter-go.git
5+
$ cd mysqlrouter-go/test
6+
$ docker compose up --build --force-recreate --always-recreate-deps --renew-anon-volumes -d;
7+
```
8+
9+
### Basic
10+
11+
root / mysql

main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var args struct {
4848
}
4949

5050
var (
51+
lastRouter *mysqlrouter.Router
5152
lastRoutes []*mysqlrouter.Routes
5253
lastRouteConnections []*mysqlrouter.RouteConnections
5354
)
@@ -152,6 +153,8 @@ func collectRouterMetrics() (*mysqlrouter.Router, error) {
152153
routerUpGauge.Set(1)
153154
routerStatusGauge.WithLabelValues(strconv.Itoa(router.ProcessID), router.ProductEdition, router.TimeStarted.String(), router.Version, router.Hostname)
154155

156+
lastRouter = router
157+
155158
return router, nil
156159
}
157160

@@ -200,10 +203,10 @@ func collectRouteMetrics(router *mysqlrouter.Router) {
200203
// so route metrics will be 0
201204
if router == nil {
202205
for _, route := range lastRoutes {
203-
routeActiveConnectionsGauge.WithLabelValues(route.Name, router.Hostname).Set(0)
204-
routeTotalConnectionsGauge.WithLabelValues(route.Name, router.Hostname).Set(0)
205-
routeBlockedHostsGauge.WithLabelValues(route.Name, router.Hostname).Set(0)
206-
routeHealthGauge.WithLabelValues(route.Name, router.Hostname).Set(0)
206+
routeActiveConnectionsGauge.WithLabelValues(route.Name, lastRouter.Hostname).Set(0)
207+
routeTotalConnectionsGauge.WithLabelValues(route.Name, lastRouter.Hostname).Set(0)
208+
routeBlockedHostsGauge.WithLabelValues(route.Name, lastRouter.Hostname).Set(0)
209+
routeHealthGauge.WithLabelValues(route.Name, lastRouter.Hostname).Set(0)
207210

208211
for _, routeConnection := range lastRouteConnections {
209212
if args.CollectRouteConnectionsByteFromServer {

0 commit comments

Comments
 (0)