-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] perform couchdb instance health checks to indicate maintenance
Needs every public address for all nodes, which might be different from the internally known cluster node addresses. Relates to #40
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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 | ||
|
@@ -211,6 +248,7 @@ func (c *CouchdbClient) getStats(config CollectorConfig) (Stats, error) { | |
} | ||
|
||
return Stats{ | ||
//HealthByNodeName: nodeHealth, | ||
StatsByNodeName: nodeStats, | ||
DatabasesTotal: len(databasesList), | ||
DatabaseStatsByDbName: databaseStats, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters