Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] perform couchdb instance health checks to indicate maintenance #47

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
38 changes: 38 additions & 0 deletions lib/couchdb-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,39 @@ type MembershipResponse struct {
ClusterNodes []string `json:"cluster_nodes"`
}

func (c *CouchdbClient) getHealthByNodeName(urisByNodeName map[string]string) (map[string]HealthResponse, error) {
healthByNodeName := make(map[string]HealthResponse)
for name, uri := range urisByNodeName {
var health HealthResponse

// Instead of http://localhost:15984/_node/[email protected]/_up
// we have to request http://localhost:15984/_up,
// but how do we find the correct base uris, say: ip and port, for each node?
data, err := c.Request("GET", fmt.Sprintf("%s/_up", uri), nil)
if err != nil {
err = fmt.Errorf("error reading couchdb health: %v", err)
//if !strings.Contains(err.Error(), "\"error\":\"nodedown\"") {
// return nil, err
//}
klog.Error(fmt.Errorf("continuing despite error: %v", err))
continue
}

err = json.Unmarshal(data, &health)
if err != nil {
return nil, fmt.Errorf("error unmarshalling health: %v", err)
}

healthByNodeName[name] = health
}

if len(urisByNodeName) == 0 {
return nil, fmt.Errorf("all nodes down")
}

return healthByNodeName, nil
}

func (c *CouchdbClient) getNodeInfo(uri string) (NodeInfo, error) {
data, err := c.Request("GET", fmt.Sprintf("%s/", uri), nil)
if err != nil {
Expand Down Expand Up @@ -179,6 +212,10 @@ func (c *CouchdbClient) getStats(config CollectorConfig) (Stats, error) {
if err != nil {
return Stats{}, err
}
//nodeHealth, err := c.getHealthByNodeName(urisByNode)
//if err != nil {
// return Stats{}, err
//}
nodeStats, err := c.getStatsByNodeName(urisByNode)
if err != nil {
return Stats{}, err
Expand Down Expand Up @@ -211,6 +248,7 @@ func (c *CouchdbClient) getStats(config CollectorConfig) (Stats, error) {
}

return Stats{
//HealthByNodeName: nodeHealth,
StatsByNodeName: nodeStats,
DatabasesTotal: len(databasesList),
DatabaseStatsByDbName: databaseStats,
Expand Down
7 changes: 7 additions & 0 deletions lib/couchdb-stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ type CouchReplicator struct {
Connection map[string]Counter `json:"connection"`
}

type HealthResponse struct {
Status string `json:"status"`
// see https://github.com/apache/couchdb/pull/1658
//Seeds map[string]SeedStat `json:"seeds"`
}

type StatsResponse struct {
Couchdb CouchdbStats `json:"couchdb"`
Up float64 `json:"-"`
Expand Down Expand Up @@ -229,6 +235,7 @@ type SystemResponse struct {
}

type Stats struct {
//HealthByNodeName map[string]HealthResponse
StatsByNodeName map[string]StatsResponse
DatabasesTotal int
DatabaseStatsByDbName DatabaseStatsByDbName
Expand Down