Chore: Refactor usage of legacy data contracts (#41218)

Refactor usage of legacy data contracts. Moves legacy data contracts 
to pkg/tsdb/legacydata package.
Refactor pkg/expr to be a proper service/dependency that can be provided 
to wire to remove some unneeded dependencies to SSE in ngalert and other places.
Refactor pkg/expr to not use the legacydata,RequestHandler and use 
backend.QueryDataHandler instead.
This commit is contained in:
Marcus Efraimsson
2021-11-10 11:52:16 +01:00
committed by GitHub
parent d6ed5d295e
commit baab021fec
54 changed files with 732 additions and 951 deletions
-3
View File
@@ -107,7 +107,6 @@ func (r *logQueryRunner) publishResults(orgID int64, channelName string) error {
// executeLiveLogQuery executes a CloudWatch Logs query with live updates over WebSocket.
// A WebSocket channel is created, which goroutines send responses over.
//nolint: staticcheck // plugins.DataResponse deprecated
func (e *cloudWatchExecutor) executeLiveLogQuery(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
responseChannelName := uuid.New().String()
responseChannel := make(chan *backend.QueryDataResponse)
@@ -133,7 +132,6 @@ func (e *cloudWatchExecutor) executeLiveLogQuery(ctx context.Context, req *backe
return response, nil
}
//nolint: staticcheck // plugins.DataResponse deprecated
func (e *cloudWatchExecutor) sendLiveQueriesToChannel(req *backend.QueryDataRequest, responseChannel chan *backend.QueryDataResponse) {
defer close(responseChannel)
@@ -211,7 +209,6 @@ func (e *cloudWatchExecutor) fetchConcurrentQueriesQuota(region string, pluginCt
return defaultConcurrentQueries
}
//nolint: staticcheck // plugins.DataResponse deprecated
func (e *cloudWatchExecutor) startLiveQuery(ctx context.Context, responseChannel chan *backend.QueryDataResponse, query backend.DataQuery, timeRange backend.TimeRange, pluginCtx backend.PluginContext) error {
model, err := simplejson.NewJson(query.JSON)
if err != nil {
+1 -5
View File
@@ -9,7 +9,6 @@ import (
func ProvideLogsService() *LogsService {
return &LogsService{
// nolint:staticcheck // plugins.DataQueryResponse deprecated
responseChannels: make(map[string]chan *backend.QueryDataResponse),
queues: make(map[string](chan bool)),
}
@@ -17,14 +16,12 @@ func ProvideLogsService() *LogsService {
// LogsService provides methods for querying CloudWatch Logs.
type LogsService struct {
channelMu sync.Mutex
// nolint:staticcheck // plugins.DataQueryResult deprecated
channelMu sync.Mutex
responseChannels map[string]chan *backend.QueryDataResponse
queues map[string](chan bool)
queueLock sync.Mutex
}
// nolint:staticcheck // plugins.DataQueryResult deprecated
func (s *LogsService) AddResponseChannel(name string, channel chan *backend.QueryDataResponse) error {
s.channelMu.Lock()
defer s.channelMu.Unlock()
@@ -37,7 +34,6 @@ func (s *LogsService) AddResponseChannel(name string, channel chan *backend.Quer
return nil
}
// nolint:staticcheck // plugins.DataQueryResult deprecated
func (s *LogsService) GetResponseChannel(name string) (chan *backend.QueryDataResponse, error) {
s.channelMu.Lock()
defer s.channelMu.Unlock()
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
"github.com/grafana/grafana/pkg/tsdb/legacydata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -48,7 +48,7 @@ func TestRequestParser(t *testing.T) {
})
})
timeRange := tsdb.NewTimeRange("now-1h", "now-2h")
timeRange := legacydata.NewDataTimeRange("now-1h", "now-2h")
from, err := timeRange.ParseFrom()
require.NoError(t, err)
to, err := timeRange.ParseTo()
@@ -138,7 +138,7 @@ func TestRequestParser(t *testing.T) {
"hide": false,
})
query.Set("period", "900")
timeRange := tsdb.NewTimeRange("now-1h", "now-2h")
timeRange := legacydata.NewDataTimeRange("now-1h", "now-2h")
from, err := timeRange.ParseFrom()
require.NoError(t, err)
to, err := timeRange.ParseTo()