UsageStats: Expose what ds types should be reported (#35916)

This commit is contained in:
Joan López de la Franca Beltran 2021-07-07 23:12:00 +02:00 committed by GitHub
parent ec45afa6b0
commit d9e500b654
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View File

@ -28,6 +28,7 @@ func init() {
type UsageStats interface {
GetUsageReport(context.Context) (UsageReport, error)
RegisterMetricsFunc(MetricsFunc)
ShouldBeReported(string) bool
}
type MetricsFunc func() (map[string]interface{}, error)

View File

@ -109,7 +109,7 @@ func (uss *UsageStatsService) GetUsageReport(ctx context.Context) (UsageReport,
// as sending that name could be sensitive information
dsOtherCount := 0
for _, dsStat := range dsStats.Result {
if uss.shouldBeReported(dsStat.Type) {
if uss.ShouldBeReported(dsStat.Type) {
metrics["stats.ds."+dsStat.Type+".count"] = dsStat.Count
} else {
dsOtherCount += dsStat.Count
@ -152,7 +152,7 @@ func (uss *UsageStatsService) GetUsageReport(ctx context.Context) (UsageReport,
alertingOtherCount := 0
for dsType, usageCount := range alertingUsageStats.DatasourceUsage {
if uss.shouldBeReported(dsType) {
if uss.ShouldBeReported(dsType) {
addAlertingUsageStats(dsType, usageCount)
} else {
alertingOtherCount += usageCount
@ -179,7 +179,7 @@ func (uss *UsageStatsService) GetUsageReport(ctx context.Context) (UsageReport,
access := strings.ToLower(dsAccessStat.Access)
if uss.shouldBeReported(dsAccessStat.Type) {
if uss.ShouldBeReported(dsAccessStat.Type) {
metrics["stats.ds_access."+dsAccessStat.Type+"."+access+".count"] = dsAccessStat.Count
} else {
old := dsAccessOtherCount[access]
@ -336,7 +336,7 @@ func (uss *UsageStatsService) updateTotalStats() {
}
}
func (uss *UsageStatsService) shouldBeReported(dsType string) bool {
func (uss *UsageStatsService) ShouldBeReported(dsType string) bool {
ds := uss.PluginManager.GetDataSource(dsType)
if ds == nil {
return false

View File

@ -53,6 +53,10 @@ func (usm *usageStatsMock) GetUsageReport(_ context.Context) (usagestats.UsageRe
return usagestats.UsageReport{Metrics: all}, nil
}
func (usm *usageStatsMock) ShouldBeReported(_ string) bool {
return true
}
type evaluatingPermissionsTestCase struct {
desc string
user userTestCase