/
healthcheck.go
39 lines (33 loc) · 1.09 KB
/
healthcheck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cassandra
import (
"fmt"
"github.com/hailo-platform/H2O/service/connhealthcheck"
"github.com/hailo-platform/H2O/service/healthcheck"
)
const (
HealthCheckId = "com.hailocab.service.cassandra"
MaxConnCheckId = "com.hailocab.service.cassandra.maxconns"
)
// HealthCheck asserts we can connect to C* and
func HealthCheck(keyspace string, cfs []string) healthcheck.Checker {
return func() (map[string]string, error) {
pool, err := ConnectionPool(keyspace)
if err != nil {
return nil, fmt.Errorf("Failed to get connection pool for keyspace '%v': %v", keyspace, err)
}
schema := pool.Schema()
for _, cf := range cfs {
if _, exists := schema.ColumnFamilies[cf]; !exists {
return nil, fmt.Errorf("ColumnFamily '%v' does not exist", cf)
}
}
return nil, nil
}
}
// MaxConnHealthCheck asserts that the total number of established connections to all cassandra nodes
// falls below a given max threshold.
func MaxConnHealthCheck(maxconns int) healthcheck.Checker {
return func() (map[string]string, error) {
return connhealthcheck.MaxTcpConnections(getHosts(), maxconns)()
}
}