Fix stats API for vpp 22.06 73/36773/2
authorLukas Vogel <vogel@anapaya.net>
Thu, 28 Jul 2022 14:50:34 +0000 (16:50 +0200)
committerNathan Skrzypczak <nathan.skrzypczak@gmail.com>
Fri, 29 Jul 2022 07:40:44 +0000 (07:40 +0000)
VPP changed the error counters to be simple counters in
https://gerrit.fd.io/r/c/vpp/+/35640, that broke goVPP stats extraction.
This was partially fixed by https://gerrit.fd.io/r/c/govpp/+/36085,
however this fix didn't make it work completely.

There were some leftover conversions from dirType (== int) to StatType
(== string). Unfortunately the Go compiler does not flag those, they
would however be catched by go vet.

The fixes that are done here makes the stats extraction work for us
partially: We noticed that error counters are now of type symlink and
unfortunately updating a stat dir that contains symlink counters doesn't
work correctly. CopyEntryData, that is called when initializing the dir,
correctly handles the symlink counters. But updateStatOnIndex simply
ignores symlink counters because `dirType != entry.Type` will hold. We
didn't really figure out how to correctly handle this so this would need
to be picked up by someone who is more familiar with the code. For now
we work around this limitation by not using the GetErrorStats API and
instead manually read the dir everytime we want to access error
counters.

Co-authored-by: Sergio Gonzalez Monroy <monroy@anapaya.net>
Change-Id: I322133f362e782fea3e8a2be70967a796ba87b75
Signed-off-by: Lukas Vogel <vogel@anapaya.net>
adapter/statsclient/stat_segment_api.go
adapter/statsclient/statsclient.go
adapter/statsclient/statseg_v1.go
adapter/statsclient/statseg_v2.go

index fd7ef36..cb8b105 100644 (file)
@@ -16,10 +16,11 @@ package statsclient
 
 import (
        "fmt"
-       "git.fd.io/govpp.git/adapter"
        "sync/atomic"
        "time"
        "unsafe"
+
+       "git.fd.io/govpp.git/adapter"
 )
 
 var (
@@ -77,7 +78,7 @@ type statSegment interface {
        //
        // Note that if the index is equal to 0, the result pointer points to
        // the same memory address as the argument.
-       GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, dirType)
+       GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, adapter.StatType)
 
        // GetEpoch re-loads stats header and returns current epoch
        //and 'inProgress' value
index 6231f69..18c1266 100644 (file)
@@ -518,7 +518,7 @@ func (sc *StatsClient) getStatEntriesOnIndex(vector dirVector, indexes ...uint32
                        },
                        Type:    t,
                        Data:    d,
-                       Symlink: adapter.StatType(dirType) == adapter.Symlink,
+                       Symlink: dirType == adapter.Symlink,
                })
        }
        return entries, nil
@@ -602,7 +602,7 @@ func (sc *StatsClient) updateStatOnIndex(entry *adapter.StatEntry, vector dirVec
        dirPtr, dirName, dirType := sc.GetStatDirOnIndex(vector, entry.Index)
        if len(dirName) == 0 ||
                !bytes.Equal(dirName, entry.Name) ||
-               adapter.StatType(dirType) != entry.Type ||
+               dirType != entry.Type ||
                entry.Data == nil {
                return nil
        }
index 3f15ce2..202a1b0 100644 (file)
@@ -75,7 +75,7 @@ func (ss *statSegmentV1) getErrorVector() (unsafe.Pointer, error) {
        return nil, fmt.Errorf("error vector is not defined for stats API v1")
 }
 
-func (ss *statSegmentV1) GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, dirType) {
+func (ss *statSegmentV1) GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, adapter.StatType) {
        statSegDir := dirSegment(uintptr(v) + uintptr(index)*unsafe.Sizeof(statSegDirectoryEntryV1{}))
        dir := (*statSegDirectoryEntryV1)(statSegDir)
        var name []byte
@@ -85,7 +85,7 @@ func (ss *statSegmentV1) GetStatDirOnIndex(v dirVector, index uint32) (dirSegmen
                        break
                }
        }
-       return statSegDir, name, dir.directoryType
+       return statSegDir, name, getStatType(dir.directoryType, true)
 }
 
 func (ss *statSegmentV1) GetEpoch() (int64, bool) {
index 11a3679..aa65a3d 100644 (file)
@@ -72,7 +72,7 @@ func (ss *statSegmentV2) GetDirectoryVector() dirVector {
        return ss.adjust(dirVector(&header.dirVector))
 }
 
-func (ss *statSegmentV2) GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, dirType) {
+func (ss *statSegmentV2) GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, adapter.StatType) {
        statSegDir := dirSegment(uintptr(v) + uintptr(index)*unsafe.Sizeof(statSegDirectoryEntryV2{}))
        dir := (*statSegDirectoryEntryV2)(statSegDir)
        var name []byte
@@ -82,7 +82,7 @@ func (ss *statSegmentV2) GetStatDirOnIndex(v dirVector, index uint32) (dirSegmen
                        break
                }
        }
-       return statSegDir, name, dir.directoryType
+       return statSegDir, name, getStatType(dir.directoryType, ss.getErrorVector() != nil)
 }
 
 func (ss *statSegmentV2) GetEpoch() (int64, bool) {