Remove LoadInfo out of CacheStats struct

This commit is contained in:
DanB
2016-08-31 17:35:24 +02:00
parent c7ad2ef980
commit ee6c2a5bc8
9 changed files with 29 additions and 64 deletions

View File

@@ -25,7 +25,6 @@ import (
"path"
"strconv"
"strings"
"time"
"github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/config"
@@ -769,20 +768,6 @@ func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.Cach
}
cs.Users = len(ups)
}
if loadHistInsts, err := self.AccountDb.GetLoadHistory(1, false, utils.NonTransactional); err != nil || len(loadHistInsts) == 0 {
if err != nil { // Not really an error here since we only count in cache
utils.Logger.Warning(fmt.Sprintf("ApierV1.GetCacheStats, error on GetLoadHistory: %s", err.Error()))
}
cs.LastLoadID = utils.NOT_AVAILABLE
cs.LastRatingLoadID = utils.NOT_AVAILABLE
cs.LastAccountingLoadID = utils.NOT_AVAILABLE
cs.LastLoadTime = utils.NOT_AVAILABLE
} else {
cs.LastLoadID = loadHistInsts[0].LoadID
cs.LastRatingLoadID = loadHistInsts[0].RatingLoadID
cs.LastAccountingLoadID = loadHistInsts[0].AccountingLoadID
cs.LastLoadTime = loadHistInsts[0].LoadTime.Format(time.RFC3339)
}
*reply = *cs
return nil
}

View File

@@ -828,7 +828,7 @@ func TestApierGetCacheStats(t *testing.T) {
var rcvStats *utils.CacheStats
var args utils.AttrCacheStats
err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats)
expectedStats := &utils.CacheStats{Destinations: 0, RatingPlans: 1, RatingProfiles: 0, Actions: 0, ActionPlans: 0, LastLoadID: utils.NOT_AVAILABLE, LastRatingLoadID: utils.NOT_AVAILABLE, LastAccountingLoadID: utils.NOT_AVAILABLE, LastLoadTime: utils.NOT_AVAILABLE}
expectedStats := &utils.CacheStats{Destinations: 0, RatingPlans: 1, RatingProfiles: 0, Actions: 0, ActionPlans: 0}
if err != nil {
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
} else if !reflect.DeepEqual(expectedStats, rcvStats) {
@@ -1247,7 +1247,7 @@ func TestApierResetDataBeforeLoadFromFolder(t *testing.T) {
var rcvStats *utils.CacheStats
var args utils.AttrCacheStats
err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats)
expectedStats := &utils.CacheStats{LastLoadID: rcvStats.LastLoadID, LastRatingLoadID: rcvStats.LastRatingLoadID, LastAccountingLoadID: rcvStats.LastAccountingLoadID, LastLoadTime: rcvStats.LastLoadTime}
expectedStats := new(utils.CacheStats)
if err != nil {
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
} else if !reflect.DeepEqual(rcvStats, expectedStats) {
@@ -1763,7 +1763,7 @@ func TestApierGetCacheStats2(t *testing.T) {
var rcvStats *utils.CacheStats
var args utils.AttrCacheStats
err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats)
expectedStats := &utils.CacheStats{LastLoadID: rcvStats.LastLoadID, LastRatingLoadID: rcvStats.LastRatingLoadID, LastAccountingLoadID: rcvStats.LastAccountingLoadID, LastLoadTime: rcvStats.LastLoadTime}
expectedStats := new(utils.CacheStats)
if err != nil {
t.Error("Got error on ApierV1.GetCacheStats: ", err.Error())
} else if !reflect.DeepEqual(expectedStats, rcvStats) {

View File

@@ -117,8 +117,7 @@ func TestSMGV1CacheStats(t *testing.T) {
var rcvStats *utils.CacheStats
expectedStats := &utils.CacheStats{Destinations: 0, RatingPlans: 4, RatingProfiles: 0, Actions: 7, ActionPlans: 4, SharedGroups: 0, Aliases: 0, ResourceLimits: 0,
DerivedChargers: 0, LcrProfiles: 0, CdrStats: 6, Users: 3,
LastLoadID: utils.NOT_AVAILABLE, LastRatingLoadID: utils.NOT_AVAILABLE, LastAccountingLoadID: utils.NOT_AVAILABLE, LastLoadTime: utils.NOT_AVAILABLE}
DerivedChargers: 0, LcrProfiles: 0, CdrStats: 6, Users: 3}
var args utils.AttrCacheStats
if err := smgV1Rpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil {
t.Error("Got error on ApierV2.GetCacheStats: ", err.Error())

View File

@@ -16,7 +16,6 @@ import (
var destCfgPath string
var destCfg *config.CGRConfig
var destRPC *rpc.Client
var destLoadInst utils.LoadInstance // Share load information between tests
func TestDestManagInitCfg(t *testing.T) {
if !*testIntegration {
@@ -81,10 +80,9 @@ func TestDestManagLoadTariffPlanFromFolderAll(t *testing.T) {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "alldests")}
var destLoadInst utils.LoadInstance
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
@@ -113,10 +111,9 @@ func TestDestManagLoadTariffPlanFromFolderRemoveSome(t *testing.T) {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome")}
var destLoadInst utils.LoadInstance
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
@@ -145,10 +142,9 @@ func TestDestManagLoadTariffPlanFromFolderRemoveSomeFlush(t *testing.T) {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome"), FlushDb: true}
var destLoadInst utils.LoadInstance
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
@@ -177,10 +173,9 @@ func TestDestManagLoadTariffPlanFromFolderAddBack(t *testing.T) {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "addback")}
var destLoadInst utils.LoadInstance
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
@@ -209,10 +204,9 @@ func TestDestManagLoadTariffPlanFromFolderAddOne(t *testing.T) {
return
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "addone")}
var destLoadInst utils.LoadInstance
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}
@@ -250,10 +244,9 @@ func TestDestManagCacheWithGetCache(t *testing.T) {
t.Errorf("Calling ApierV1.ReloadCache received: %+v", reply)
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true}
var destLoadInst utils.LoadInstance
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
@@ -274,8 +267,6 @@ func TestDestManagCacheWithGetCache(t *testing.T) {
attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheone"), FlushDb: true}
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
@@ -307,10 +298,9 @@ func TestDestManagCacheWithGetCost(t *testing.T) {
t.Errorf("Calling ApierV1.ReloadCache received: %+v", reply)
}
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true}
var destLoadInst utils.LoadInstance
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
@@ -340,8 +330,6 @@ func TestDestManagCacheWithGetCost(t *testing.T) {
attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheone"), FlushDb: true}
if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil {
t.Error(err)
} else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", destLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups

View File

@@ -118,8 +118,7 @@ func TestSTICacheStats(t *testing.T) {
return
}
var rcvStats *utils.CacheStats
expectedStats := &utils.CacheStats{Destinations: 1, RatingPlans: 1, RatingProfiles: 1, DerivedChargers: 1,
LastRatingLoadID: stiLoadInst.RatingLoadID, LastAccountingLoadID: stiLoadInst.AccountingLoadID, LastLoadTime: stiLoadInst.LoadTime.Format(time.RFC3339)}
expectedStats := &utils.CacheStats{Destinations: 1, RatingPlans: 1, RatingProfiles: 1, DerivedChargers: 1}
var args utils.AttrCacheStats
if err := stiRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil {
t.Error("Got error on ApierV2.GetCacheStats: ", err.Error())

View File

@@ -84,8 +84,6 @@ func TestTpLoadTariffPlanFromFolder(t *testing.T) {
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testtp")}
if err := tpRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &tpLoadInst); err != nil {
t.Error(err)
} else if tpLoadInst.RatingLoadID == "" || tpLoadInst.AccountingLoadID == "" {
t.Error("Empty loadId received, loadInstance: ", tpLoadInst)
}
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
}

View File

@@ -115,7 +115,7 @@ func TestTutSMGCacheStats(t *testing.T) {
var rcvStats *utils.CacheStats
expectedStats := &utils.CacheStats{Destinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, SharedGroups: 1, Aliases: 1, ResourceLimits: 0,
DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastLoadID: "LoadTariffPlanFromFolderAPI", LastRatingLoadID: smgLoadInst.RatingLoadID, LastAccountingLoadID: smgLoadInst.AccountingLoadID, LastLoadTime: smgLoadInst.LoadTime.Format(time.RFC3339)}
DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3}
var args utils.AttrCacheStats
if err := tutSMGRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil {
t.Error("Got error on ApierV2.GetCacheStats: ", err.Error())

View File

@@ -116,7 +116,7 @@ func TestTutLocalCacheStats(t *testing.T) {
var rcvStats *utils.CacheStats
expectedStats := &utils.CacheStats{Destinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, SharedGroups: 1, Aliases: 1, ResourceLimits: 0,
DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastLoadID: "LoadTariffPlanFromFolderAPI", LastRatingLoadID: loadInst.RatingLoadID, LastAccountingLoadID: loadInst.AccountingLoadID, LastLoadTime: loadInst.LoadTime.Format(time.RFC3339)}
DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3}
var args utils.AttrCacheStats
if err := tutLocalRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil {
t.Error("Got error on ApierV2.GetCacheStats: ", err.Error())
@@ -1102,7 +1102,7 @@ func TestTutLocalLeastCost(t *testing.T) {
} else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
} else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) {
t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[2], lcr.SupplierCosts[2])
t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts, lcr.SupplierCosts)
}
cd = engine.CallDescriptor{
Direction: "*out",

View File

@@ -578,24 +578,20 @@ type AttrCacheStats struct { // Add in the future filters here maybe so we avoid
}
type CacheStats struct {
Destinations int
ReverseDestinations int
RatingPlans int
RatingProfiles int
Actions int
ActionPlans int
SharedGroups int
DerivedChargers int
LcrProfiles int
CdrStats int
Users int
Aliases int
ReverseAliases int
ResourceLimits int
LastLoadID string
LastRatingLoadID string
LastAccountingLoadID string
LastLoadTime string
Destinations int
ReverseDestinations int
RatingPlans int
RatingProfiles int
Actions int
ActionPlans int
SharedGroups int
DerivedChargers int
LcrProfiles int
CdrStats int
Users int
Aliases int
ReverseAliases int
ResourceLimits int
}
type AttrExpFileCdrs struct {