Usage Stats: Report usage for all signed plugins (#31545)
* Report usage for all the signed plugins * Remove no longer used code * Fix tests by manipulating the global state * Minor test fix
This commit is contained in:
@@ -94,7 +94,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 models.IsKnownDataSourcePlugin(dsStat.Type) {
|
||||
if uss.shouldBeReported(dsStat.Type) {
|
||||
metrics["stats.ds."+dsStat.Type+".count"] = dsStat.Count
|
||||
} else {
|
||||
dsOtherCount += dsStat.Count
|
||||
@@ -118,7 +118,7 @@ func (uss *UsageStatsService) GetUsageReport(ctx context.Context) (UsageReport,
|
||||
|
||||
alertingOtherCount := 0
|
||||
for dsType, usageCount := range alertingUsageStats.DatasourceUsage {
|
||||
if models.IsKnownDataSourcePlugin(dsType) {
|
||||
if uss.shouldBeReported(dsType) {
|
||||
addAlertingUsageStats(dsType, usageCount)
|
||||
} else {
|
||||
alertingOtherCount += usageCount
|
||||
@@ -145,7 +145,7 @@ func (uss *UsageStatsService) GetUsageReport(ctx context.Context) (UsageReport,
|
||||
|
||||
access := strings.ToLower(dsAccessStat.Access)
|
||||
|
||||
if models.IsKnownDataSourcePlugin(dsAccessStat.Type) {
|
||||
if uss.shouldBeReported(dsAccessStat.Type) {
|
||||
metrics["stats.ds_access."+dsAccessStat.Type+"."+access+".count"] = dsAccessStat.Count
|
||||
} else {
|
||||
old := dsAccessOtherCount[access]
|
||||
@@ -290,6 +290,15 @@ func (uss *UsageStatsService) updateTotalStats() {
|
||||
}
|
||||
}
|
||||
|
||||
func (uss *UsageStatsService) shouldBeReported(dsType string) bool {
|
||||
ds, ok := plugins.DataSources[dsType]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return ds.Signature.IsValid() || ds.Signature.IsInternal()
|
||||
}
|
||||
|
||||
func getEdition() string {
|
||||
edition := "oss"
|
||||
if setting.IsEnterprise {
|
||||
|
||||
@@ -39,6 +39,8 @@ func Test_InterfaceContractValidity(t *testing.T) {
|
||||
|
||||
func TestMetrics(t *testing.T) {
|
||||
t.Run("When sending usage stats", func(t *testing.T) {
|
||||
setupSomeDataSourcePlugins(t)
|
||||
|
||||
uss := &UsageStatsService{
|
||||
Bus: bus.New(),
|
||||
SQLStore: sqlstore.InitTestDB(t),
|
||||
@@ -526,3 +528,41 @@ func (aum *alertingUsageMock) QueryUsageStats() (*alerting.UsageStats, error) {
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func setupSomeDataSourcePlugins(t *testing.T) {
|
||||
originalDataSources := plugins.DataSources
|
||||
t.Cleanup(func() { plugins.DataSources = originalDataSources })
|
||||
|
||||
plugins.DataSources = make(map[string]*plugins.DataSourcePlugin)
|
||||
|
||||
plugins.DataSources[models.DS_ES] = &plugins.DataSourcePlugin{
|
||||
FrontendPluginBase: plugins.FrontendPluginBase{
|
||||
PluginBase: plugins.PluginBase{
|
||||
Signature: "internal",
|
||||
},
|
||||
},
|
||||
}
|
||||
plugins.DataSources[models.DS_PROMETHEUS] = &plugins.DataSourcePlugin{
|
||||
FrontendPluginBase: plugins.FrontendPluginBase{
|
||||
PluginBase: plugins.PluginBase{
|
||||
Signature: "internal",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
plugins.DataSources[models.DS_GRAPHITE] = &plugins.DataSourcePlugin{
|
||||
FrontendPluginBase: plugins.FrontendPluginBase{
|
||||
PluginBase: plugins.PluginBase{
|
||||
Signature: "internal",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
plugins.DataSources[models.DS_MYSQL] = &plugins.DataSourcePlugin{
|
||||
FrontendPluginBase: plugins.FrontendPluginBase{
|
||||
PluginBase: plugins.PluginBase{
|
||||
Signature: "internal",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user