Documentation
¶
Index ¶
- Variables
- func ConvertField(frame *data.Frame, fieldName string, converter data.FieldConverter) error
- func DebugFrame(frame *data.Frame, headRows int) string
- func DebugFrameHead(frame *data.Frame, n int) string
- func DebugFrameInfo(frame *data.Frame) string
- func DeriveUUID(baseUUID string, extra interface{}) (string, error)
- func GetHistoryTimeRange(currentFrom time.Time, htr HistoryTimeRange) (time.Time, time.Time)
- func GetRecalculateTimeRange(from, to time.Time, htr HistoryTimeRange) (time.Time, time.Time)
- func NewDatasource(_ context.Context, _ backend.DataSourceInstanceSettings) (instancemgmt.Instance, error)
- func ParsePeriods(durations string, intervalMs int64) ([]uint, error)
- func RenderFrameWithBaseline(df *data.Frame, refID string) *data.Frame
- func RenderFrameWithForecast(df *data.Frame, refID string, seriesName string) *data.Frame
- func RenderFrameWithOutlier(df *data.Frame) *data.Frame
- func TransformDataFrame(df *data.Frame) error
- func UniqueSlice[T comparable](s []T) []T
- type Alert4MLQueryBody
- type Alert4MLQueryJson
- type Datasource
- func (d *Datasource) CheckGrafanaHealth(config *models.PluginSettings) error
- func (d *Datasource) CheckHealth(_ context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
- func (d *Datasource) CheckPgHealth(config *models.PluginSettings) error
- func (d *Datasource) Dispose()
- func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- type DynamicsHyperParams
- type ForecastHyperParams
- type ForecastTrainingKey
- type HistoryTimeRange
- type HyperParams
- type RsodHyperParams
- type UniqueKeys
- type UniqueKeysUUID
Constants ¶
This section is empty.
Variables ¶
var ( // Alert4MLNamespace is the namespace UUID for Alert4ML plugin // Generated using uuid.NewSHA1(uuid.NameSpaceOID, []byte("alert4ml-plugin")) Alert4MLNamespace = uuid.MustParse("6ba7b810-9dad-11d1-80b4-00c04fd430c8") )
Define namespace UUID for generating deterministic UUID v5 Can use uuid.NameSpaceOID or custom namespace
Functions ¶
func ConvertField ¶
ConvertTimezField 应用 FieldConverter 对指定字段进行转换
func DebugFrameInfo ¶
func DeriveUUID ¶ added in v0.2.6
DeriveUUID creates a new deterministic UUID by combining a base UUID with additional data (e.g. training parameters). Same inputs always produce the same derived UUID, different inputs produce different UUIDs.
func GetHistoryTimeRange ¶
GetHistoryTimeRange returns the absolute [historyFrom, historyTo) window, pinned to end at the current panel's `from`.
func GetRecalculateTimeRange ¶
GetRecalculateTimeRange extends the base data-source fetch range backwards by the history duration so the downstream query returns enough history for training. The evaluation window (`to`) is unchanged.
func NewDatasource ¶
func NewDatasource(_ context.Context, _ backend.DataSourceInstanceSettings) (instancemgmt.Instance, error)
NewDatasource creates a new datasource instance.
func RenderFrameWithBaseline ¶
func RenderFrameWithForecast ¶
func TransformDataFrame ¶
func UniqueSlice ¶
func UniqueSlice[T comparable](s []T) []T
Types ¶
type Alert4MLQueryBody ¶
type Alert4MLQueryBody struct {
Queries []json.RawMessage `json:"queries"`
From time.Time `json:"from"`
To time.Time `json:"to"`
IntervalMs int64 `json:"-"` // 查询间隔,单位毫秒
}
func ParseAlert4MLQueryTargets ¶
func ParseAlert4MLQueryTargets(queries []backend.DataQuery) ([]*Alert4MLQueryBody, error)
ParseAlert4MLQueryTargets 解析查询参数
type Alert4MLQueryJson ¶
type Alert4MLQueryJson struct {
DetectType string `json:"detectType"`
SupportDetect string `json:"supportDetect"`
SeriesRefId string `json:"seriesRefId"`
HyperParams json.RawMessage `json:"hyperParams"`
Targets []json.RawMessage `json:"targets,omitempty"`
ShowAnomalyPoints bool `json:"showAnomalyPoints"`
HistoryTimeRange HistoryTimeRange `json:"historyTimeRange"`
UniqueKeys UniqueKeys `json:"uniqueKeys"`
}
func ParseQueryJson ¶
func ParseQueryJson(jsonData json.RawMessage) (*Alert4MLQueryJson, error)
ParseQuery 解析查询参数
type Datasource ¶
type Datasource struct{}
Datasource is an example datasource which can respond to data queries, reports its health and has streaming skills.
func (*Datasource) CheckGrafanaHealth ¶
func (d *Datasource) CheckGrafanaHealth(config *models.PluginSettings) error
func (*Datasource) CheckHealth ¶
func (d *Datasource) CheckHealth(_ context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
CheckHealth handles health checks sent from Grafana to the plugin. The main use case for these health checks is the test button on the datasource configuration page which allows users to verify that a datasource is working as expected.
func (*Datasource) CheckPgHealth ¶ added in v0.2.4
func (d *Datasource) CheckPgHealth(config *models.PluginSettings) error
func (*Datasource) Dispose ¶
func (d *Datasource) Dispose()
Dispose here tells plugin SDK that plugin wants to clean up resources when a new instance created. As soon as datasource settings change detected by SDK old datasource instance will be disposed and a new one will be created using NewSampleDatasource factory function.
func (*Datasource) QueryData ¶
func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
QueryData handles multiple queries and returns multiple responses. req contains the queries []DataQuery (where each query contains RefID as a unique identifier). The QueryDataResponse contains a map of RefID to the response for each query, and each response contains Frames ([]*Frame).
type DynamicsHyperParams ¶ added in v0.2.4
type DynamicsHyperParams struct {
Trend string `json:"trend,omitempty"`
PeriodDays int `json:"periodDays,omitempty"`
StdDevMultiplier float64 `json:"stdDevMultiplier,omitempty"`
}
DynamicsHyperParams 动态基线检测参数
func (*DynamicsHyperParams) GetType ¶ added in v0.2.4
func (p *DynamicsHyperParams) GetType() string
func (*DynamicsHyperParams) SetDefaults ¶ added in v0.2.4
func (p *DynamicsHyperParams) SetDefaults()
type ForecastHyperParams ¶
type ForecastHyperParams struct {
ModelName string `json:"model_name"`
Periods string `json:"periods"`
UUID string `json:"uuid"`
Budget float32 `json:"budget,omitempty"`
NumThreads int `json:"numThreads,omitempty"`
Nlags int `json:"nlags,omitempty"`
StdDevMultiplier float64 `json:"stdDevMultiplier,omitempty"`
AllowNegativeBounds bool `json:"allowNegativeBounds,omitempty"`
MaxBin uint16 `json:"maxBin,omitempty"`
IterationLimit *int `json:"iterationLimit,omitempty"`
Timeout *float32 `json:"timeout,omitempty"`
StoppingRounds *int `json:"stoppingRounds,omitempty"`
Seed *uint64 `json:"seed,omitempty"`
LogIterations *int `json:"logIterations,omitempty"`
}
func (*ForecastHyperParams) GetType ¶
func (p *ForecastHyperParams) GetType() string
func (*ForecastHyperParams) SetDefaults ¶
func (p *ForecastHyperParams) SetDefaults()
type ForecastTrainingKey ¶ added in v0.2.6
type ForecastTrainingKey struct {
Periods []uint `json:"periods"`
Budget float32 `json:"budget"`
NumThreads int `json:"num_threads"`
MaxBin uint16 `json:"max_bin"`
IterationLimit *int `json:"iteration_limit"`
Timeout *float32 `json:"timeout"`
StoppingRounds *int `json:"stopping_rounds"`
Seed *uint64 `json:"seed"`
}
ForecastTrainingKey contains only parameters that affect model training. Used to derive a deterministic UUID so that parameter changes trigger retraining.
type HistoryTimeRange ¶
type HistoryTimeRange struct {
DurationMs uint64 `json:"durationMs"`
}
HistoryTimeRange stores only the length of the history window. The history window's upper bound is always anchored at the current panel's timeRange.From (derived at query time, not stored here), so:
history.to = panel.timeRange.From history.from = panel.timeRange.From - DurationMs
A custom UnmarshalJSON handles legacy dashboards that stored `{from, to}` relative-seconds pairs.
func (*HistoryTimeRange) UnmarshalJSON ¶ added in v0.2.7
func (h *HistoryTimeRange) UnmarshalJSON(data []byte) error
UnmarshalJSON accepts three wire formats:
- modern: {"durationMs": 300000}
- legacy-rel-seconds: {"from": 300, "to": 0} -> duration = |to-from| * 1000 ms
- picker-style: {"mode": "relative", "relativeDuration": "5m"} -> ignored (duration stays 0)
type HyperParams ¶
type HyperParams interface {
GetType() string
SetDefaults() // 设置默认值的方法
}
HyperParams 是所有超参数的接口
func ParseHyperParams ¶
func ParseHyperParams(detectType string, data json.RawMessage) (HyperParams, error)
ParseHyperParams 根据检测类型解析超参数
type RsodHyperParams ¶
type RsodHyperParams struct {
Periods string `json:"periods,omitempty"`
ModelName string `json:"model_name,omitempty"`
NTrees *int `json:"nTrees,omitempty"`
SampleSize *int `json:"sampleSize,omitempty"`
MaxTreeDepth *int `json:"maxTreeDepth,omitempty"`
ExtensionLevel *int `json:"extensionLevel,omitempty"`
}
func (*RsodHyperParams) GetType ¶
func (p *RsodHyperParams) GetType() string
func (*RsodHyperParams) SetDefaults ¶
func (p *RsodHyperParams) SetDefaults()
SetDefaults 设置 RSOD 参数的默认值
type UniqueKeys ¶
type UniqueKeysUUID ¶
type UniqueKeysUUID struct {
DetectType string `json:"detectType"`
SupportDetect string `json:"supportDetect"`
UniqueKeys UniqueKeys `json:"uniqueKeys"`
SeriesName string `json:"seriesName"`
}
func (*UniqueKeysUUID) ToUUID ¶
func (uk *UniqueKeysUUID) ToUUID() (uuid.UUID, error)
ToUUID converts UniqueKeysUUID to UUID v5 Uses SHA-1 hash to ensure same input always generates same UUID
func (*UniqueKeysUUID) ToUUIDString ¶
func (uk *UniqueKeysUUID) ToUUIDString() (string, error)
ToUUIDString converts UniqueKeysUUID to UUID string