statsclient: fix retrieving stats type 03/32503/3
authorVladimir Lavor <vlavor@cisco.com>
Tue, 1 Jun 2021 07:21:49 +0000 (09:21 +0200)
committerVladimir Lavor <vlavor@cisco.com>
Tue, 1 Jun 2021 14:08:39 +0000 (16:08 +0200)
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Change-Id: Id51fa03ac69a2fc29aca5ff644178cdfcabe523c

adapter/statsclient/statsclient.go
adapter/statsclient/statseg_v2.go

index 0b16a77..8c5904d 100644 (file)
@@ -505,13 +505,17 @@ func (sc *StatsClient) getStatEntriesOnIndex(vector dirVector, indexes ...uint32
                if len(dirName) == 0 {
                        return
                }
+               var t adapter.StatType
                d := sc.CopyEntryData(dirPtr, ^uint32(0))
+               if d != nil {
+                       t = d.Type()
+               }
                entries = append(entries, adapter.StatEntry{
                        StatIdentifier: adapter.StatIdentifier{
                                Index: index,
                                Name:  dirName,
                        },
-                       Type:    d.Type(),
+                       Type:    t,
                        Data:    d,
                        Symlink: adapter.StatType(dirType) == adapter.Symlink,
                })
index 16f1729..0780248 100644 (file)
@@ -92,12 +92,14 @@ func (ss *statSegmentV2) GetEpoch() (int64, bool) {
 
 func (ss *statSegmentV2) CopyEntryData(segment dirSegment, index uint32) adapter.Stat {
        dirEntry := (*statSegDirectoryEntryV2)(segment)
-       if dirEntry.unionData == 0 {
-               debugf("data value or pointer not defined for %s", dirEntry.name)
+       typ := adapter.StatType(dirEntry.directoryType)
+       // skip zero pointer value
+       if typ != statDirScalarIndex && typ != statDirEmpty && dirEntry.unionData == 0 {
+               debugf("data pointer not defined for %s", dirEntry.name)
                return nil
        }
 
-       switch adapter.StatType(dirEntry.directoryType) {
+       switch typ {
        case statDirScalarIndex:
                return adapter.ScalarStat(dirEntry.unionData)