From 1765be124791eb14a61fb3746953f1fadfac4e46 Mon Sep 17 00:00:00 2001 From: gezimbll Date: Thu, 17 Oct 2024 11:46:10 +0200 Subject: [PATCH] modified ranking csv and model --- apier/v1/precache_it_test.go | 2 +- apier/v1/rankings_it_test.go | 25 ++- apier/v1/tprankings_it_test.go | 14 +- .../mysql/create_tariffplan_tables.sql | 3 +- .../postgres/create_tariffplan_tables.sql | 3 +- data/tariffplans/testtp/Rankings.csv | 4 +- engine/datamanager.go | 2 +- engine/librankings.go | 15 +- engine/libtrends.go | 2 +- engine/loader_csv_test.go | 20 +-- engine/model_helpers.go | 144 +++++++++--------- engine/model_helpers_test.go | 14 +- engine/models.go | 5 +- general_tests/trends_aut_it_test.go | 32 ++-- utils/apitpdata.go | 7 +- 15 files changed, 149 insertions(+), 143 deletions(-) diff --git a/apier/v1/precache_it_test.go b/apier/v1/precache_it_test.go index b90a7d5a4..bd6bbcf35 100644 --- a/apier/v1/precache_it_test.go +++ b/apier/v1/precache_it_test.go @@ -43,7 +43,7 @@ var ( precacheConfigDIR string //run tests for specific configuration // use this flag to test the APIBan implementation for precache - apiBan = flag.Bool("apiban", true, "used to control if we run the apiban tests") + apiBan = flag.Bool("apiban", false, "used to control if we run the apiban tests") sTestsPrecache = []func(t *testing.T){ testPrecacheInitCfg, diff --git a/apier/v1/rankings_it_test.go b/apier/v1/rankings_it_test.go index 6cf3bb3ab..ec339ea5a 100644 --- a/apier/v1/rankings_it_test.go +++ b/apier/v1/rankings_it_test.go @@ -23,7 +23,6 @@ package v1 import ( "path" "testing" - "time" "github.com/cgrates/birpc" "github.com/cgrates/birpc/context" @@ -126,11 +125,11 @@ func testRankingSRPCConn(t *testing.T) { func testRankingSLoadAdd(t *testing.T) { rankingProfile := &engine.RankingProfileWithAPIOpts{ RankingProfile: &engine.RankingProfile{ - Tenant: "cgrates.org", - ID: "SG_Sum", - QueryInterval: 2 * time.Minute, - StatIDs: []string{"SQProfile1"}, - MetricIDs: []string{"*sum"}, + Tenant: "cgrates.org", + ID: "SG_Sum", + Schedule: "@every 15m", + StatIDs: []string{"SQProfile1"}, + MetricIDs: []string{"*sum"}, }, } @@ -150,13 +149,13 @@ func testRankingSSetRankingProfile(t *testing.T) { ) rankingProfile = &engine.RankingProfileWithAPIOpts{ RankingProfile: &engine.RankingProfile{ - Tenant: "cgrates.org", - ID: "Ranking1", - QueryInterval: time.Second * 15, - StatIDs: []string{"SQ1", "SQ2"}, - MetricIDs: []string{"*acc", "*sum"}, - Sorting: "*asc", - ThresholdIDs: []string{"THD1", "THD2"}}, + Tenant: "cgrates.org", + ID: "Ranking1", + Schedule: "@every 15m", + StatIDs: []string{"SQ1", "SQ2"}, + MetricIDs: []string{"*acc", "*sum"}, + Sorting: "*asc", + ThresholdIDs: []string{"THD1", "THD2"}}, } if err := rankingRPC.Call(context.Background(), utils.APIerSv1GetRankingProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Ranking1"}, &reply); err == nil || diff --git a/apier/v1/tprankings_it_test.go b/apier/v1/tprankings_it_test.go index b3554976c..44ce24818 100644 --- a/apier/v1/tprankings_it_test.go +++ b/apier/v1/tprankings_it_test.go @@ -122,13 +122,13 @@ func testTPRankingsGetTPRankingBeforeSet(t *testing.T) { func testTPRankingsSetTPRanking(t *testing.T) { tpRanking = &utils.TPRankingProfile{ - Tenant: "cgrates.org", - TPid: "TPS1", - ID: "Ranking1", - QueryInterval: "1m", - Sorting: "*asc", - StatIDs: []string{"Stat1"}, - ThresholdIDs: []string{"ThreshValue", "ThreshValueTwo"}, + Tenant: "cgrates.org", + TPid: "TPS1", + ID: "Ranking1", + Schedule: "1m", + Sorting: "*asc", + StatIDs: []string{"Stat1"}, + ThresholdIDs: []string{"ThreshValue", "ThreshValueTwo"}, } sort.Strings(tpRanking.ThresholdIDs) var result string diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 88364faf4..8519cd5f0 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -305,11 +305,12 @@ CREATE TABLE tp_rankings( `tpid` varchar(64) NOT NULL, `tenant` varchar(64) NOT NULL, `id` varchar(64) NOT NULL, - `query_interval` varchar(64) NOT NULL, + `schedule` varchar(32) NOT NULL, `stat_ids` varchar(64) NOT NULL, `metric_ids` varchar(64) NOT NULL, `sorting` varchar(32) NOT NULL, `sorting_parameters` varchar(64) NOT NULL, + `stored` BOOLEAN NOT NULL, `threshold_ids` varchar(64) NOT NULL, `created_at` TIMESTAMP, PRIMARY KEY (`pk`), diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index b678b1999..832bc2572 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -299,11 +299,12 @@ CREATE TABLE tp_rankings( "tpid" varchar(64) NOT NULL, "tenant" varchar(64) NOT NULL, "id" varchar(64) NOT NULL, - "query_interval" varchar(64) NOT NULL, + "schedule" varchar(32) NOT NULL, "stat_ids" varchar(64) NOT NULL, "metric_ids" varchar(64) NOT NULL, "sorting" varchar(32) NOT NULL, "sorting_parameters" varchar(64) NOT NULL, + "stored" BOOLEAN NOT NULL, "threshold_ids" varchar(64) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE ); diff --git a/data/tariffplans/testtp/Rankings.csv b/data/tariffplans/testtp/Rankings.csv index 3669b3acd..c8b3cca3d 100644 --- a/data/tariffplans/testtp/Rankings.csv +++ b/data/tariffplans/testtp/Rankings.csv @@ -1,2 +1,2 @@ -#Tenant[0],Id[1],QueryInterval[2],StatIDs[2],MetricIDs[3],Sorting[4],SortingParameters[5],ThresholdIDs[6] -cgrates.org,RANK1,15m,Stats2;Stats3;Stats4,Metric1;Metric3,*asc,,TD1;THD2 \ No newline at end of file +#Tenant[0],Id[1],Schedule[2],StatIDs[3],MetricIDs[4],Sorting[5],SortingParameters[6],Stored[7],ThresholdIDs[8] +cgrates.org,RANK1,@every 15m,Stats2;Stats3;Stats4,Metric1;Metric3,*asc,,true,THD1;THD2 \ No newline at end of file diff --git a/engine/datamanager.go b/engine/datamanager.go index d85ab0d1e..77640242b 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -1338,7 +1338,7 @@ func (dm *DataManager) GetTrend(tenant, id string, return } } - if err := tr.uncompress(dm.ms); err != nil { + if err = tr.uncompress(dm.ms); err != nil { return nil, err } if cacheWrite { diff --git a/engine/librankings.go b/engine/librankings.go index b32e137e9..ddb640d51 100644 --- a/engine/librankings.go +++ b/engine/librankings.go @@ -13,14 +13,13 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program. If not, see +along with this program. If not, see */ package engine import ( "sync" - "time" "github.com/cgrates/cgrates/utils" ) @@ -33,11 +32,12 @@ type RankingProfileWithAPIOpts struct { type RankingProfile struct { Tenant string ID string - QueryInterval time.Duration + Schedule string StatIDs []string MetricIDs []string Sorting string SortingParameters []string + Stored bool ThresholdIDs []string } @@ -48,10 +48,10 @@ func (rkp *RankingProfile) TenantID() string { // Clone will clone a RankingProfile func (rkP *RankingProfile) Clone() (cln *RankingProfile) { cln = &RankingProfile{ - Tenant: rkP.Tenant, - ID: rkP.ID, - QueryInterval: rkP.QueryInterval, - Sorting: rkP.Sorting, + Tenant: rkP.Tenant, + ID: rkP.ID, + Schedule: rkP.Schedule, + Sorting: rkP.Sorting, } if rkP.StatIDs != nil { copy(cln.StatIDs, rkP.StatIDs) @@ -123,7 +123,6 @@ func newRankingSorter(sortingType string, sortingParams []string, return &rankingDescSorter{sortingParams, statMetrics}, nil } - return } // rankingDescSorter will sort data descendently for metrics in sortingParams or randomly if all equal diff --git a/engine/libtrends.go b/engine/libtrends.go index ffbc1e988..e0693bfbd 100644 --- a/engine/libtrends.go +++ b/engine/libtrends.go @@ -136,7 +136,7 @@ func (t *Trend) compress(ms Marshaler) (err error) { } func (t *Trend) uncompress(ms Marshaler) (err error) { - if t == nil || t.RunTimes != nil { + if t == nil || t.CompressedMetrics == nil { return } err = ms.Unmarshal(t.CompressedMetrics, &t.Metrics) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 46031ca9f..7af09c04c 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -237,8 +237,8 @@ cgrates.org,TestStats2,FLTR_1,2014-07-29T15:00:00Z,100,1s,2,*sum#~*req.Value;*su cgrates.org,TestStats2,,,,,2,*sum#~*req.Cost;*average#~*req.Cost,,true,true,20, ` RankingsCSVContent = ` -#Tenant[0],Id[1],QueryInterval[2],StatIDs[2],MetricIDs[3],Sorting[4],SortingParameters[5],ThresholdIDs[6] -cgrates.org,Ranking1,15m,Stats2;Stats3;Stats4,Metric1;Metric3,*asc,,THD1;THD2 +#Tenant[0],Id[1],Schedule[2],StatIDs[3],MetricIDs[4],Sorting[5],SortingParameters[6],StoredThresholdIDs[7] +cgrates.org,Ranking1,@every 5m,Stats2;Stats3;Stats4,Metric1;Metric3,*asc,,true,THD1;THD2 ` TrendsCSVContent = ` #Tenant[0],Id[1],Schedule[2],StatID[3],Metrics[4],TTL[5],QueueLength[6],MinItems[7],CorrelationType[8],Tolerance[9],Stored[10],ThresholdIDs[11] @@ -1337,14 +1337,14 @@ func TestLoadStatQueueProfiles(t *testing.T) { func TestLoadRankingProfiles(t *testing.T) { eRankings := map[utils.TenantID]*utils.TPRankingProfile{ {Tenant: "cgrates.org", ID: "Ranking1"}: { - TPid: testTPID, - Tenant: "cgrates.org", - ID: "Ranking1", - QueryInterval: "15m", - StatIDs: []string{"Stats2", "Stats3", "Stats4"}, - MetricIDs: []string{"Metric1", "Metric3"}, - Sorting: "*asc", - ThresholdIDs: []string{"THD1", "THD2"}, + TPid: testTPID, + Tenant: "cgrates.org", + ID: "Ranking1", + Schedule: "15m", + StatIDs: []string{"Stats2", "Stats3", "Stats4"}, + MetricIDs: []string{"Metric1", "Metric3"}, + Sorting: "*asc", + ThresholdIDs: []string{"THD1", "THD2"}, }, } rgkey := utils.TenantID{Tenant: "cgrates.org", ID: "RANKING1"} diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 03175edf0..9a5aba7f0 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -1463,8 +1463,8 @@ func StatQueueProfileToAPI(st *StatQueueProfile) (tpST *utils.TPStatProfile) { type RankingsMdls []*RankingsMdl func (tps RankingsMdls) CSVHeader() (result []string) { - return []string{"#" + utils.Tenant, utils.ID, utils.StatIDs, - utils.MetricIDs, utils.Sorting, utils.SortingParameters, + return []string{"#" + utils.Tenant, utils.ID, utils.Schedule, utils.StatIDs, + utils.MetricIDs, utils.Sorting, utils.SortingParameters, utils.Stored, utils.ThresholdIDs} } @@ -1473,24 +1473,28 @@ func (models RankingsMdls) AsTPRanking() (result []*utils.TPRankingProfile) { metricsMap := make(map[string]utils.StringSet) sortingParameterMap := make(map[string]utils.StringSet) statsMap := make(map[string]utils.StringSet) - msg := make(map[string]*utils.TPRankingProfile) + mrg := make(map[string]*utils.TPRankingProfile) for _, model := range models { key := &utils.TenantID{Tenant: model.Tenant, ID: model.ID} - sg, found := msg[key.TenantID()] + rg, found := mrg[key.TenantID()] if !found { - sg = &utils.TPRankingProfile{ - Tenant: model.Tenant, - TPid: model.Tpid, - ID: model.ID, - QueryInterval: model.QueryInterval, - Sorting: model.Sorting, + rg = &utils.TPRankingProfile{ + Tenant: model.Tenant, + TPid: model.Tpid, + ID: model.ID, + Schedule: model.Schedule, + Sorting: model.Sorting, + Stored: model.Stored, } } - if model.QueryInterval != utils.EmptyString { - sg.QueryInterval = model.QueryInterval + if model.Schedule != utils.EmptyString { + rg.Schedule = model.Schedule } if model.Sorting != utils.EmptyString { - sg.QueryInterval = model.QueryInterval + rg.Sorting = model.Sorting + } + if model.Stored { + rg.Stored = model.Stored } if model.StatIDs != utils.EmptyString { if _, has := statsMap[key.TenantID()]; !has { @@ -1516,12 +1520,12 @@ func (models RankingsMdls) AsTPRanking() (result []*utils.TPRankingProfile) { } metricsMap[key.TenantID()].AddSlice(strings.Split(model.MetricIDs, utils.InfieldSep)) } - msg[key.TenantID()] = sg + mrg[key.TenantID()] = rg } - result = make([]*utils.TPRankingProfile, len(msg)) + result = make([]*utils.TPRankingProfile, len(mrg)) i := 0 - for tntID, sg := range msg { - result[i] = sg + for tntID, rg := range mrg { + result[i] = rg result[i].StatIDs = statsMap[tntID].AsSlice() result[i].MetricIDs = metricsMap[tntID].AsSlice() result[i].SortingParameters = sortingParameterMap[tntID].AsSlice() @@ -1531,32 +1535,33 @@ func (models RankingsMdls) AsTPRanking() (result []*utils.TPRankingProfile) { return } -func APItoModelTPRanking(tpSG *utils.TPRankingProfile) (mdls RankingsMdls) { - if tpSG == nil { +func APItoModelTPRanking(tpRG *utils.TPRankingProfile) (mdls RankingsMdls) { + if tpRG == nil { return } - if len(tpSG.StatIDs) == 0 { + if len(tpRG.StatIDs) == 0 { mdl := &RankingsMdl{ - Tpid: tpSG.TPid, - Tenant: tpSG.Tenant, - ID: tpSG.ID, - QueryInterval: tpSG.QueryInterval, - Sorting: tpSG.Sorting, + Tpid: tpRG.TPid, + Tenant: tpRG.Tenant, + ID: tpRG.ID, + Schedule: tpRG.Schedule, + Sorting: tpRG.Sorting, + Stored: tpRG.Stored, } - for i, val := range tpSG.ThresholdIDs { + for i, val := range tpRG.ThresholdIDs { if i != 0 { mdl.ThresholdIDs += utils.InfieldSep } mdl.ThresholdIDs += val } - for i, metric := range tpSG.MetricIDs { + for i, metric := range tpRG.MetricIDs { if i != 0 { mdl.MetricIDs += utils.InfieldSep } mdl.MetricIDs += metric } - for i, sorting := range tpSG.SortingParameters { + for i, sorting := range tpRG.SortingParameters { if i != 0 { mdl.SortingParameters += utils.InfieldSep } @@ -1565,28 +1570,28 @@ func APItoModelTPRanking(tpSG *utils.TPRankingProfile) (mdls RankingsMdls) { mdls = append(mdls, mdl) } - for i, stat := range tpSG.StatIDs { + for i, stat := range tpRG.StatIDs { mdl := &RankingsMdl{ - Tpid: tpSG.TPid, - Tenant: tpSG.Tenant, - ID: tpSG.ID, + Tpid: tpRG.TPid, + Tenant: tpRG.Tenant, + ID: tpRG.ID, } if i == 0 { - mdl.QueryInterval = tpSG.QueryInterval - mdl.Sorting = tpSG.Sorting - for i, val := range tpSG.ThresholdIDs { + mdl.Schedule = tpRG.Schedule + mdl.Sorting = tpRG.Sorting + for i, val := range tpRG.ThresholdIDs { if i != 0 { mdl.ThresholdIDs += utils.InfieldSep } mdl.ThresholdIDs += val } - for i, metric := range tpSG.MetricIDs { + for i, metric := range tpRG.MetricIDs { if i != 0 { mdl.MetricIDs += utils.InfieldSep } mdl.MetricIDs += metric } - for i, sorting := range tpSG.SortingParameters { + for i, sorting := range tpRG.SortingParameters { if i != 0 { mdl.SortingParameters += utils.InfieldSep } @@ -1599,44 +1604,41 @@ func APItoModelTPRanking(tpSG *utils.TPRankingProfile) (mdls RankingsMdls) { return } -func APItoRanking(tpSG *utils.TPRankingProfile) (sg *RankingProfile, err error) { - sg = &RankingProfile{ - Tenant: tpSG.Tenant, - ID: tpSG.ID, - StatIDs: make([]string, len(tpSG.StatIDs)), - MetricIDs: make([]string, len(tpSG.MetricIDs)), - Sorting: tpSG.Sorting, - SortingParameters: make([]string, len(tpSG.SortingParameters)), - ThresholdIDs: make([]string, len(tpSG.ThresholdIDs)), +func APItoRanking(tpRG *utils.TPRankingProfile) (rg *RankingProfile, err error) { + rg = &RankingProfile{ + Tenant: tpRG.Tenant, + ID: tpRG.ID, + Schedule: tpRG.Schedule, + Sorting: tpRG.Sorting, + Stored: tpRG.Stored, + StatIDs: make([]string, len(tpRG.StatIDs)), + MetricIDs: make([]string, len(tpRG.MetricIDs)), + SortingParameters: make([]string, len(tpRG.SortingParameters)), + ThresholdIDs: make([]string, len(tpRG.ThresholdIDs)), } - - if tpSG.QueryInterval != utils.EmptyString { - if sg.QueryInterval, err = utils.ParseDurationWithNanosecs(tpSG.QueryInterval); err != nil { - return nil, err - } - } - copy(sg.StatIDs, tpSG.StatIDs) - copy(sg.ThresholdIDs, tpSG.ThresholdIDs) - copy(sg.MetricIDs, tpSG.MetricIDs) - return sg, nil + copy(rg.StatIDs, tpRG.StatIDs) + copy(rg.ThresholdIDs, tpRG.ThresholdIDs) + copy(rg.SortingParameters, tpRG.SortingParameters) + copy(rg.MetricIDs, tpRG.MetricIDs) + return rg, nil } -func RankingProfileToAPI(sg *RankingProfile) (tpSG *utils.TPRankingProfile) { - tpSG = &utils.TPRankingProfile{ - Tenant: sg.Tenant, - ID: sg.ID, - StatIDs: make([]string, len(sg.StatIDs)), - MetricIDs: make([]string, len(sg.MetricIDs)), - SortingParameters: make([]string, len(sg.SortingParameters)), - ThresholdIDs: make([]string, len(sg.ThresholdIDs)), +func RankingProfileToAPI(rg *RankingProfile) (tpRG *utils.TPRankingProfile) { + tpRG = &utils.TPRankingProfile{ + Tenant: rg.Tenant, + ID: rg.ID, + Schedule: rg.Schedule, + Sorting: rg.Sorting, + Stored: rg.Stored, + StatIDs: make([]string, len(rg.StatIDs)), + MetricIDs: make([]string, len(rg.MetricIDs)), + SortingParameters: make([]string, len(rg.SortingParameters)), + ThresholdIDs: make([]string, len(rg.ThresholdIDs)), } - if sg.QueryInterval != time.Duration(0) { - tpSG.QueryInterval = sg.QueryInterval.String() - } - copy(tpSG.StatIDs, sg.StatIDs) - copy(tpSG.ThresholdIDs, sg.ThresholdIDs) - copy(tpSG.MetricIDs, sg.MetricIDs) - copy(tpSG.SortingParameters, sg.SortingParameters) + copy(tpRG.StatIDs, rg.StatIDs) + copy(tpRG.ThresholdIDs, rg.ThresholdIDs) + copy(tpRG.MetricIDs, rg.MetricIDs) + copy(tpRG.SortingParameters, rg.SortingParameters) return } diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index ad88c0bca..5dc5eab15 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -5949,10 +5949,12 @@ func TestCSVHeaders(t *testing.T) { expected := []string{ "#" + utils.Tenant, utils.ID, + utils.Schedule, utils.StatIDs, utils.MetricIDs, utils.Sorting, utils.SortingParameters, + utils.Stored, utils.ThresholdIDs, } var tps RankingsMdls @@ -6004,7 +6006,7 @@ func TestRankingProfileToAPI(t *testing.T) { MetricIDs: []string{"metric1", "metric2"}, SortingParameters: []string{"sort1", "sort2"}, ThresholdIDs: []string{"threshold1", "threshold2"}, - QueryInterval: 30 * time.Minute, + Schedule: "@every 30m", } expected := &utils.TPRankingProfile{ @@ -6014,7 +6016,7 @@ func TestRankingProfileToAPI(t *testing.T) { MetricIDs: []string{"metric1", "metric2"}, SortingParameters: []string{"sort1", "sort2"}, ThresholdIDs: []string{"threshold1", "threshold2"}, - QueryInterval: "30m0s", + Schedule: "@every 30m", } result := RankingProfileToAPI(sg) if result.Tenant != expected.Tenant { @@ -6059,8 +6061,8 @@ func TestRankingProfileToAPI(t *testing.T) { } } } - if result.QueryInterval != expected.QueryInterval { - t.Errorf("Expected QueryInterval %s, got %s", expected.QueryInterval, result.QueryInterval) + if result.Schedule != expected.Schedule { + t.Errorf("Expected QueryInterval %s, got %s", expected.Schedule, result.Schedule) } } @@ -6081,7 +6083,7 @@ func TestAPItoModelTPRanking(t *testing.T) { TPid: "tpid1", Tenant: "cgrates.org", ID: "id1", - QueryInterval: "1h", + Schedule: "1h", Sorting: "asc", ThresholdIDs: []string{"threshold1", "threshold2"}, MetricIDs: []string{"metric1", "metric2"}, @@ -6093,7 +6095,7 @@ func TestAPItoModelTPRanking(t *testing.T) { Tpid: "tpid1", Tenant: "cgrates.org", ID: "id1", - QueryInterval: "1h", + Schedule: "1h", Sorting: "asc", StatIDs: "", ThresholdIDs: "threshold1" + utils.InfieldSep + "threshold2", diff --git a/engine/models.go b/engine/models.go index 2b4da9266..388f9ab75 100644 --- a/engine/models.go +++ b/engine/models.go @@ -288,12 +288,13 @@ type RankingsMdl struct { Tpid string Tenant string `index:"0" re:".*"` ID string `index:"1" re:".*"` - QueryInterval string `index:"2" re:".*"` + Schedule string `index:"2" re:".*"` StatIDs string `index:"3" re:".*"` MetricIDs string `index:"4" re:".*"` Sorting string `index:"5" re:".*"` SortingParameters string `index:"6" re:".*"` - ThresholdIDs string `index:"7" re:".*"` + Stored bool `index:"7" re:".*"` + ThresholdIDs string `index:"8" re:".*"` CreatedAt time.Time } diff --git a/general_tests/trends_aut_it_test.go b/general_tests/trends_aut_it_test.go index c446070f3..d90a205d4 100644 --- a/general_tests/trends_aut_it_test.go +++ b/general_tests/trends_aut_it_test.go @@ -151,17 +151,17 @@ func testScheduledTrends(t *testing.T) { // getting all scheduled trends for a tenant var schedTrends []utils.ScheduledTrend - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org"}}, TrendIDPrefix: []string{}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org"}}, TrendIDPrefixes: []string{}}, &schedTrends); err != nil { t.Error(err) } else if len(schedTrends) != 3 { t.Errorf("expected 3 schedTrends, got %d", len(schedTrends)) } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant1"}}, TrendIDPrefix: []string{}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant1"}}, TrendIDPrefixes: []string{}}, &schedTrends); err != nil { t.Error(err) } else if len(schedTrends) != 2 { t.Errorf("expected 2 schedTrends, got %d", len(schedTrends)) } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant2"}}, TrendIDPrefix: []string{}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant2"}}, TrendIDPrefixes: []string{}}, &schedTrends); err != nil { t.Error(err) } else if len(schedTrends) != 2 { t.Errorf("expected 2 schedTrends, got %d", len(schedTrends)) @@ -179,9 +179,9 @@ func testScheduledTrends(t *testing.T) { }, } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org"}}, TrendIDPrefix: []string{"TREND"}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org"}}, TrendIDPrefixes: []string{"TREND"}}, &schedTrends); err != nil { t.Error(err) - } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.EquateApproxTime(4*time.Second), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Prev")); diff != utils.EmptyString { + } else if diff := cmp.Diff(schedTrends[0], expTrends[0], cmpopts.EquateApproxTime(4*time.Second), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Previous")); diff != utils.EmptyString { t.Errorf("unexpected scheduled trends (-want +got)\n%s", diff) } @@ -191,9 +191,9 @@ func testScheduledTrends(t *testing.T) { }, } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant1"}}, TrendIDPrefix: []string{"TR_1"}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant1"}}, TrendIDPrefixes: []string{"TR_1"}}, &schedTrends); err != nil { t.Error(err) - } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Next"), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Prev")); diff != utils.EmptyString { + } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Next"), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Previous")); diff != utils.EmptyString { t.Errorf("unexpected scheduled trends (-want +got)\n%s", diff) } @@ -203,17 +203,17 @@ func testScheduledTrends2(t *testing.T) { // getting all scheduled trends for a tenant var schedTrends []utils.ScheduledTrend - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org"}}, TrendIDPrefix: []string{}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org"}}, TrendIDPrefixes: []string{}}, &schedTrends); err != nil { t.Error(err) } else if len(schedTrends) != 1 { t.Errorf("expected 1 schedTrends, got %d", len(schedTrends)) } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant1"}}, TrendIDPrefix: []string{}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant1"}}, TrendIDPrefixes: []string{}}, &schedTrends); err != nil { t.Error(err) } else if len(schedTrends) != 1 { t.Errorf("expected 1 schedTrends, got %d", len(schedTrends)) } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant2"}}, TrendIDPrefix: []string{}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant2"}}, TrendIDPrefixes: []string{}}, &schedTrends); err != nil { t.Error(err) } else if len(schedTrends) != 2 { t.Errorf("expected 2 schedTrends, got %d", len(schedTrends)) @@ -225,9 +225,9 @@ func testScheduledTrends2(t *testing.T) { Next: time.Now().Add(1 * time.Minute), }, } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org"}}, TrendIDPrefix: []string{}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org"}}, TrendIDPrefixes: []string{}}, &schedTrends); err != nil { t.Error(err) - } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.EquateApproxTime(1*time.Minute), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Prev")); diff != utils.EmptyString { + } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.EquateApproxTime(1*time.Minute), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Previous")); diff != utils.EmptyString { t.Errorf("unexpected scheduled trends (-want +got)\n%s", diff) } @@ -237,9 +237,9 @@ func testScheduledTrends2(t *testing.T) { Next: time.Now().Add(5 * time.Minute), }, } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant1"}}, TrendIDPrefix: []string{}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant1"}}, TrendIDPrefixes: []string{}}, &schedTrends); err != nil { t.Error(err) - } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.EquateApproxTime(5*time.Minute), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Prev")); diff != utils.EmptyString { + } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.EquateApproxTime(5*time.Minute), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Previous")); diff != utils.EmptyString { t.Errorf("unexpected scheduled trends (-want +got)\n%s", diff) } @@ -255,9 +255,9 @@ func testScheduledTrends2(t *testing.T) { }, } - if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant2"}}, TrendIDPrefix: []string{"Trend_avg"}}, &schedTrends); err != nil { + if err := trendAuQRpc.Call(context.Background(), utils.TrendSv1GetScheduledTrends, &utils.ArgScheduledTrends{TenantIDWithAPIOpts: utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant2"}}, TrendIDPrefixes: []string{"Trend_avg"}}, &schedTrends); err != nil { t.Error(err) - } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.EquateApproxTime(10*time.Minute), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Prev")); diff != utils.EmptyString { + } else if diff := cmp.Diff(schedTrends, expTrends, cmpopts.EquateApproxTime(10*time.Minute), cmpopts.IgnoreFields(utils.ScheduledTrend{}, "Previous")); diff != utils.EmptyString { t.Errorf("unexpected scheduled trends (-want +got)\n%s", diff) } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 082f94133..f192ebbbe 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1044,11 +1044,12 @@ type TPRankingProfile struct { TPid string Tenant string ID string - QueryInterval string + Schedule string StatIDs []string MetricIDs []string Sorting string SortingParameters []string + Stored bool ThresholdIDs []string } @@ -1673,8 +1674,8 @@ type ArgGetTrend struct { } type ScheduledTrend struct { - TrendID string - Next time.Time + TrendID string + Next time.Time Previous time.Time }