backend/datasources: move datasources models into the datasources service package (#51267)
* backend/datasources: move datasources models into the datasources service pkg
This commit is contained in:
@@ -7,8 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
)
|
||||
|
||||
@@ -77,7 +78,7 @@ func (ic *intervalCalculator) CalculateSafeInterval(timerange legacydata.DataTim
|
||||
return Interval{Text: FormatDuration(rounded), Value: rounded}
|
||||
}
|
||||
|
||||
func GetIntervalFrom(dsInfo *models.DataSource, queryModel *simplejson.Json, defaultInterval time.Duration) (time.Duration, error) {
|
||||
func GetIntervalFrom(dsInfo *datasources.DataSource, queryModel *simplejson.Json, defaultInterval time.Duration) (time.Duration, error) {
|
||||
interval := queryModel.Get("interval").MustString("")
|
||||
|
||||
// intervalMs field appears in the v2 plugins API and should be preferred
|
||||
|
||||
@@ -4,11 +4,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
)
|
||||
|
||||
func TestIntervalCalculator_Calculate(t *testing.T) {
|
||||
@@ -98,7 +99,7 @@ func TestGetIntervalFrom(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
testCases := []struct {
|
||||
name string
|
||||
dsInfo *models.DataSource
|
||||
dsInfo *datasources.DataSource
|
||||
queryModel string
|
||||
defaultInterval time.Duration
|
||||
expected time.Duration
|
||||
@@ -108,7 +109,7 @@ func TestGetIntervalFrom(t *testing.T) {
|
||||
{"2m", nil, `{"interval": "2m"}`, time.Second * 15, time.Minute * 2},
|
||||
{"intervalMs", nil, `{"intervalMs": 45000}`, time.Second * 15, time.Second * 45},
|
||||
{"intervalMs sub-seconds", nil, `{"intervalMs": 45200}`, time.Second * 15, time.Millisecond * 45200},
|
||||
{"dsInfo timeInterval", &models.DataSource{
|
||||
{"dsInfo timeInterval", &datasources.DataSource{
|
||||
JsonData: dsJSON,
|
||||
}, `{}`, time.Second * 15, time.Second * 60},
|
||||
{"defaultInterval when interval empty", nil, `{"interval": ""}`, time.Second * 15, time.Second * 15},
|
||||
|
||||
Reference in New Issue
Block a user