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

Use heal summary for heal metrics #199

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
32 changes: 8 additions & 24 deletions gluster-exporter/metric_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,36 +332,20 @@ func healCounts(gluster glusterutils.GInterface) error {
return err
}

// locHealInfoFunc is a function literal, which takes
// arg1: f1 a function which takes a string and returns ([]HealEntry, error)
// (can be 'HealInfo' or 'SplitBrainHealInfo')
// arg2: gVect a pointer to GaugeVec
// (can be either 'glusterVolumeHealCount' or 'glusterVolumeSplitBrainHealCount')
// arg3: volName a string representing the volume name
// arg4: errStr the error string in case of error
locHealInfoFunc := func(f1 func(string) ([]glusterutils.HealEntry, error), gVect string, volName string, errStr string) {
// Get the heal count
heals, err := f1(volName)
for _, volume := range volumes {
volName := volume.Name

heals, err := gluster.HealInfo(volName)
if err != nil {
log.WithError(err).WithFields(log.Fields{
"volume": volName,
}).Debug(errStr)
return
}).Debug("Error getting heal info summary")
continue
}
for _, healinfo := range heals {
labels := getVolumeHealLabels(volName, healinfo.Hostname, healinfo.Brick)
volumeHealGaugeVecs[gVect].Set(labels, float64(healinfo.NumHealEntries))
}
}

for _, volume := range volumes {
name := volume.Name
if strings.Contains(volume.Type, "Replicate") {
locHealInfoFunc(gluster.HealInfo, glusterVolumeHealCount, name, "Error getting heal info")
locHealInfoFunc(gluster.SplitBrainHealInfo, glusterVolumeSplitBrainHealCount, name, "Error getting split brain heal info")
}
if strings.Contains(volume.Type, "Disperse") {
locHealInfoFunc(gluster.HealInfo, glusterVolumeHealCount, name, "Error getting heal info")
volumeHealGaugeVecs[glusterVolumeHealCount].Set(labels, float64(healinfo.NumHealPending))
volumeHealGaugeVecs[glusterVolumeSplitBrainHealCount].Set(labels, float64(healinfo.NumSplitBrain))
}
}
return nil
Expand Down
27 changes: 0 additions & 27 deletions pkg/glusterutils/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,6 @@ func (gc *GCache) HealInfo(vol string) ([]HealEntry, error) {
return retVal, err
}

// SplitBrainHealInfo wraps the GInterface.SplitBrainHealInfo call
func (gc *GCache) SplitBrainHealInfo(vol string) ([]HealEntry, error) {
gc.lock.Lock()
defer gc.lock.Unlock()
// adding the argument[s] also to the 'localName'
// as we want to cache the function call with each argument
// it will be wrong to cache the results for only one volume
// and show the same result throughout for other volumes
const origName = "SplitBrainHealInfo"
var localName = origName + "-" + vol
var retVal []HealEntry
var err error
var ok bool
if gc.timeForNewCall(localName, origName) {
if retVal, err = gc.gd.SplitBrainHealInfo(vol); err != nil {
return retVal, err
}
// reset the last called time only on a successful call
gc.lastCallTimeMap[localName] = time.Now()
gc.lastCallValueMap[localName] = retVal
}
if retVal, ok = gc.lastCallValueMap[localName].([]HealEntry); !ok {
err = errors.New("[CacheError] Unable to convert back to a valid return type")
}
return retVal, err
}

// IsLeader method wraps the GInterface.IsLeader call
func (gc *GCache) IsLeader() (bool, error) {
gc.lock.Lock()
Expand Down
3 changes: 2 additions & 1 deletion pkg/glusterutils/gd1.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ type healEntriesXML struct {
HostUUID string `xml:"hostUuid,attr"`
Brickname string `xml:"name"`
Connected string `xml:"status"`
NumHealEntries string `xml:"numberOfEntries"`
NumHealPending string `xml:"numberOfEntriesInHealPending"`
NumSplitBrain string `xml:"numberOfEntriesInSplitBrain"`
}

type gd1Brick struct {
Expand Down
22 changes: 8 additions & 14 deletions pkg/glusterutils/healinfo_gd1.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ func (g *GD1) getHealDetails(cmd string) ([]HealEntry, error) {
heals := make([]HealEntry, len(healop.Healentries))
for hidx, entry := range healop.Healentries {
if entry.Connected == "Connected" {
entries, err := strconv.ParseInt(entry.NumHealEntries, 10, 64)
numHealPending, err := strconv.ParseInt(entry.NumHealPending, 10, 64)
if err != nil {
return nil, err
}
numSplitBrain, err := strconv.ParseInt(entry.NumSplitBrain, 10, 64)
if err != nil {
return nil, err
}
hostPath := strings.Split(entry.Brickname, ":")
heal := HealEntry{PeerID: entry.HostUUID, Hostname: hostPath[0],
Brick: hostPath[1],
Connected: entry.Connected,
NumHealEntries: entries}
NumHealPending: numHealPending,
NumSplitBrain: numSplitBrain}
heals[hidx] = heal
}
}
Expand All @@ -40,22 +45,11 @@ func (g *GD1) getHealDetails(cmd string) ([]HealEntry, error) {
// HealInfo gets gluster vol heal info (GD1)
func (g GD1) HealInfo(vol string) ([]HealEntry, error) {
// Get the overall heal count
cmd := fmt.Sprintf("vol heal %s info --nolog", vol)
cmd := fmt.Sprintf("vol heal %s info summary --nolog", vol)
heals, err := g.getHealDetails(cmd)
if err != nil {
return nil, err
}

return heals, nil
}

// SplitBrainHealInfo gets gluster vol heal info (GD1)
func (g GD1) SplitBrainHealInfo(vol string) ([]HealEntry, error) {
cmd := fmt.Sprintf("vol heal %s info split-brain --nolog", vol)
splitBrainHeals, err := g.getHealDetails(cmd)
if err != nil {
return nil, err
}

return splitBrainHeals, nil
}
43 changes: 2 additions & 41 deletions pkg/glusterutils/healinfo_gd2.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,8 @@
package glusterutils

import "strings"
import "errors"

// HealInfo gets heal info from glusterd2 using rest api
func (g GD2) HealInfo(vol string) ([]HealEntry, error) {
client, err := initRESTClient(g.config)
if err != nil {
return nil, err
}
healinfo, herr := client.SelfHealInfo(vol)
if herr != nil {
return nil, herr
}
brickheal := make([]HealEntry, len(healinfo))
for hidx, heal := range healinfo {
hostPath := strings.Split(heal.Name, ":")
entry := HealEntry{PeerID: heal.HostID, Hostname: hostPath[0],
Brick: hostPath[1], Connected: heal.Status,
NumHealEntries: *(heal.Entries)}
brickheal[hidx] = entry
}
return brickheal, herr

}

// SplitBrainHealInfo gets heal info from glusterd2 using rest api
func (g GD2) SplitBrainHealInfo(vol string) ([]HealEntry, error) {
client, err := initRESTClient(g.config)
if err != nil {
return nil, err
}
healinfo, herr := client.SelfHealInfo(vol, "split-brain-info")
if herr != nil {
return nil, herr
}
brickheal := make([]HealEntry, len(healinfo))
for hidx, heal := range healinfo {
hostPath := strings.Split(heal.Name, ":")
entry := HealEntry{PeerID: heal.HostID, Hostname: hostPath[0],
Brick: hostPath[1], Connected: heal.Status,
NumHealEntries: *(heal.Entries)}
brickheal[hidx] = entry
}
return brickheal, herr

return nil, errors.New("not implemented for GD2")
}
4 changes: 2 additions & 2 deletions pkg/glusterutils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ type HealEntry struct {
Hostname string
Brick string
Connected string
NumHealEntries int64
NumHealPending int64
NumSplitBrain int64
}

// Snapshot represents a Volume snapshot
Expand Down Expand Up @@ -96,7 +97,6 @@ type GInterface interface {
LocalPeerID() (string, error)
IsLeader() (bool, error)
HealInfo(vol string) ([]HealEntry, error)
SplitBrainHealInfo(vol string) ([]HealEntry, error)
VolumeInfo() ([]Volume, error)
Snapshots() ([]Snapshot, error)
VolumeProfileInfo(vol string) ([]ProfileInfo, error)
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fi

echo "Building $BIN $VERSION"

go build $INSTALLFLAG -ldflags "${LDFLAGS}" -o "$OUTDIR/$BIN" "$GOPKG" || exit 1
GO111MODULE=off go build $INSTALLFLAG -ldflags "${LDFLAGS}" -o "$OUTDIR/$BIN" "$GOPKG" || exit 1

echo "Built $PACKAGE $VERSION at $OUTDIR/$BIN"

2 changes: 1 addition & 1 deletion scripts/pkg-version
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ get_release()
}

if test "x$1" = "x--full"; then
echo -n "v$(get_version)-$(get_release)"
printf "v%s-%s" "$(get_version)" "$(get_release)"
elif test "x$1" = "x--version"; then
get_version
elif test "x$1" = "x--release"; then
Expand Down