mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Stats StoredSQ -> SQStoredMetrics
This commit is contained in:
@@ -31,8 +31,8 @@ type SQItem struct {
|
||||
ExpiryTime *time.Time // Used to auto-expire events
|
||||
}
|
||||
|
||||
// SQStored contains values saved in DB on store
|
||||
type StoredSQ struct {
|
||||
// SQStoredMetrics contains metrics saved in DB
|
||||
type SQStoredMetrics struct {
|
||||
SqID string // StatsQueueID
|
||||
SEvents map[string]StatsEvent // Events used by SQItems
|
||||
SQItems []*SQItem // SQItems
|
||||
@@ -51,7 +51,7 @@ type StatsQueue struct {
|
||||
ActivationInterval *utils.ActivationInterval // Activation interval
|
||||
Filters []*RequestFilter
|
||||
QueueLength int
|
||||
TTL time.Duration
|
||||
TTL *time.Duration
|
||||
Metrics []string // list of metrics to build
|
||||
Store bool // store to DB
|
||||
Thresholds []string // list of thresholds to be checked after changes
|
||||
@@ -59,20 +59,20 @@ type StatsQueue struct {
|
||||
|
||||
// Init prepares a StatsQueue for operations
|
||||
// Should be executed at server start
|
||||
func (sq *StatsQueue) Init(sec *StatsEventCache, storedSQ *StoredSQ) (err error) {
|
||||
func (sq *StatsQueue) Init(sec *StatsEventCache, sqSM *SQStoredMetrics) (err error) {
|
||||
sq.sec = sec
|
||||
if storedSQ == nil {
|
||||
if sqSM == nil {
|
||||
return
|
||||
}
|
||||
for evID, ev := range storedSQ.SEvents {
|
||||
for evID, ev := range sqSM.SEvents {
|
||||
sq.sec.Cache(evID, ev, sq.ID)
|
||||
}
|
||||
sq.sqItems = storedSQ.SQItems
|
||||
sq.sqItems = sqSM.SQItems
|
||||
for metricID := range sq.sqMetrics {
|
||||
if sq.sqMetrics[metricID], err = NewStatsMetric(metricID); err != nil {
|
||||
return
|
||||
}
|
||||
if stored, has := storedSQ.SQMetrics[metricID]; !has {
|
||||
if stored, has := sqSM.SQMetrics[metricID]; !has {
|
||||
continue
|
||||
} else if err = sq.sqMetrics[metricID].loadStoredValues(stored); err != nil {
|
||||
return
|
||||
@@ -81,8 +81,8 @@ func (sq *StatsQueue) Init(sec *StatsEventCache, storedSQ *StoredSQ) (err error)
|
||||
return
|
||||
}
|
||||
|
||||
// GetStoredSQ retrieves the data used for store to DB
|
||||
func (sq *StatsQueue) GetStoredSQ() (sSQ *StoredSQ) {
|
||||
// GetSQStoredMetrics retrieves the data used for store to DB
|
||||
func (sq *StatsQueue) GetStoredMetrics() (sqSM *SQStoredMetrics) {
|
||||
sq.RLock()
|
||||
defer sq.RUnlock()
|
||||
sEvents := make(map[string]StatsEvent)
|
||||
@@ -97,13 +97,13 @@ func (sq *StatsQueue) GetStoredSQ() (sSQ *StoredSQ) {
|
||||
sEvents[sqItem.EventID] = ev
|
||||
sItems = append(sItems, sqItem)
|
||||
}
|
||||
sSQ = &StoredSQ{
|
||||
sqSM = &SQStoredMetrics{
|
||||
SEvents: sEvents,
|
||||
SQItems: sItems,
|
||||
SQMetrics: make(map[string][]byte, len(sq.sqMetrics))}
|
||||
for metricID, metric := range sq.sqMetrics {
|
||||
var err error
|
||||
if sSQ.SQMetrics[metricID], err = metric.getStoredValues(); err != nil {
|
||||
if sqSM.SQMetrics[metricID], err = metric.getStoredValues(); err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("<StatsQueue> querying for storage metricID: %s, error: %s",
|
||||
metricID, err.Error()))
|
||||
continue
|
||||
|
||||
@@ -110,8 +110,12 @@ type DataDB interface {
|
||||
GetReqFilterIndexes(dbKey string) (indexes map[string]map[string]utils.StringMap, err error)
|
||||
SetReqFilterIndexes(dbKey string, indexes map[string]map[string]utils.StringMap) (err error)
|
||||
MatchReqFilterIndex(dbKey, fieldValKey string) (itemIDs utils.StringMap, err error)
|
||||
SetStoredSQ(ssq *StoredSQ) (err error) // stores StatsQueue
|
||||
GetStoredSQ(sqID string) (ssq *StoredSQ, err error)
|
||||
//GetStatsQueue(sqID string) (sq *StatsQueue, err error)
|
||||
//SetStatsQueue(sq *StatsQueue) (err error)
|
||||
//RemStatsQueue(sqID string) (err error)
|
||||
GetSQStoredMetrics(sqID string) (sqSM *SQStoredMetrics, err error)
|
||||
SetSQStoredMetrics(sqSM *SQStoredMetrics) (err error)
|
||||
RemSQStoredMetrics(sqID string) (err error)
|
||||
// CacheDataFromDB loads data to cache, prefix represents the cache prefix, IDs should be nil if all available data should be loaded
|
||||
CacheDataFromDB(prefix string, IDs []string, mustBeCached bool) error // ToDo: Move this to dataManager
|
||||
}
|
||||
|
||||
@@ -1549,24 +1549,38 @@ func (ms *MapStorage) RemoveVersions(vrs Versions) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetStoredSQ stores the variable part of a StatsQueue
|
||||
func (ms *MapStorage) SetStoredSQ(ssq *StoredSQ) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
var result []byte
|
||||
result, err = ms.ms.Marshal(ssq)
|
||||
ms.dict[utils.StoredSQPrefix+ssq.SqID] = result
|
||||
return
|
||||
}
|
||||
|
||||
// GetStoredSQ retrieves the variable part of a StatsQueue
|
||||
func (ms *MapStorage) GetStoredSQ(sqID string) (ssq *StoredSQ, err error) {
|
||||
// GetSQStoredMetrics retrieves the stored metrics for a StatsQueue
|
||||
func (ms *MapStorage) GetSQStoredMetrics(sqID string) (sqSM *SQStoredMetrics, err error) {
|
||||
ms.mu.RLock()
|
||||
defer ms.mu.RUnlock()
|
||||
values, ok := ms.dict[utils.StoredSQPrefix+ssq.SqID]
|
||||
values, ok := ms.dict[utils.SQStoredMetricsPrefix+sqID]
|
||||
if !ok {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
err = ms.ms.Unmarshal(values, &ssq)
|
||||
err = ms.ms.Unmarshal(values, &sqSM)
|
||||
return
|
||||
}
|
||||
|
||||
// SetStoredSQ stores the metrics for a StatsQueue
|
||||
func (ms *MapStorage) SetSQStoredMetrics(sqSM *SQStoredMetrics) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
var result []byte
|
||||
result, err = ms.ms.Marshal(sqSM)
|
||||
ms.dict[utils.SQStoredMetricsPrefix+sqSM.SqID] = result
|
||||
return
|
||||
}
|
||||
|
||||
// RemSQStoredMetrics removes stored metrics for a StatsQueue
|
||||
func (ms *MapStorage) RemSQStoredMetrics(sqID string) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
delete(ms.dict, utils.SQStoredMetricsPrefix+sqID)
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
GetStatsQueue(sqID string, skipCache bool, transactionID string) (sq *StatsQueue, err error)
|
||||
SetStatsQueue(sq *StatsQueue) (err error)
|
||||
RemStatsQueue(sqID, transactionID string) (err error)
|
||||
*/
|
||||
|
||||
@@ -2009,12 +2009,17 @@ func (ms *MongoStorage) MatchReqFilterIndex(dbKey, fieldValKey string) (itemIDs
|
||||
return
|
||||
}
|
||||
|
||||
// SetStoredSQ stores the variable part of a StatsQueue
|
||||
func (ms *MongoStorage) SetStoredSQ(ssq *StoredSQ) (err error) {
|
||||
// GetSQStoredMetrics retrieves the stored metrics for a StatsQueue
|
||||
func (ms *MongoStorage) GetSQStoredMetrics(sqID string) (sqSM *SQStoredMetrics, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetStoredSQ retrieves the variable part of a StatsQueue
|
||||
func (ms *MongoStorage) GetStoredSQ(sqID string) (ssq *StoredSQ, err error) {
|
||||
// SetStoredSQ stores the metrics for a StatsQueue
|
||||
func (ms *MongoStorage) SetSQStoredMetrics(sqSM *SQStoredMetrics) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// RemSQStoredMetrics removes stored metrics for a StatsQueue
|
||||
func (ms *MongoStorage) RemSQStoredMetrics(sqID string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1567,12 +1567,17 @@ func (rs *RedisStorage) RemoveVersions(vrs Versions) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// SetStoredSQ stores the variable part of a StatsQueue
|
||||
func (rs *RedisStorage) SetStoredSQ(ssq *StoredSQ) (err error) {
|
||||
// GetSQStoredMetrics retrieves the stored metrics for a StatsQueue
|
||||
func (rs *RedisStorage) GetSQStoredMetrics(sqID string) (sqSM *SQStoredMetrics, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetStoredSQ retrieves the variable part of a StatsQueue
|
||||
func (rs *RedisStorage) GetStoredSQ(sqID string) (ssq *StoredSQ, err error) {
|
||||
// SetStoredSQ stores the metrics for a StatsQueue
|
||||
func (rs *RedisStorage) SetSQStoredMetrics(sqSM *SQStoredMetrics) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// RemSQStoredMetrics removes stored metrics for a StatsQueue
|
||||
func (rs *RedisStorage) RemSQStoredMetrics(sqID string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -223,7 +223,8 @@ const (
|
||||
LOG_ERR = "ler_"
|
||||
LOG_CDR = "cdr_"
|
||||
LOG_MEDIATED_CDR = "mcd_"
|
||||
StoredSQPrefix = "ssq_"
|
||||
SQStoredMetricsPrefix = "ssm_"
|
||||
StatsQueuePrefix = "stq_"
|
||||
LOADINST_KEY = "load_history"
|
||||
SESSION_MANAGER_SOURCE = "SMR"
|
||||
MEDIATOR_SOURCE = "MED"
|
||||
|
||||
Reference in New Issue
Block a user