From 8ed0a145f9cb1251273e1396e0f10893cd35c5f2 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 14 Jul 2021 14:11:49 +0300 Subject: [PATCH] Updated caps birpc server --- cores/caps.go | 3 +++ .../dispatchers/all_mysql/cgrates.json | 6 ++++- data/conf/samples/ees/cgrates.json | 2 +- dispatchers/attributes_it_test.go | 8 +++--- dispatchers/sessions_it_test.go | 8 +++--- ees/nats_it_test.go | 8 +++++- engine/libstats.go | 18 ++++++++++++- engine/libstats_test.go | 25 +++++++++++++++++-- general_tests/filters_it_test.go | 2 +- 9 files changed, 65 insertions(+), 15 deletions(-) diff --git a/cores/caps.go b/cores/caps.go index 559b50059..d308a0350 100644 --- a/cores/caps.go +++ b/cores/caps.go @@ -146,6 +146,9 @@ func newCapsBiRPCJSONCodec(conn conn, caps *engine.Caps, anz *analyzers.Analyzer } func newCapsBiRPCCodec(sc rpc2.Codec, caps *engine.Caps) rpc2.Codec { + if !caps.IsLimited() { + return sc + } return &capsBiRPCCodec{ sc: sc, caps: caps, diff --git a/data/conf/samples/dispatchers/all_mysql/cgrates.json b/data/conf/samples/dispatchers/all_mysql/cgrates.json index b1ab1e83a..633c3704a 100644 --- a/data/conf/samples/dispatchers/all_mysql/cgrates.json +++ b/data/conf/samples/dispatchers/all_mysql/cgrates.json @@ -10,7 +10,7 @@ "listen": { - "rpc_json": ":6012", + "rpc_json": ":6012", "rpc_gob": ":6013", "http": ":6080", }, @@ -31,6 +31,10 @@ "strategy": "*first", "conns": [{"address": "127.0.0.1:6012", "transport":"*json"}], }, + "rplConn": { + "strategy": "*broadcast_sync", + "conns": [{"address": "127.0.0.1:7012", "transport":"*json"}], + } }, diff --git a/data/conf/samples/ees/cgrates.json b/data/conf/samples/ees/cgrates.json index 05553768b..605858261 100644 --- a/data/conf/samples/ees/cgrates.json +++ b/data/conf/samples/ees/cgrates.json @@ -414,7 +414,7 @@ ] }, { - "id": "HTTPJsonMapExporter", + "id": "NatsJsonMapExporter", "type": "*nats_json_map", "export_path": "nats://localhost:4222", "attempts": 1, diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go index 5df7c3976..aa9525085 100644 --- a/dispatchers/attributes_it_test.go +++ b/dispatchers/attributes_it_test.go @@ -245,7 +245,7 @@ func testDspAttrGetAttrFailover(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1002_SIMPLEAUTH"}, + MatchedProfiles: []string{"cgrates.org:ATTR_1002_SIMPLEAUTH"}, AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", @@ -445,7 +445,7 @@ func testDspAttrTestAuthKey2(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1001_SIMPLEAUTH"}, + MatchedProfiles: []string{"cgrates.org:ATTR_1001_SIMPLEAUTH"}, AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ @@ -529,7 +529,7 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1002_SIMPLEAUTH"}, + MatchedProfiles: []string{"cgrates.org:ATTR_1002_SIMPLEAUTH"}, AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", @@ -601,7 +601,7 @@ func testDspAttrGetAttrInternal(t *testing.T) { } eRply := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1003_SIMPLEAUTH"}, + MatchedProfiles: []string{"cgrates.org:ATTR_1003_SIMPLEAUTH"}, AlteredFields: []string{"*req.Password"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", diff --git a/dispatchers/sessions_it_test.go b/dispatchers/sessions_it_test.go index 4bda4a893..b1127ba67 100644 --- a/dispatchers/sessions_it_test.go +++ b/dispatchers/sessions_it_test.go @@ -382,7 +382,7 @@ func testDspSessionUpdate(t *testing.T) { t.Error(err) } eAttrs := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_ACNT_1001"}, + MatchedProfiles: []string{"cgrates.org:ATTR_ACNT_1001"}, AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", @@ -453,7 +453,7 @@ func testDspSessionUpdate2(t *testing.T) { t.Fatal(err) } eAttrs := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1001_SESSIONAUTH"}, + MatchedProfiles: []string{"cgrates.org:ATTR_1001_SESSIONAUTH"}, AlteredFields: []string{"*req.LCRProfile", "*req.Password", "*req.RequestType", "*req.PaypalAccount"}, CGREvent: &utils.CGREvent{ @@ -608,7 +608,7 @@ func testDspSessionProcessEvent(t *testing.T) { t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation) } eAttrs := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_ACNT_1001"}, + MatchedProfiles: []string{"cgrates.org:ATTR_ACNT_1001"}, AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ @@ -687,7 +687,7 @@ func testDspSessionProcessEvent2(t *testing.T) { t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation) } eAttrs := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1001_SIMPLEAUTH"}, + MatchedProfiles: []string{"cgrates.org:ATTR_1001_SIMPLEAUTH"}, AlteredFields: []string{"*req.EventName", "*req.Password"}, CGREvent: &utils.CGREvent{ diff --git a/ees/nats_it_test.go b/ees/nats_it_test.go index 54d49d721..1556b3f95 100644 --- a/ees/nats_it_test.go +++ b/ees/nats_it_test.go @@ -43,7 +43,13 @@ func TestNatsEE(t *testing.T) { if err != nil { t.Fatal(err) } - evExp, err := NewEventExporter(cfg, 5, new(engine.FilterS)) + var idx int + for idx = range cfg.EEsCfg().Exporters { + if cfg.EEsCfg().Exporters[idx].ID == "NatsJsonMapExporter" { + break + } + } + evExp, err := NewEventExporter(cfg, idx, new(engine.FilterS)) if err != nil { t.Fatal(err) } diff --git a/engine/libstats.go b/engine/libstats.go index 56313e58d..31fcbbff1 100644 --- a/engine/libstats.go +++ b/engine/libstats.go @@ -386,10 +386,26 @@ func (sq *StatQueue) UnmarshalJSON(data []byte) (err error) { return fmt.Errorf("unsupported metric type <%s>", metricSplit[0]) } if err = json.Unmarshal([]byte(val), metric); err != nil { - fmt.Println(1) return } sq.SQMetrics[metricID] = metric } return } + +// UnmarshalJSON here only to fully support json for StatQueue +func (ssq *StatQueueWithAPIOpts) UnmarshalJSON(data []byte) (err error) { + sq := new(StatQueue) + if err = json.Unmarshal(data, &sq); err != nil { + return + } + i := struct { + APIOpts map[string]interface{} + }{} + if err = json.Unmarshal(data, &i); err != nil { + return + } + ssq.StatQueue = sq + ssq.APIOpts = i.APIOpts + return +} diff --git a/engine/libstats_test.go b/engine/libstats_test.go index 2266ed783..585a85311 100644 --- a/engine/libstats_test.go +++ b/engine/libstats_test.go @@ -1227,7 +1227,7 @@ func TestLibstatsaddStatEventNoPass(t *testing.T) { } func TestStatQueueJSONMarshall(t *testing.T) { - rply := new(StatQueue) + var rply *StatQueue exp, err := NewStatQueue("cgrates.org", "STS", []*MetricWithFilters{ {MetricID: utils.MetaASR}, {MetricID: utils.MetaTCD}, @@ -1235,10 +1235,31 @@ func TestStatQueueJSONMarshall(t *testing.T) { if err != nil { t.Fatal(err) } - if err = json.Unmarshal([]byte(utils.ToJSON(exp)), rply); err != nil { + if err = json.Unmarshal([]byte(utils.ToJSON(exp)), &rply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(rply, exp) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(exp), utils.ToJSON(rply)) } } + +func TestStatQueueWithAPIOptsJSONMarshall(t *testing.T) { + rply := &StatQueueWithAPIOpts{ /*StatQueue: &StatQueue{}*/ } + exp, err := NewStatQueue("cgrates.org", "STS", []*MetricWithFilters{ + {MetricID: utils.MetaASR}, + {MetricID: utils.MetaTCD}, + }, 1) + exp2 := &StatQueueWithAPIOpts{ + StatQueue: exp, + APIOpts: map[string]interface{}{"a": "a"}, + } + if err != nil { + t.Fatal(err) + } + if err = json.Unmarshal([]byte(utils.ToJSON(exp2)), rply); err != nil { + t.Fatal(err) + } else if !reflect.DeepEqual(rply, exp2) { + t.Errorf("Expected: %s , received: %s", utils.ToJSON(exp2), utils.ToJSON(rply)) + } + +} diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go index 4bb71fa26..fc6eda212 100644 --- a/general_tests/filters_it_test.go +++ b/general_tests/filters_it_test.go @@ -1030,7 +1030,7 @@ func testV1FltrAttributesPrefix(t *testing.T) { processedEv := &engine.AttrSProcessEventReply{ AlteredFields: []string{"*req.CustomField"}, - MatchedProfiles: []string{"cgrates.org:ATTR_1001"}, + MatchedProfiles: []string{"cgrates.new:ATTR_1001"}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.new",