mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
TrendSummary implementation
This commit is contained in:
@@ -122,6 +122,27 @@ func (t *Trend) Clone() (tC *Trend) {
|
||||
return
|
||||
}
|
||||
|
||||
// AsTrendSummary transforms the trend into TrendSummary
|
||||
func (t *Trend) AsTrendSummary() (ts *TrendSummary) {
|
||||
ts = &TrendSummary{
|
||||
Tenant: t.Tenant,
|
||||
ID: t.ID,
|
||||
Metrics: make(map[string]*MetricWithTrend),
|
||||
}
|
||||
if len(t.RunTimes) != 0 {
|
||||
ts.Time = t.RunTimes[len(t.RunTimes)-1]
|
||||
for mID, mWt := range t.Metrics[ts.Time] {
|
||||
ts.Metrics[mID] = &MetricWithTrend{
|
||||
ID: mWt.ID,
|
||||
Value: mWt.Value,
|
||||
TrendGrowth: mWt.TrendGrowth,
|
||||
TrendLabel: mWt.TrendLabel,
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (t *Trend) compress(ms Marshaler) (err error) {
|
||||
if config.CgrConfig().TrendSCfg().StoreUncompressedLimit > len(t.RunTimes) {
|
||||
return
|
||||
@@ -278,3 +299,11 @@ type MetricWithTrend struct {
|
||||
func (tr *Trend) TenantID() string {
|
||||
return utils.ConcatenatedKey(tr.Tenant, tr.ID)
|
||||
}
|
||||
|
||||
// TrendSummary represents the last trend computed
|
||||
type TrendSummary struct {
|
||||
Tenant string
|
||||
ID string
|
||||
Time time.Time
|
||||
Metrics map[string]*MetricWithTrend
|
||||
}
|
||||
|
||||
@@ -180,22 +180,15 @@ func (tS *TrendS) processThresholds(trnd *Trend) (err error) {
|
||||
copy(thIDs, trnd.tPrfl.ThresholdIDs)
|
||||
}
|
||||
opts[utils.OptsThresholdsProfileIDs] = thIDs
|
||||
mtrx := make(map[string]*MetricWithTrend)
|
||||
for mtID, mtWT := range trnd.Metrics[trnd.RunTimes[len(trnd.RunTimes)-1]] {
|
||||
mtrx[mtID] = &MetricWithTrend{
|
||||
ID: mtWT.ID,
|
||||
Value: mtWT.Value,
|
||||
TrendGrowth: mtWT.TrendGrowth,
|
||||
TrendLabel: mtWT.TrendLabel,
|
||||
}
|
||||
}
|
||||
ts := trnd.AsTrendSummary()
|
||||
trndEv := &utils.CGREvent{
|
||||
Tenant: trnd.Tenant,
|
||||
ID: utils.GenUUID(),
|
||||
APIOpts: opts,
|
||||
Event: map[string]any{
|
||||
utils.TrendID: trnd.ID,
|
||||
utils.Metrics: mtrx,
|
||||
utils.Time: ts.Time,
|
||||
utils.Metrics: ts.Metrics,
|
||||
},
|
||||
}
|
||||
var withErrs bool
|
||||
@@ -225,15 +218,7 @@ func (tS *TrendS) processEEs(trnd *Trend) (err error) {
|
||||
opts := map[string]any{
|
||||
utils.MetaEventType: utils.TrendUpdate,
|
||||
}
|
||||
mtrx := make(map[string]*MetricWithTrend)
|
||||
for mtID, mtWT := range trnd.Metrics[trnd.RunTimes[len(trnd.RunTimes)-1]] {
|
||||
mtrx[mtID] = &MetricWithTrend{
|
||||
ID: mtWT.ID,
|
||||
Value: mtWT.Value,
|
||||
TrendGrowth: mtWT.TrendGrowth,
|
||||
TrendLabel: mtWT.TrendLabel,
|
||||
}
|
||||
}
|
||||
ts := trnd.AsTrendSummary()
|
||||
trndEv := &CGREventWithEeIDs{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: trnd.Tenant,
|
||||
@@ -241,7 +226,8 @@ func (tS *TrendS) processEEs(trnd *Trend) (err error) {
|
||||
APIOpts: opts,
|
||||
Event: map[string]any{
|
||||
utils.TrendID: trnd.ID,
|
||||
utils.Metrics: mtrx,
|
||||
utils.Time: ts.Time,
|
||||
utils.Metrics: ts.Metrics,
|
||||
},
|
||||
},
|
||||
EeIDs: tS.cgrcfg.TrendSCfg().EEsExporterIDs,
|
||||
|
||||
Reference in New Issue
Block a user