mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
d373566feb
commit
01b4048026
@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -9,25 +9,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DS_GRAPHITE = "graphite"
|
||||
DS_INFLUXDB = "influxdb"
|
||||
DS_INFLUXDB_08 = "influxdb_08"
|
||||
DS_ES = "elasticsearch"
|
||||
DS_OPENTSDB = "opentsdb"
|
||||
DS_CLOUDWATCH = "cloudwatch"
|
||||
DS_KAIROSDB = "kairosdb"
|
||||
DS_PROMETHEUS = "prometheus"
|
||||
DS_POSTGRES = "postgres"
|
||||
DS_MYSQL = "mysql"
|
||||
DS_MSSQL = "mssql"
|
||||
DS_ACCESS_DIRECT = "direct"
|
||||
DS_ACCESS_PROXY = "proxy"
|
||||
// Stackdriver was renamed Google Cloud monitoring 2020-05 but we keep
|
||||
// "stackdriver" to avoid breaking changes in reporting.
|
||||
DS_CLOUD_MONITORING = "stackdriver"
|
||||
DS_AZURE_MONITOR = "grafana-azure-monitor-datasource"
|
||||
DS_LOKI = "loki"
|
||||
DS_ES_OPEN_DISTRO = "grafana-es-open-distro-datasource"
|
||||
DS_GRAPHITE = "graphite"
|
||||
DS_INFLUXDB = "influxdb"
|
||||
DS_INFLUXDB_08 = "influxdb_08"
|
||||
DS_ES = "elasticsearch"
|
||||
DS_PROMETHEUS = "prometheus"
|
||||
DS_MYSQL = "mysql"
|
||||
DS_ACCESS_DIRECT = "direct"
|
||||
DS_ACCESS_PROXY = "proxy"
|
||||
DS_ES_OPEN_DISTRO = "grafana-es-open-distro-datasource"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -89,50 +79,6 @@ func (ds *DataSource) decryptedValue(field string, fallback string) string {
|
||||
return fallback
|
||||
}
|
||||
|
||||
var knownDatasourcePlugins = map[string]bool{
|
||||
DS_ES: true,
|
||||
DS_GRAPHITE: true,
|
||||
DS_INFLUXDB: true,
|
||||
DS_INFLUXDB_08: true,
|
||||
DS_KAIROSDB: true,
|
||||
DS_CLOUDWATCH: true,
|
||||
DS_PROMETHEUS: true,
|
||||
DS_OPENTSDB: true,
|
||||
DS_POSTGRES: true,
|
||||
DS_MYSQL: true,
|
||||
DS_MSSQL: true,
|
||||
DS_CLOUD_MONITORING: true,
|
||||
DS_AZURE_MONITOR: true,
|
||||
DS_LOKI: true,
|
||||
"opennms": true,
|
||||
"abhisant-druid-datasource": true,
|
||||
"dalmatinerdb-datasource": true,
|
||||
"gnocci": true,
|
||||
"zabbix": true,
|
||||
"newrelic-app": true,
|
||||
"grafana-datadog-datasource": true,
|
||||
"grafana-simple-json": true,
|
||||
"grafana-splunk-datasource": true,
|
||||
"udoprog-heroic-datasource": true,
|
||||
"grafana-openfalcon-datasource": true,
|
||||
"opennms-datasource": true,
|
||||
"rackerlabs-blueflood-datasource": true,
|
||||
"crate-datasource": true,
|
||||
"ayoungprogrammer-finance-datasource": true,
|
||||
"monasca-datasource": true,
|
||||
"vertamedia-clickhouse-datasource": true,
|
||||
"alexanderzobnin-zabbix-datasource": true,
|
||||
"grafana-influxdb-flux-datasource": true,
|
||||
"doitintl-bigquery-datasource": true,
|
||||
"grafana-azure-data-explorer-datasource": true,
|
||||
"tempo": true,
|
||||
}
|
||||
|
||||
func IsKnownDataSourcePlugin(dsType string) bool {
|
||||
_, exists := knownDatasourcePlugins[dsType]
|
||||
return exists
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
// COMMANDS
|
||||
|
||||
|
@ -29,6 +29,14 @@ type PluginSignatureState struct {
|
||||
|
||||
type PluginSignatureStatus string
|
||||
|
||||
func (pss PluginSignatureStatus) IsValid() bool {
|
||||
return pss == pluginSignatureValid
|
||||
}
|
||||
|
||||
func (pss PluginSignatureStatus) IsInternal() bool {
|
||||
return pss == pluginSignatureInternal
|
||||
}
|
||||
|
||||
const (
|
||||
pluginSignatureInternal PluginSignatureStatus = "internal" // core plugin, no signature
|
||||
pluginSignatureValid PluginSignatureStatus = "valid" // signed and accurate MANIFEST
|
||||
|
Loading…
Reference in New Issue
Block a user