From 6943579bbbf19aecb227c387c5b1479ec87006d8 Mon Sep 17 00:00:00 2001 From: Trevor North Date: Fri, 4 Mar 2022 12:05:46 +0000 Subject: [PATCH] Use heal summary for heal metrics --- gluster-exporter/metric_volume.go | 32 ++++++----------------- pkg/glusterutils/cache.go | 27 ------------------- pkg/glusterutils/gd1.go | 3 ++- pkg/glusterutils/healinfo_gd1.go | 22 ++++++---------- pkg/glusterutils/healinfo_gd2.go | 43 ++----------------------------- pkg/glusterutils/types.go | 4 +-- scripts/build.sh | 2 +- scripts/pkg-version | 2 +- 8 files changed, 24 insertions(+), 111 deletions(-) diff --git a/gluster-exporter/metric_volume.go b/gluster-exporter/metric_volume.go index 9a10ab6..9ccbc06 100644 --- a/gluster-exporter/metric_volume.go +++ b/gluster-exporter/metric_volume.go @@ -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 diff --git a/pkg/glusterutils/cache.go b/pkg/glusterutils/cache.go index 0ff40d0..0e14485 100644 --- a/pkg/glusterutils/cache.go +++ b/pkg/glusterutils/cache.go @@ -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() diff --git a/pkg/glusterutils/gd1.go b/pkg/glusterutils/gd1.go index 1ff26d2..b7a9449 100644 --- a/pkg/glusterutils/gd1.go +++ b/pkg/glusterutils/gd1.go @@ -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 { diff --git a/pkg/glusterutils/healinfo_gd1.go b/pkg/glusterutils/healinfo_gd1.go index a9ea812..a539508 100644 --- a/pkg/glusterutils/healinfo_gd1.go +++ b/pkg/glusterutils/healinfo_gd1.go @@ -21,7 +21,11 @@ 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 } @@ -29,7 +33,8 @@ func (g *GD1) getHealDetails(cmd string) ([]HealEntry, error) { heal := HealEntry{PeerID: entry.HostUUID, Hostname: hostPath[0], Brick: hostPath[1], Connected: entry.Connected, - NumHealEntries: entries} + NumHealPending: numHealPending, + NumSplitBrain: numSplitBrain} heals[hidx] = heal } } @@ -40,7 +45,7 @@ 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 @@ -48,14 +53,3 @@ func (g GD1) HealInfo(vol string) ([]HealEntry, error) { 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 -} diff --git a/pkg/glusterutils/healinfo_gd2.go b/pkg/glusterutils/healinfo_gd2.go index fff97e0..d942942 100644 --- a/pkg/glusterutils/healinfo_gd2.go +++ b/pkg/glusterutils/healinfo_gd2.go @@ -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") } diff --git a/pkg/glusterutils/types.go b/pkg/glusterutils/types.go index ff554a9..4992a83 100644 --- a/pkg/glusterutils/types.go +++ b/pkg/glusterutils/types.go @@ -65,7 +65,8 @@ type HealEntry struct { Hostname string Brick string Connected string - NumHealEntries int64 + NumHealPending int64 + NumSplitBrain int64 } // Snapshot represents a Volume snapshot @@ -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) diff --git a/scripts/build.sh b/scripts/build.sh index f1cb6fd..d947d70 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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" diff --git a/scripts/pkg-version b/scripts/pkg-version index 39086a0..dbd0308 100755 --- a/scripts/pkg-version +++ b/scripts/pkg-version @@ -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