X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=adapter%2Fstats_api.go;h=7dc7dc38b446d7cc7e67e5a4f2bd22de98ecc563;hb=a4112fac7b86fe09650d2bb57969fe46404edd7d;hp=5b19173633800340f2903e28edecff6315a2fdf1;hpb=c380ee6064379258768fdfe4e9d4ad9138980ec0;p=govpp.git diff --git a/adapter/stats_api.go b/adapter/stats_api.go index 5b19173..7dc7dc3 100644 --- a/adapter/stats_api.go +++ b/adapter/stats_api.go @@ -16,7 +16,6 @@ package adapter import ( "errors" - "fmt" ) const ( @@ -53,36 +52,19 @@ type StatsAPI interface { // StatType represents type of stat directory and simply // defines what type of stat data is stored in the stat entry. -type StatType int +type StatType string const ( - _ StatType = 0 - ScalarIndex StatType = 1 - SimpleCounterVector StatType = 2 - CombinedCounterVector StatType = 3 - ErrorIndex StatType = 4 - NameVector StatType = 5 - Empty StatType = 6 + Unknown StatType = "UnknownStatType" + ScalarIndex StatType = "ScalarIndex" + SimpleCounterVector StatType = "SimpleCounterVector" + CombinedCounterVector StatType = "CombinedCounterVector" + ErrorIndex StatType = "ErrorIndex" + NameVector StatType = "NameVector" + Empty StatType = "Empty" + Symlink StatType = "Symlink" ) -func (d StatType) String() string { - switch d { - case ScalarIndex: - return "ScalarIndex" - case SimpleCounterVector: - return "SimpleCounterVector" - case CombinedCounterVector: - return "CombinedCounterVector" - case ErrorIndex: - return "ErrorIndex" - case NameVector: - return "NameVector" - case Empty: - return "Empty" - } - return fmt.Sprintf("UnknownStatType(%d)", d) -} - // StatDir defines directory of stats entries created by PrepareDir. type StatDir struct { Epoch int64 @@ -99,8 +81,9 @@ type StatIdentifier struct { // is defined by Type. type StatEntry struct { StatIdentifier - Type StatType - Data Stat + Type StatType + Data Stat + Symlink bool } // Counter represents simple counter with single value, which is usually packet count. @@ -129,6 +112,9 @@ type Stat interface { // IsZero returns true if all of its values equal to zero. IsZero() bool + // Type returns underlying type of a stat + Type() StatType + // isStat is intentionally unexported to limit implementations of interface to this package, isStat() } @@ -139,13 +125,13 @@ type ScalarStat float64 // ErrorStat represents stat for ErrorIndex. The array represents workers. type ErrorStat []Counter -// SimpleCounterStat represents stat for SimpleCounterVector. +// SimpleCounterStat represents indexed stat for SimpleCounterVector. // The outer array represents workers and the inner array represents interface/node/.. indexes. // Values should be aggregated per interface/node for every worker. // ReduceSimpleCounterStatIndex can be used to reduce specific index. type SimpleCounterStat [][]Counter -// CombinedCounterStat represents stat for CombinedCounterVector. +// CombinedCounterStat represents indexed stat for CombinedCounterVector. // The outer array represents workers and the inner array represents interface/node/.. indexes. // Values should be aggregated per interface/node for every worker. // ReduceCombinedCounterStatIndex can be used to reduce specific index. @@ -167,6 +153,11 @@ func (EmptyStat) isStat() {} func (s ScalarStat) IsZero() bool { return s == 0 } + +func (s ScalarStat) Type() StatType { + return ScalarIndex +} + func (s ErrorStat) IsZero() bool { if s == nil { return true @@ -178,6 +169,11 @@ func (s ErrorStat) IsZero() bool { } return true } + +func (s ErrorStat) Type() StatType { + return ErrorIndex +} + func (s SimpleCounterStat) IsZero() bool { if s == nil { return true @@ -191,6 +187,11 @@ func (s SimpleCounterStat) IsZero() bool { } return true } + +func (s SimpleCounterStat) Type() StatType { + return SimpleCounterVector +} + func (s CombinedCounterStat) IsZero() bool { if s == nil { return true @@ -207,6 +208,11 @@ func (s CombinedCounterStat) IsZero() bool { } return true } + +func (s CombinedCounterStat) Type() StatType { + return CombinedCounterVector +} + func (s NameStat) IsZero() bool { if s == nil { return true @@ -218,10 +224,19 @@ func (s NameStat) IsZero() bool { } return true } + +func (s NameStat) Type() StatType { + return NameVector +} + func (s EmptyStat) IsZero() bool { return true } +func (s EmptyStat) Type() StatType { + return Empty +} + // ReduceSimpleCounterStatIndex returns reduced SimpleCounterStat s for index i. func ReduceSimpleCounterStatIndex(s SimpleCounterStat, i int) uint64 { var val uint64