Add quota setting for correlations (#65076)

* Add quota setting for correlations

* Fix linter
This commit is contained in:
Kristina
2023-03-21 15:27:25 -05:00
committed by GitHub
parent bf54f2672e
commit 702ec59cc4
7 changed files with 117 additions and 19 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/quota"
"github.com/grafana/grafana/pkg/util"
)
@@ -177,6 +178,31 @@ func (s CorrelationsService) getCorrelation(ctx context.Context, cmd GetCorrelat
return correlation, nil
}
func (s CorrelationsService) CountCorrelations(ctx context.Context) (*quota.Map, error) {
u := &quota.Map{}
var err error
count := int64(0)
err = s.SQLStore.WithDbSession(ctx, func(sess *db.Session) error {
q := sess.Table("correlation")
count, err = q.Count()
if err != nil {
return err
}
tag, err := quota.NewTag(QuotaTargetSrv, QuotaTarget, quota.GlobalScope)
if err != nil {
return err
}
u.Set(tag, count)
return nil
})
if err != nil {
return nil, err
}
return u, err
}
func (s CorrelationsService) getCorrelationsBySourceUID(ctx context.Context, cmd GetCorrelationsBySourceUIDQuery) ([]Correlation, error) {
correlations := make([]Correlation, 0)