From 7131698daf3a83c28a034f2146237b56e9297075 Mon Sep 17 00:00:00 2001 From: gezimblliku Date: Tue, 10 Sep 2024 15:10:28 +0200 Subject: [PATCH] updated processEEs to pass metrics in a map to event --- engine/stats.go | 14 ++++++++------ general_tests/stats_export_it_test.go | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/engine/stats.go b/engine/stats.go index 04cea6ec8..71f8f9a3c 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -317,7 +317,7 @@ func (sS *StatService) processThresholds(sQs StatQueues, opts map[string]any) (e return } -// processThresholds will pass the event for statQueue to EEs +// processEEs will pass the event for statQueue to EEs func (sS *StatService) processEEs(sQs StatQueues, opts map[string]any) (err error) { if len(sS.cgrcfg.StatSCfg().EEsConns) == 0 { return @@ -327,26 +327,28 @@ func (sS *StatService) processEEs(sQs StatQueues, opts map[string]any) (err erro opts = make(map[string]any) } for _, sq := range sQs { + metrics := make(map[string]any) + for metricID, metric := range sq.SQMetrics { + metrics[metricID] = metric.GetValue(sS.cgrcfg.GeneralCfg().RoundingDecimals) + } cgrEv := &utils.CGREvent{ Tenant: sq.Tenant, ID: utils.GenUUID(), Event: map[string]any{ utils.EventType: utils.StatUpdate, utils.StatID: sq.ID, + utils.Metrics: metrics, }, APIOpts: opts, } - for metricID, metric := range sq.SQMetrics { - cgrEv.Event[metricID] = metric.GetValue(sS.cgrcfg.GeneralCfg().RoundingDecimals) - } - cgrEventId := &CGREventWithEeIDs{ + cgrEventWithID := &CGREventWithEeIDs{ CGREvent: cgrEv, EeIDs: sS.cgrcfg.StatSCfg().EEsExporterIDs, } var reply map[string]map[string]any if err := sS.connMgr.Call(context.TODO(), sS.cgrcfg.StatSCfg().EEsConns, utils.EeSv1ProcessEvent, - cgrEventId, &reply); err != nil && + cgrEventWithID, &reply); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( fmt.Sprintf(" error: %s processing event %+v with EEs.", err.Error(), cgrEv)) diff --git a/general_tests/stats_export_it_test.go b/general_tests/stats_export_it_test.go index 4754db2d6..337cbbd8c 100644 --- a/general_tests/stats_export_it_test.go +++ b/general_tests/stats_export_it_test.go @@ -77,10 +77,10 @@ func TestStatsEEsExport(t *testing.T) { {"tag": "EventType", "path": "*uch.EventType", "type": "*variable", "value": "~*req.EventType"}, {"tag": "StatID", "path": "*uch.StatID", "type": "*variable", "value": "~*req.StatID"}, {"tag": "ExporterID", "path": "*uch.ExporterID", "type": "*variable", "value": "~*opts.*exporterID"}, - {"tag": "SumUsage", "path": "*uch.SumUsage", "type": "*variable", "value": "~*req.*sum#~*req.Usage"}, - {"tag": "AverageCallCost", "path": "*uch.AverageCallCost", "type": "*variable", "value": "~*req.*acc"}, - {"tag": "AnswerSeizureRatio", "path": "*uch.AnswerSeizureRatio", "type": "*variable", "value": "~*req.*asr"}, - {"tag": "TotalCallDuration", "path": "*uch.TotalCallDuration", "type": "*variable", "value": "~*req.*tcd"}, + {"tag": "SumUsage", "path": "*uch.SumUsage", "type": "*variable", "value": "~*req.Metrics.*sum#~*req.Usage"}, + {"tag": "AverageCallCost", "path": "*uch.AverageCallCost", "type": "*variable", "value": "~*req.Metrics.*acc"}, + {"tag": "AnswerSeizureRatio", "path": "*uch.AnswerSeizureRatio", "type": "*variable", "value": "~*req.Metrics.*asr"}, + {"tag": "TotalCallDuration", "path": "*uch.TotalCallDuration", "type": "*variable", "value": "~*req.Metrics.*tcd"}, ], }, ]