ml

package
v11.1.4-modfix Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	// DatasourceUID returns UID of a data source that is used by machine learning as the source of data
	DatasourceUID() string
	// Execute creates a payload send request to the ML API by calling the function argument sendRequest, and then parses response.
	// Function sendRequest is supposed to abstract the client configuration such creating http request, adding authorization parameters, host etc.
	Execute(from, to time.Time, sendRequest func(method string, path string, payload []byte) (response.Response, error)) (*backend.QueryDataResponse, error)

	Type() string
}

Command is an interface implemented by all Machine Learning commands that can be executed against ML API.

func UnmarshalCommand

func UnmarshalCommand(query []byte, appURL string) (Command, error)

UnmarshalCommand parses a config parameters and creates a command. Requires key `type` to be specified. Based on the value of `type` field it parses a Command

type CommandConfiguration

type CommandConfiguration struct {
	Type       string              `json:"type"`
	IntervalMs *uint               `json:"intervalMs,omitempty"`
	Config     jsoniter.RawMessage `json:"config"`
}

type CommandType

type CommandType string
const (
	Outlier CommandType = "outlier"
)

type FakeCommand

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
	}
}

func (*FakeCommand) DatasourceUID

func (f *FakeCommand) DatasourceUID() string

func (*FakeCommand) Execute

func (f *FakeCommand) Execute(from, to time.Time, executor func(method string, path string, payload []byte) (response.Response, error)) (*backend.QueryDataResponse, error)

func (*FakeCommand) Type

func (f *FakeCommand) Type() string

type OutlierCommand

type OutlierCommand struct {
	// contains filtered or unexported fields
}

OutlierCommand implements Command that sends a request to outlier proxy API and converts response to backend.QueryDataResponse

func (OutlierCommand) DatasourceUID

func (c OutlierCommand) DatasourceUID() string

func (OutlierCommand) Execute

func (c OutlierCommand) Execute(from, to time.Time, sendRequest func(method string, path string, payload []byte) (response.Response, error)) (*backend.QueryDataResponse, error)

Execute copies the original configuration JSON and appends (overwrites) a field "start_end_attributes" and "grafana_url" to the root object. The value of "start_end_attributes" is JSON object that configures time range and interval. The value of "grafana_url" is app URL that should be used by ML to query the data source. After payload is generated it sends it to POST /proxy/api/v1/outlier endpoint and parses the response. The proxy API normally responds with a structured data. It recognizes status 200 and 204 as successful result. Other statuses are considered unsuccessful and result in error. Tries to extract error from the structured payload. Otherwise, mentions the full message in error

func (OutlierCommand) Type

func (c OutlierCommand) Type() string

type OutlierCommandConfiguration

type OutlierCommandConfiguration struct {
	DatasourceType string `json:"datasource_type"`
	DatasourceUID  string `json:"datasource_uid,omitempty"`

	// If Query is empty it should be contained in a datasource specific format
	// inside of QueryParms.
	Query       string         `json:"query,omitempty"`
	QueryParams map[string]any `json:"query_params,omitempty"`

	Algorithm    map[string]any `json:"algorithm"`
	ResponseType string         `json:"response_type"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL