Chore: Collect elasticsearch version usage stats (#31787)

* Chore: Collect elasticsearch version usage stats

* Fix lint error

* use GetDataSources from sqlstore

* Apply review suggestions

* Return error if datasource type is not specified

* Update pkg/services/sqlstore/datasource.go

* fix undefined var
This commit is contained in:
Giordano Ricci
2021-03-17 09:14:53 +00:00
committed by GitHub
parent 8e1c2d6472
commit 0c2045109e
5 changed files with 115 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package sqlstore
import (
"fmt"
"strings"
"time"
@ -18,6 +19,7 @@ import (
func init() {
bus.AddHandler("sql", GetDataSources)
bus.AddHandler("sql", GetDataSourcesByType)
bus.AddHandler("sql", GetDataSource)
bus.AddHandler("sql", AddDataSource)
bus.AddHandler("sql", DeleteDataSource)
@ -71,10 +73,21 @@ func GetDataSources(query *models.GetDataSourcesQuery) error {
} else {
sess = x.Limit(query.DataSourceLimit, 0).Where("org_id=?", query.OrgId).Asc("name")
}
query.Result = make([]*models.DataSource, 0)
return sess.Find(&query.Result)
}
// GetDataSourcesByType returns all datasources for a given type or an error if the specified type is an empty string
func GetDataSourcesByType(query *models.GetDataSourcesByTypeQuery) error {
if query.Type == "" {
return fmt.Errorf("datasource type cannot be empty")
}
query.Result = make([]*models.DataSource, 0)
return x.Where("type=?", query.Type).Asc("id").Find(&query.Result)
}
// GetDefaultDataSource is used to get the default datasource of organization
func GetDefaultDataSource(query *models.GetDefaultDataSourceQuery) error {
datasource := models.DataSource{}