Merge fixes

This commit is contained in:
adi
2022-09-22 16:07:16 +03:00
committed by Dan Christian Bogos
parent 15fbc25351
commit 67163a1ff5
22 changed files with 224 additions and 123 deletions

View File

@@ -162,7 +162,7 @@ func (alS *AttributeS) processEvent(ctx *context.Context, tnt string, args *util
return
}
var ignFilters bool
if ignFilters, err = GetBoolOpts(ctx, tnt, args, alS.fltrS, alS.cfg.AttributeSCfg().Opts.ProfileIgnoreFilters,
if ignFilters, err = GetBoolOpts(ctx, tnt, evNm, alS.fltrS, alS.cfg.AttributeSCfg().Opts.ProfileIgnoreFilters,
config.AttributesProfileIgnoreFiltersDftOpt, utils.MetaProfileIgnoreFilters); err != nil {
return
}
@@ -256,18 +256,20 @@ func (alS *AttributeS) V1GetAttributeForEvent(ctx *context.Context, args *utils.
config.AttributesProfileIDsDftOpt, utils.OptsAttributesProfileIDs); err != nil {
return
}
var ignFilters bool
if ignFilters, err = GetBoolOpts(ctx, tnt, args, alS.fltrS, alS.cfg.AttributeSCfg().Opts.ProfileIgnoreFilters,
config.AttributesProfileIgnoreFiltersDftOpt, utils.MetaProfileIgnoreFilters); err != nil {
return
}
attrPrf, err := alS.attributeProfileForEvent(ctx, tnt, attrIDs, utils.MapStorage{
evNM := utils.MapStorage{
utils.MetaReq: args.Event,
utils.MetaOpts: args.APIOpts,
utils.MetaVars: utils.MapStorage{
utils.OptsAttributesProcessRuns: 0,
},
}, utils.EmptyString, make(map[string]int), 0, ignFilters)
}
var ignFilters bool
if ignFilters, err = GetBoolOpts(ctx, tnt, evNM, alS.fltrS, alS.cfg.AttributeSCfg().Opts.ProfileIgnoreFilters,
config.AttributesProfileIgnoreFiltersDftOpt, utils.MetaProfileIgnoreFilters); err != nil {
return
}
attrPrf, err := alS.attributeProfileForEvent(ctx, tnt, attrIDs, evNM,
utils.EmptyString, make(map[string]int), 0, ignFilters)
if err != nil {
if err != utils.ErrNotFound {
err = utils.NewErrServerError(err)

View File

@@ -195,7 +195,7 @@ func (cdrS *CDRServer) eeSProcessEvent(ctx *context.Context, cgrEv *utils.CGREve
func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (evs []*utils.EventsWithOpts, err error) {
// making the options
var attrS bool
if attrS, err = GetBoolOpts(ctx, ev.Tenant, ev, cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Attributes,
if attrS, err = GetBoolOpts(ctx, ev.Tenant, ev.AsDataProvider(), cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Attributes,
config.CDRsAttributesDftOpt, utils.OptsAttributeS); err != nil {
return
}
@@ -211,7 +211,7 @@ func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (e
var cgrEvs []*utils.CGREvent
var chrgS bool
if chrgS, err = GetBoolOpts(ctx, ev.Tenant, ev, cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Chargers,
if chrgS, err = GetBoolOpts(ctx, ev.Tenant, ev.AsDataProvider(), cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Chargers,
config.CDRsChargersDftOpt, utils.OptsChargerS); err != nil {
return
}
@@ -231,7 +231,7 @@ func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (e
var rateS bool
for _, cgrEv := range cgrEvs {
if rateS, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv, cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Rates,
if rateS, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv.AsDataProvider(), cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Rates,
config.CDRsRatesDftOpt, utils.OptsRateS); err != nil {
return
}
@@ -247,7 +247,7 @@ func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (e
var acntS bool
for _, cgrEv := range cgrEvs {
if acntS, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv, cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Accounts,
if acntS, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv.AsDataProvider(), cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Accounts,
config.CDRsAccountsDftOpt, utils.OptsAccountS); err != nil {
return
}
@@ -287,7 +287,7 @@ func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (e
}
var export bool
for _, cgrEv := range cgrEvs {
if export, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv, cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Export,
if export, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv.AsDataProvider(), cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Export,
config.CDRsExportDftOpt, utils.OptsCDRsExport); err != nil {
return
}
@@ -307,7 +307,7 @@ func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (e
var thdS bool
for _, cgrEv := range cgrEvs {
if thdS, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv, cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Thresholds,
if thdS, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv.AsDataProvider(), cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Thresholds,
config.CDRsThresholdsDftOpt, utils.OptsThresholdS); err != nil {
return
}
@@ -323,7 +323,7 @@ func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (e
var stS bool
for _, cgrEv := range cgrEvs {
if stS, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv, cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Stats,
if stS, err = GetBoolOpts(ctx, cgrEv.Tenant, cgrEv.AsDataProvider(), cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Stats,
config.CDRsStatsDftOpt, utils.OptsStatS); err != nil {
return
}

View File

@@ -171,19 +171,19 @@ func GetIntOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS *Filter
// GetBoolOpts checks the specified option names in order among the keys in APIOpts returning the first value it finds as bool, otherwise it
// returns the config option if at least one filter passes or the default value if none of them do
func GetBoolOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS *FilterS, dynOpts []*utils.DynamicBoolOpt,
func GetBoolOpts(ctx *context.Context, tnt string, dP utils.DataProvider, fS *FilterS, dynOpts []*utils.DynamicBoolOpt,
dftOpt bool, optNames ...string) (cfgOpt bool, err error) {
optsDP := GetAPIOptsFromDataProvider(dP)
for _, optName := range optNames {
if opt, has := ev.APIOpts[optName]; has {
if opt, has := optsDP[optName]; has {
return utils.IfaceAsBool(opt)
}
}
evDP := ev.AsDataProvider()
for _, opt := range dynOpts { // iterate through the options
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
continue
}
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, dP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
return false, err
} else if pass {
return opt.Value, nil

View File

@@ -785,7 +785,7 @@ func TestLibFiltersGetBoolOptsReturnConfigOpt(t *testing.T) {
}
expected := true
if rcv, err := GetBoolOpts(context.Background(), "cgrates.org", ev, fS, dynOpts,
if rcv, err := GetBoolOpts(context.Background(), "cgrates.org", ev.AsDataProvider(), fS, dynOpts,
config.ThresholdsProfileIgnoreFiltersDftOpt, utils.MetaProfileIgnoreFilters); err != nil {
t.Error(err)
} else if rcv != expected {
@@ -816,7 +816,7 @@ func TestLibFiltersGetBoolOptsFilterCheckErr(t *testing.T) {
}
experr := `inline parse error for string: <*string.invalid:filter>`
if _, err := GetBoolOpts(context.Background(), "cgrates.org", ev, fS, dynOpts,
if _, err := GetBoolOpts(context.Background(), "cgrates.org", ev.AsDataProvider(), fS, dynOpts,
config.ThresholdsProfileIgnoreFiltersDftOpt, utils.MetaProfileIgnoreFilters); err == nil ||
err.Error() != experr {
t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err)
@@ -845,7 +845,7 @@ func TestLibFiltersGetBoolOptsReturnDefaultOpt(t *testing.T) {
},
}
if rcv, err := GetBoolOpts(context.Background(), "cgrates.org", ev, fS, dynOpts,
if rcv, err := GetBoolOpts(context.Background(), "cgrates.org", ev.AsDataProvider(), fS, dynOpts,
config.ThresholdsProfileIgnoreFiltersDftOpt, utils.MetaProfileIgnoreFilters); err != nil {
t.Error(err)
} else if rcv != config.ThresholdsProfileIgnoreFiltersDftOpt {
@@ -879,7 +879,7 @@ func TestLibFiltersGetBoolOptsReturnOptFromAPIOpts(t *testing.T) {
}
expected := true
if rcv, err := GetBoolOpts(context.Background(), "cgrates.org", ev, fS, dynOpts,
if rcv, err := GetBoolOpts(context.Background(), "cgrates.org", ev.AsDataProvider(), fS, dynOpts,
config.ThresholdsProfileIgnoreFiltersDftOpt, "nonExistingAPIOpt", utils.MetaProfileIgnoreFilters); err != nil {
t.Error(err)
} else if rcv != expected {

View File

@@ -182,6 +182,19 @@ func NewServiceWithName(val interface{}, name string, useName bool) (_ IntServic
return s, nil
}
func GetAPIOptsFromDataProvider(dP utils.DataProvider) map[string]interface{} {
switch v := dP.(type) {
case utils.MapStorage:
if x, has := v[utils.MetaOpts]; has {
return x.(map[string]interface{})
}
return make(map[string]interface{})
case MapEvent:
return v
}
return nil
}
func NewDispatcherService(val interface{}) (_ IntService, err error) {
var srv *birpc.Service
if srv, err = birpc.NewService(val, utils.EmptyString, false); err != nil {

View File

@@ -198,7 +198,7 @@ func (rpS *RouteS) matchingRouteProfilesForEvent(ctx *context.Context, tnt strin
func newOptsGetRoutes(ctx *context.Context, ev *utils.CGREvent, fS *FilterS, cfgOpts *config.RoutesOpts) (opts *optsGetRoutes, err error) {
var ignoreErrors bool
if ignoreErrors, err = GetBoolOpts(ctx, ev.Tenant, ev, fS, cfgOpts.IgnoreErrors,
if ignoreErrors, err = GetBoolOpts(ctx, ev.Tenant, ev.AsDataProvider(), fS, cfgOpts.IgnoreErrors,
config.RoutesIgnoreErrorsDftOpt, utils.OptsRoutesIgnoreErrors); err != nil {
return
}

View File

@@ -330,7 +330,7 @@ func (sS *StatS) processEvent(ctx *context.Context, tnt string, args *utils.CGRE
return
}
var ignFilters bool
if ignFilters, err = GetBoolOpts(ctx, tnt, args, sS.fltrS, sS.cfg.StatSCfg().Opts.ProfileIgnoreFilters,
if ignFilters, err = GetBoolOpts(ctx, tnt, evNm, sS.fltrS, sS.cfg.StatSCfg().Opts.ProfileIgnoreFilters,
config.StatsProfileIgnoreFilters, utils.MetaProfileIgnoreFilters); err != nil {
return
}
@@ -421,13 +421,14 @@ func (sS *StatS) V1GetStatQueuesForEvent(ctx *context.Context, args *utils.CGREv
config.StatsProfileIDsDftOpt, utils.OptsStatsProfileIDs); err != nil {
return
}
evDp := args.AsDataProvider()
var ignFilters bool
if ignFilters, err = GetBoolOpts(ctx, tnt, args, sS.fltrS, sS.cfg.StatSCfg().Opts.ProfileIgnoreFilters,
if ignFilters, err = GetBoolOpts(ctx, tnt, evDp, sS.fltrS, sS.cfg.StatSCfg().Opts.ProfileIgnoreFilters,
config.StatsProfileIgnoreFilters, utils.MetaProfileIgnoreFilters); err != nil {
return
}
var sQs StatQueues
if sQs, err = sS.matchingStatQueuesForEvent(ctx, tnt, sqIDs, args.AsDataProvider(), ignFilters); err != nil {
if sQs, err = sS.matchingStatQueuesForEvent(ctx, tnt, sqIDs, evDp, ignFilters); err != nil {
return
}

View File

@@ -336,7 +336,7 @@ func (tS *ThresholdS) matchingThresholdsForEvent(ctx *context.Context, tnt strin
return
}
var ignFilters bool
if ignFilters, err = GetBoolOpts(ctx, tnt, args, tS.fltrS, tS.cfg.ThresholdSCfg().Opts.ProfileIgnoreFilters,
if ignFilters, err = GetBoolOpts(ctx, tnt, evNm, tS.fltrS, tS.cfg.ThresholdSCfg().Opts.ProfileIgnoreFilters,
config.ThresholdsProfileIgnoreFiltersDftOpt, utils.MetaProfileIgnoreFilters); err != nil {
return
}