mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
* introduce a new node-type ML and implement a command outlier that uses ML plugin as a source of data. * add feature flag mlExpressions that guards the feature
45 lines
976 B
Go
45 lines
976 B
Go
package ml
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
)
|
|
|
|
type FakeCommand struct {
|
|
Method string
|
|
Path string
|
|
Payload []byte
|
|
Response *backend.QueryDataResponse
|
|
Error error
|
|
Recordings []struct {
|
|
From time.Time
|
|
To time.Time
|
|
Response response.Response
|
|
Error error
|
|
}
|
|
}
|
|
|
|
var _ Command = &FakeCommand{}
|
|
|
|
func (f *FakeCommand) DatasourceUID() string {
|
|
return "fake-ml-datasource"
|
|
}
|
|
|
|
func (f *FakeCommand) Execute(from, to time.Time, executor func(method string, path string, payload []byte) (response.Response, error)) (*backend.QueryDataResponse, error) {
|
|
r, err := executor(f.Method, f.Path, f.Payload)
|
|
f.Recordings = append(f.Recordings, struct {
|
|
From time.Time
|
|
To time.Time
|
|
Response response.Response
|
|
Error error
|
|
}{From: from, To: to, Response: r, Error: err})
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return f.Response, f.Error
|
|
}
|