mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
cfg: add stats/thresholds_conns to dns_agent
This commit is contained in:
committed by
Dan Christian Bogos
parent
fc905f0e9c
commit
9b706f57ac
@@ -825,6 +825,8 @@ const CGRATES_CFG_JSON = `
|
||||
}
|
||||
],
|
||||
"sessions_conns": ["*internal"],
|
||||
"stats_conns": [], // connections to StatS, empty to disable: <""|*internal|$rpc_conns_id>
|
||||
"thresholds_conns": [], // connections to ThresholdS, empty to disable: <""|*internal|$rpc_conns_id>
|
||||
"timezone": "", // timezone of the events if not specified <UTC|Local|$IANA_TZ_DB>
|
||||
"request_processors": [] // request processors to be applied to DNS messages
|
||||
},
|
||||
|
||||
@@ -710,7 +710,9 @@ func testCGRConfigReloadDNSAgent(t *testing.T) {
|
||||
Network: "tcp",
|
||||
},
|
||||
},
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS)},
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS)},
|
||||
StatSConns: []string{},
|
||||
ThresholdSConns: []string{},
|
||||
// Timezone string
|
||||
// RequestProcessors []*RequestProcessor
|
||||
}
|
||||
|
||||
@@ -1162,9 +1162,11 @@ func TestDNSAgentJsonCfg(t *testing.T) {
|
||||
Address: utils.StringPointer("127.0.0.1:53"),
|
||||
},
|
||||
},
|
||||
Sessions_conns: &[]string{utils.ConcatenatedKey(utils.MetaInternal)},
|
||||
Timezone: utils.StringPointer(""),
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{},
|
||||
SessionSConns: &[]string{utils.ConcatenatedKey(utils.MetaInternal)},
|
||||
StatSConns: &[]string{},
|
||||
ThresholdSConns: &[]string{},
|
||||
Timezone: utils.StringPointer(""),
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{},
|
||||
}
|
||||
dfCgrJSONCfg, err := NewCgrJsonCfgFromBytes([]byte(CGRATES_CFG_JSON))
|
||||
if err != nil {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -478,6 +478,22 @@ func (cfg *CGRConfig) checkConfigSanity() error {
|
||||
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.DNSAgent, connID)
|
||||
}
|
||||
}
|
||||
for _, connID := range cfg.dnsAgentCfg.StatSConns {
|
||||
if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.sessionSCfg.Enabled {
|
||||
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.StatS, utils.DNSAgent)
|
||||
}
|
||||
if _, has := cfg.rpcConns[connID]; !has && !strings.HasPrefix(connID, utils.MetaInternal) {
|
||||
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.DNSAgent, connID)
|
||||
}
|
||||
}
|
||||
for _, connID := range cfg.dnsAgentCfg.ThresholdSConns {
|
||||
if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.sessionSCfg.Enabled {
|
||||
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.ThresholdS, utils.DNSAgent)
|
||||
}
|
||||
if _, has := cfg.rpcConns[connID]; !has && !strings.HasPrefix(connID, utils.MetaInternal) {
|
||||
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.DNSAgent, connID)
|
||||
}
|
||||
}
|
||||
for _, req := range cfg.dnsAgentCfg.RequestProcessors {
|
||||
for _, field := range req.RequestFields {
|
||||
if field.Type != utils.MetaNone && field.Path == utils.EmptyString {
|
||||
|
||||
@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package config
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -32,6 +34,8 @@ type DNSAgentCfg struct {
|
||||
Enabled bool
|
||||
Listeners []DnsListener
|
||||
SessionSConns []string
|
||||
StatSConns []string
|
||||
ThresholdSConns []string
|
||||
Timezone string
|
||||
RequestProcessors []*RequestProcessor
|
||||
}
|
||||
@@ -60,9 +64,9 @@ func (da *DNSAgentCfg) loadFromJSONCfg(jsnCfg *DNSAgentJsonCfg, sep string) (err
|
||||
if jsnCfg.Timezone != nil {
|
||||
da.Timezone = *jsnCfg.Timezone
|
||||
}
|
||||
if jsnCfg.Sessions_conns != nil {
|
||||
da.SessionSConns = make([]string, len(*jsnCfg.Sessions_conns))
|
||||
for idx, connID := range *jsnCfg.Sessions_conns {
|
||||
if jsnCfg.SessionSConns != nil {
|
||||
da.SessionSConns = make([]string, len(*jsnCfg.SessionSConns))
|
||||
for idx, connID := range *jsnCfg.SessionSConns {
|
||||
// if we have the connection internal we change the name so we can have internal rpc for each subsystem
|
||||
da.SessionSConns[idx] = connID
|
||||
if connID == utils.MetaInternal {
|
||||
@@ -70,8 +74,14 @@ func (da *DNSAgentCfg) loadFromJSONCfg(jsnCfg *DNSAgentJsonCfg, sep string) (err
|
||||
}
|
||||
}
|
||||
}
|
||||
if jsnCfg.Request_processors != nil {
|
||||
for _, reqProcJsn := range *jsnCfg.Request_processors {
|
||||
if jsnCfg.StatSConns != nil {
|
||||
da.StatSConns = tagInternalConns(*jsnCfg.StatSConns, utils.MetaStats)
|
||||
}
|
||||
if jsnCfg.ThresholdSConns != nil {
|
||||
da.ThresholdSConns = tagInternalConns(*jsnCfg.ThresholdSConns, utils.MetaThresholds)
|
||||
}
|
||||
if jsnCfg.RequestProcessors != nil {
|
||||
for _, reqProcJsn := range *jsnCfg.RequestProcessors {
|
||||
rp := new(RequestProcessor)
|
||||
var haveID bool
|
||||
for _, rpSet := range da.RequestProcessors {
|
||||
@@ -102,24 +112,23 @@ func (lstn *DnsListener) AsMapInterface(separator string) map[string]any {
|
||||
}
|
||||
|
||||
// AsMapInterface returns the config as a map[string]any
|
||||
func (da *DNSAgentCfg) AsMapInterface(separator string) (initialMP map[string]any) {
|
||||
initialMP = map[string]any{
|
||||
utils.EnabledCfg: da.Enabled,
|
||||
utils.TimezoneCfg: da.Timezone,
|
||||
}
|
||||
|
||||
func (da *DNSAgentCfg) AsMapInterface(sep string) map[string]any {
|
||||
listeners := make([]map[string]any, len(da.Listeners))
|
||||
for i, item := range da.Listeners {
|
||||
listeners[i] = item.AsMapInterface(separator)
|
||||
listeners[i] = item.AsMapInterface(sep)
|
||||
}
|
||||
initialMP[utils.ListenersCfg] = listeners
|
||||
|
||||
requestProcessors := make([]map[string]any, len(da.RequestProcessors))
|
||||
for i, item := range da.RequestProcessors {
|
||||
requestProcessors[i] = item.AsMapInterface(separator)
|
||||
requestProcessors[i] = item.AsMapInterface(sep)
|
||||
}
|
||||
m := map[string]any{
|
||||
utils.EnabledCfg: da.Enabled,
|
||||
utils.ListenersCfg: listeners,
|
||||
utils.TimezoneCfg: da.Timezone,
|
||||
utils.StatSConnsCfg: stripInternalConns(da.StatSConns),
|
||||
utils.ThresholdSConnsCfg: stripInternalConns(da.ThresholdSConns),
|
||||
utils.RequestProcessorsCfg: requestProcessors,
|
||||
}
|
||||
initialMP[utils.RequestProcessorsCfg] = requestProcessors
|
||||
|
||||
if da.SessionSConns != nil {
|
||||
sessionSConns := make([]string, len(da.SessionSConns))
|
||||
for i, item := range da.SessionSConns {
|
||||
@@ -128,35 +137,28 @@ func (da *DNSAgentCfg) AsMapInterface(separator string) (initialMP map[string]an
|
||||
sessionSConns[i] = utils.MetaInternal
|
||||
}
|
||||
}
|
||||
initialMP[utils.SessionSConnsCfg] = sessionSConns
|
||||
m[utils.SessionSConnsCfg] = sessionSConns
|
||||
}
|
||||
return
|
||||
return m
|
||||
}
|
||||
|
||||
// Clone returns a deep copy of DNSAgentCfg
|
||||
func (da DNSAgentCfg) Clone() (cln *DNSAgentCfg) {
|
||||
cln = &DNSAgentCfg{
|
||||
Enabled: da.Enabled,
|
||||
Listeners: da.Listeners,
|
||||
Timezone: da.Timezone,
|
||||
}
|
||||
|
||||
if da.Listeners != nil {
|
||||
cln.Listeners = make([]DnsListener, len(da.Listeners))
|
||||
copy(cln.Listeners, da.Listeners)
|
||||
}
|
||||
|
||||
if da.SessionSConns != nil {
|
||||
cln.SessionSConns = make([]string, len(da.SessionSConns))
|
||||
copy(cln.SessionSConns, da.SessionSConns)
|
||||
func (da DNSAgentCfg) Clone() *DNSAgentCfg {
|
||||
clone := &DNSAgentCfg{
|
||||
Enabled: da.Enabled,
|
||||
Listeners: slices.Clone(da.Listeners),
|
||||
Timezone: da.Timezone,
|
||||
SessionSConns: slices.Clone(da.SessionSConns),
|
||||
StatSConns: slices.Clone(da.StatSConns),
|
||||
ThresholdSConns: slices.Clone(da.ThresholdSConns),
|
||||
}
|
||||
if da.RequestProcessors != nil {
|
||||
cln.RequestProcessors = make([]*RequestProcessor, len(da.RequestProcessors))
|
||||
clone.RequestProcessors = make([]*RequestProcessor, len(da.RequestProcessors))
|
||||
for i, req := range da.RequestProcessors {
|
||||
cln.RequestProcessors[i] = req.Clone()
|
||||
clone.RequestProcessors[i] = req.Clone()
|
||||
}
|
||||
}
|
||||
return
|
||||
return clone
|
||||
}
|
||||
|
||||
// RequestProcessor is the request processor configuration
|
||||
@@ -33,9 +33,11 @@ func TestDNSAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
Network: utils.StringPointer("udp"),
|
||||
},
|
||||
},
|
||||
Sessions_conns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
Timezone: utils.StringPointer("UTC"),
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
SessionSConns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
StatSConns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
ThresholdSConns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
Timezone: utils.StringPointer("UTC"),
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
ID: utils.StringPointer("OutboundAUTHDryRun"),
|
||||
Filters: &[]string{"*string:~*req.request_type:OutboundAUTH", "*string:~*req.Msisdn:497700056231"},
|
||||
@@ -57,8 +59,10 @@ func TestDNSAgentCfgloadFromJsonCfg(t *testing.T) {
|
||||
Network: "udp",
|
||||
},
|
||||
},
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
Timezone: "UTC",
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
StatSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats), "*conn1"},
|
||||
ThresholdSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds), "*conn1"},
|
||||
Timezone: "UTC",
|
||||
RequestProcessors: []*RequestProcessor{
|
||||
{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
@@ -116,7 +120,7 @@ func TestRequestProcessorloadFromJsonCfg(t *testing.T) {
|
||||
|
||||
func TestRequestProcessorDNSAgentloadFromJsonCfg(t *testing.T) {
|
||||
cfgJSON := &DNSAgentJsonCfg{
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
Tenant: utils.StringPointer("a{*"),
|
||||
},
|
||||
@@ -140,7 +144,7 @@ func TestRequestProcessorDNSAgentloadFromJsonCfg1(t *testing.T) {
|
||||
}
|
||||
}`
|
||||
cfgJSON := &DNSAgentJsonCfg{
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
ID: utils.StringPointer("random"),
|
||||
},
|
||||
@@ -155,7 +159,7 @@ func TestRequestProcessorDNSAgentloadFromJsonCfg1(t *testing.T) {
|
||||
|
||||
func TestRequestProcessorReplyFieldsloadFromJsonCfg(t *testing.T) {
|
||||
cfgJSON := &DNSAgentJsonCfg{
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
Reply_fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
@@ -175,7 +179,7 @@ func TestRequestProcessorReplyFieldsloadFromJsonCfg(t *testing.T) {
|
||||
|
||||
func TestRequestProcessorRequestFieldsloadFromJsonCfg(t *testing.T) {
|
||||
cfgJSON := &DNSAgentJsonCfg{
|
||||
Request_processors: &[]*ReqProcessorJsnCfg{
|
||||
RequestProcessors: &[]*ReqProcessorJsnCfg{
|
||||
{
|
||||
Request_fields: &[]*FcTemplateJsonCfg{
|
||||
{
|
||||
@@ -216,6 +220,8 @@ func TestDNSAgentCfgAsMapInterface(t *testing.T) {
|
||||
},
|
||||
},
|
||||
utils.SessionSConnsCfg: []string{"*internal"},
|
||||
utils.StatSConnsCfg: []string{},
|
||||
utils.ThresholdSConnsCfg: []string{},
|
||||
utils.TimezoneCfg: "",
|
||||
utils.RequestProcessorsCfg: []map[string]any{},
|
||||
}
|
||||
@@ -237,6 +243,8 @@ func TestDNSAgentCfgAsMapInterface1(t *testing.T) {
|
||||
}
|
||||
],
|
||||
"sessions_conns": ["*internal:*sessions", "*conn1"],
|
||||
"stats_conns": ["*internal:*stats", "*conn1"],
|
||||
"thresholds_conns": ["*internal:*thresholds", "*conn1"],
|
||||
"timezone": "UTC",
|
||||
"request_processors": [
|
||||
{
|
||||
@@ -270,8 +278,10 @@ func TestDNSAgentCfgAsMapInterface1(t *testing.T) {
|
||||
utils.NetworkCfg: "udp",
|
||||
},
|
||||
},
|
||||
utils.SessionSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.TimezoneCfg: "UTC",
|
||||
utils.SessionSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.StatSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.ThresholdSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.TimezoneCfg: "UTC",
|
||||
utils.RequestProcessorsCfg: []map[string]any{
|
||||
{
|
||||
utils.IDCfg: "OutboundAUTHDryRun",
|
||||
@@ -330,8 +340,10 @@ func TestDNSAgentCfgClone(t *testing.T) {
|
||||
Network: "udp",
|
||||
},
|
||||
},
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
Timezone: "UTC",
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
StatSConns: []string{},
|
||||
ThresholdSConns: []string{},
|
||||
Timezone: "UTC",
|
||||
RequestProcessors: []*RequestProcessor{
|
||||
{
|
||||
ID: "OutboundAUTHDryRun",
|
||||
@@ -610,11 +610,13 @@ type DnsListenerJsnCfg struct {
|
||||
|
||||
// DNSAgentJsonCfg
|
||||
type DNSAgentJsonCfg struct {
|
||||
Enabled *bool
|
||||
Listeners *[]*DnsListenerJsnCfg
|
||||
Sessions_conns *[]string
|
||||
Timezone *string
|
||||
Request_processors *[]*ReqProcessorJsnCfg
|
||||
Enabled *bool `json:"enabled"`
|
||||
Listeners *[]*DnsListenerJsnCfg `json:"listeners"`
|
||||
SessionSConns *[]string `json:"sessions_conns"`
|
||||
StatSConns *[]string `json:"stats_conns"`
|
||||
ThresholdSConns *[]string `json:"thresholds_conns"`
|
||||
Timezone *string `json:"timezone"`
|
||||
RequestProcessors *[]*ReqProcessorJsnCfg `json:"request_processors"`
|
||||
}
|
||||
|
||||
type ReqProcessorJsnCfg struct {
|
||||
|
||||
Reference in New Issue
Block a user