Skip to content

Commit c3f35c3

Browse files
authored
Merge pull request #78 from Scalingo/feat/SRE-570/implement_MySQL_probe
feat(mysqlprobe): implement MySQL probe
2 parents 1580e00 + bc756f5 commit c3f35c3

33 files changed

+7191
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## To Be Released
44

5+
* feat(mysqlprobe): implement MySQL probe
6+
57
## v4.4.5
68

79
* feat(prober): change the exposed CheckOneProbe to make it usable outside of this package

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ go 1.17
55
require (
66
github.com/Scalingo/go-utils/logger v1.1.0
77
github.com/fsouza/go-dockerclient v1.7.11
8+
github.com/go-sql-driver/mysql v1.6.0
89
github.com/gorilla/mux v1.8.0
910
github.com/goware/httpmock v0.0.0-20150807175315-4fdb484c3e70
1011
github.com/lib/pq v1.10.6
1112
github.com/ncw/swift v1.0.53
13+
github.com/pkg/errors v0.9.1
1214
github.com/sirupsen/logrus v1.8.1
1315
github.com/stretchr/testify v1.7.1
1416
go.etcd.io/etcd/client/v2 v2.305.4
@@ -41,7 +43,6 @@ require (
4143
github.com/opencontainers/go-digest v1.0.0 // indirect
4244
github.com/opencontainers/image-spec v1.0.2 // indirect
4345
github.com/opencontainers/runc v1.1.0 // indirect
44-
github.com/pkg/errors v0.9.1 // indirect
4546
github.com/pmezard/go-difflib v1.0.0 // indirect
4647
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
4748
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dp
386386
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
387387
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
388388
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
389+
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
390+
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
389391
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
390392
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
391393
github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=

mysqlprobe/mysqlprobe.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package mysqlprobe
2+
3+
import (
4+
"database/sql"
5+
6+
// Mandatory for sql.Open to work
7+
_ "github.com/go-sql-driver/mysql"
8+
9+
errgo "gopkg.in/errgo.v1"
10+
)
11+
12+
type MySQLProbe struct {
13+
name string
14+
connectionString string
15+
}
16+
17+
// NewMySQLProbe instantiate a new MySQL probe:
18+
// - name: probe name
19+
// - connectionString: connection string with the form "mysql://username:[email protected]"
20+
func NewMySQLProbe(name, connectionString string) MySQLProbe {
21+
return MySQLProbe{
22+
name: name,
23+
connectionString: connectionString,
24+
}
25+
}
26+
27+
func (p MySQLProbe) Name() string {
28+
return p.name
29+
}
30+
31+
func (p MySQLProbe) Check() error {
32+
client, err := sql.Open("mysql", p.connectionString)
33+
if err != nil {
34+
return errgo.Notef(err, "fail to open a new connection to MySQL")
35+
}
36+
defer client.Close()
37+
38+
err = client.Ping()
39+
if err != nil {
40+
return errgo.Notef(err, "unable to contact MySQL host")
41+
}
42+
43+
return nil
44+
}

vendor/github.com/go-sql-driver/mysql/.gitignore

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/go-sql-driver/mysql/AUTHORS

Lines changed: 117 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)