mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
StatS - fix metrics initialization
This commit is contained in:
@@ -98,7 +98,10 @@ func TestStatSV1GetStats(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(expectedIDs, reply) {
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedIDs, reply)
|
||||
}
|
||||
expectedMetrics := map[string]string{}
|
||||
expectedMetrics := map[string]string{
|
||||
utils.MetaASR: utils.NOT_AVAILABLE,
|
||||
utils.MetaACD: "",
|
||||
}
|
||||
if err := stsV1Rpc.Call("StatSV1.GetStatMetrics", "Stats1", &metrics); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedMetrics, metrics) {
|
||||
@@ -135,7 +138,10 @@ func TestStatSV1ProcessEvent(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("received reply: %s", reply)
|
||||
}
|
||||
expectedMetrics := map[string]string{}
|
||||
expectedMetrics := map[string]string{
|
||||
utils.MetaASR: "66.66667%",
|
||||
utils.MetaACD: "",
|
||||
}
|
||||
var metrics map[string]string
|
||||
if err := stsV1Rpc.Call("StatSV1.GetStatMetrics", "Stats1", &metrics); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Blocker,Stored,Weight,Thresholds
|
||||
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,true,20,THRESH1;THRESH2
|
||||
Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd,true,true,20,THRESH1;THRESH2
|
||||
|
||||
|
@@ -50,15 +50,22 @@ func (sis StatsInstances) remWithID(qID string) {
|
||||
// NewStatsInstance instantiates a StatsInstance
|
||||
func NewStatsInstance(sec *StatsEventCache, ms engine.Marshaler,
|
||||
sqCfg *engine.StatsQueue, sqSM *engine.SQStoredMetrics) (si *StatsInstance, err error) {
|
||||
si = &StatsInstance{sec: sec, ms: ms, cfg: sqCfg}
|
||||
si = &StatsInstance{sec: sec, ms: ms, cfg: sqCfg, sqMetrics: make(map[string]StatsMetric)}
|
||||
for _, metricID := range sqCfg.Metrics {
|
||||
if si.sqMetrics[metricID], err = NewStatsMetric(metricID); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if sqSM != nil {
|
||||
for evID, ev := range sqSM.SEvents {
|
||||
si.sec.Cache(evID, ev, si.cfg.ID)
|
||||
}
|
||||
si.sqItems = sqSM.SQItems
|
||||
for metricID := range si.sqMetrics {
|
||||
if si.sqMetrics[metricID], err = NewStatsMetric(metricID); err != nil {
|
||||
return
|
||||
if _, has := si.sqMetrics[metricID]; !has {
|
||||
if si.sqMetrics[metricID], err = NewStatsMetric(metricID); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if stored, has := sqSM.SQMetrics[metricID]; !has {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user