Documentation ¶
Index ¶
- Constants
- type Alert
- type AnomalyCondition
- type Client
- func (c *Client) DeleteHoliday(ctx context.Context, id string) error
- func (c *Client) DeleteJob(ctx context.Context, id string) error
- func (c *Client) DeleteJobAlert(ctx context.Context, jobID, alertID string) error
- func (c *Client) DeleteOutlierAlert(ctx context.Context, outlierID, alertID string) error
- func (c *Client) DeleteOutlierDetector(ctx context.Context, id string) error
- func (c *Client) ForecastJob(ctx context.Context, spec ForecastRequest) (backend.QueryDataResponse, error)
- func (c *Client) Holiday(ctx context.Context, id string) (Holiday, error)
- func (c *Client) Holidays(ctx context.Context) ([]Holiday, error)
- func (c *Client) Job(ctx context.Context, id string) (Job, error)
- func (c *Client) JobAlert(ctx context.Context, jobID, alertID string) (Alert, error)
- func (c *Client) JobAlerts(ctx context.Context, jobID string) ([]Alert, error)
- func (c *Client) Jobs(ctx context.Context) ([]Job, error)
- func (c *Client) LinkHolidaysToJob(ctx context.Context, jobID string, holidayIDs []string) (Job, error)
- func (c *Client) NewHoliday(ctx context.Context, holiday Holiday) (Holiday, error)
- func (c *Client) NewJob(ctx context.Context, job Job) (Job, error)
- func (c *Client) NewJobAlert(ctx context.Context, jobID string, alert Alert) (Alert, error)
- func (c *Client) NewOutlierAlert(ctx context.Context, outlierID string, alert Alert) (Alert, error)
- func (c *Client) NewOutlierDetector(ctx context.Context, outlier OutlierDetector) (OutlierDetector, error)
- func (c *Client) OutlierAlert(ctx context.Context, outlierID, alertID string) (Alert, error)
- func (c *Client) OutlierAlerts(ctx context.Context, outlierID string) ([]Alert, error)
- func (c *Client) OutlierDetector(ctx context.Context, id string) (OutlierDetector, error)
- func (c *Client) OutlierDetectors(ctx context.Context) ([]OutlierDetector, error)
- func (c *Client) UpdateHoliday(ctx context.Context, holiday Holiday) (Holiday, error)
- func (c *Client) UpdateJob(ctx context.Context, job Job) (Job, error)
- func (c *Client) UpdateJobAlert(ctx context.Context, jobID string, alert Alert) (Alert, error)
- func (c *Client) UpdateOutlierAlert(ctx context.Context, outlierID string, alert Alert) (Alert, error)
- func (c *Client) UpdateOutlierDetector(ctx context.Context, outlier OutlierDetector) (OutlierDetector, error)
- type Config
- type CustomPeriod
- type CustomPeriods
- type ForecastParams
- type ForecastRequest
- type Holiday
- type Job
- type NoDataState
- type OutlierAlgorithm
- type OutlierAlgorithmConfig
- type OutlierDetector
Constants ¶
const ( NoDataStateOK = "OK" NoDataStateAlerting = "Alerting" NoDataStateNoData = "NoData" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶ added in v0.8.0
type Alert struct { ID string `json:"id,omitempty"` // Ttile of the alert, at most 190 characters. Title string `json:"title"` // Whether we look for anomalies that are too low, too high, or both. AnomalyCondition AnomalyCondition `json:"anomalyCondition,omitempty"` // The Prometheus style for clause of an alert. For model.Duration `json:"for"` // Allows a comparison of if the average value over the window is // anomalous, for example `>0.7` would alert if more than 70% of the points // in the window are anomalous according to the anomaly condition. Threshold string `json:"threshold,omitempty"` // Specifying a window will issue a range query instead of an instant query // and average values over that range. Maximum of 12h. Window model.Duration `json:"window"` // Additional labels to add to the alert. Labels map[string]string `json:"labels"` // Annotations to include on an alert, such as severity or a description. Annotations map[string]string `json:"annotations"` // NoDataState allows alerting if no data is found in the query. Empty will // default to OK to match Prometheus behavior. NoDataState NoDataState `json:"noDataCondition"` SyncError string `json:"syncError,omitempty"` }
type AnomalyCondition ¶ added in v0.8.0
type AnomalyCondition string
AnomalyCondition describes what sort of anomaly an alert should be generated for.
It is only used for forecast alerts and is not supported for outlier alerts.
const ( // AnomalyConditionHigh alerts when the actual value of a metric is higher than the expected range. AnomalyConditionHigh AnomalyCondition = "high" // AnomalyConditionLow alerts when the actual value of a metric is lower than the expected range. AnomalyConditionLow AnomalyCondition = "low" // AnomalyConditionAny alerts when any anomalous condition is present (too high or too low). AnomalyConditionAny AnomalyCondition = "any" )
func (*AnomalyCondition) UnmarshalJSON ¶ added in v0.8.0
func (d *AnomalyCondition) UnmarshalJSON(b []byte) error
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Grafana API client.
func (*Client) DeleteHoliday ¶ added in v0.3.0
DeleteHoliday deletes an existing holiday.
func (*Client) DeleteJobAlert ¶ added in v0.8.0
DeleteJobAlert deletes an alert on a job.
func (*Client) DeleteOutlierAlert ¶ added in v0.8.0
DeleteOutlierAlert deletes an alert on an outlier detector.
func (*Client) DeleteOutlierDetector ¶ added in v0.4.0
DeleteOutlierDetector deletes an outlier detector.
func (*Client) ForecastJob ¶ added in v0.6.0
func (c *Client) ForecastJob(ctx context.Context, spec ForecastRequest) (backend.QueryDataResponse, error)
ForecastJob returns a forecast for a job definition and time range.
This is a convenience API to avoid having to create a job, wait for it to train, and then query the forecast. It is designed for exploratory usage rather than to be called regularly; if you want to regularly query a forecast, create a job and query it using the `grafanacloud-ml-metrics` datasource. Jobs specified in the ForecastRequest must have a single series, or this will return an error. This function may be slow the first time it is called, but the result will be cached for 24 hours after that.
func (*Client) JobAlert ¶ added in v0.8.0
JobAlert fetches an existing alert for the given machine learning job.
func (*Client) LinkHolidaysToJob ¶ added in v0.3.0
func (c *Client) LinkHolidaysToJob(ctx context.Context, jobID string, holidayIDs []string) (Job, error)
LinkHolidaysToJob links a job to a set of holidays. Only the ID and Holidays fields of the Job struct are used.
func (*Client) NewHoliday ¶ added in v0.3.0
NewHoliday creates a new holiday.
func (*Client) NewJobAlert ¶ added in v0.8.0
NewJobAlert creates an alert for a job.
func (*Client) NewOutlierAlert ¶ added in v0.8.0
NewOutlierAlert creates an alert for an outlier detector.
func (*Client) NewOutlierDetector ¶ added in v0.4.0
func (c *Client) NewOutlierDetector(ctx context.Context, outlier OutlierDetector) (OutlierDetector, error)
NewOutlierDetector creates an outlier detector.
func (*Client) OutlierAlert ¶ added in v0.8.0
JobAlert fetches an existing alert for the given outlier detector.
func (*Client) OutlierAlerts ¶ added in v0.8.0
OutlierAlerts fetches all alerts for a given Job.
func (*Client) OutlierDetector ¶ added in v0.4.0
OutlierDetector fetches an existing outlier detector.
func (*Client) OutlierDetectors ¶ added in v0.7.0
func (c *Client) OutlierDetectors(ctx context.Context) ([]OutlierDetector, error)
OutlierDetectors fetches all existing outlier detectors.
func (*Client) UpdateHoliday ¶ added in v0.3.0
UpdateHoliday updates an existing holiday.
func (*Client) UpdateJob ¶
UpdateJob updates a machine learning job. A new training will be scheduled as part of updating.
func (*Client) UpdateJobAlert ¶ added in v0.8.0
UpdateJobAlert updates the alert for a machine learning job.
func (*Client) UpdateOutlierAlert ¶ added in v0.8.0
func (c *Client) UpdateOutlierAlert(ctx context.Context, outlierID string, alert Alert) (Alert, error)
UpdateJobAlert updates the alert for an outlier detector.
func (*Client) UpdateOutlierDetector ¶ added in v0.4.0
func (c *Client) UpdateOutlierDetector(ctx context.Context, outlier OutlierDetector) (OutlierDetector, error)
UpdateOutlierDetector updates an outlier detector.
type Config ¶
type Config struct { // BearerToken is an optional API key. BearerToken string // BasicAuth is optional basic auth credentials. BasicAuth *url.Userinfo // Client provides an optional HTTP client, otherwise a default will be used. Client *http.Client // NumRetries contains the number of attempted retries NumRetries int }
Config contains client configuration.
type CustomPeriod ¶ added in v0.3.0
type CustomPeriod struct { // Name is the name of this period. Name string `json:"name"` // StartTime is the (inclusive) start of this period. StartTime time.Time `json:"startTime"` // EndTime is the (exclusive) end of this period. EndTime time.Time `json:"endTime"` }
CustomPeriod is a single period to be included in a holiday.
type CustomPeriods ¶ added in v0.3.0
type CustomPeriods []CustomPeriod
CustomPeriods is a slice of CustomPeriods representing all occurrences of a holiday.
type ForecastParams ¶ added in v0.6.0
type ForecastParams struct { // Start is the start time of the forecast. Start time.Time `json:"start"` // End is the end time of the forecast. End time.Time `json:"end"` // Interval is the interval of the forecast. Interval uint `json:"interval"` }
ForecastParams are parameters used in an ephemeral job prediction. Note this doesn't include `series` because users will not know the hash of the training's series in advance. Instead we enforce that ephemeral forecasts can only include a single series.
type ForecastRequest ¶ added in v0.6.0
type ForecastRequest struct { // Job is the specification of a job to run the forecast for. Job Job `json:"job"` // ForecastParams specify the start, end, and interval of the forecast. ForecastParams ForecastParams `json:"forecastParams"` }
ForecastRequest is a request to run an ephemeral forecast.
type Holiday ¶ added in v0.3.0
type Holiday struct { ID string `json:"id,omitempty"` // Name is a human readable name for the holiday. Name string `json:"name"` // Description is a human readable description for the holiday. Description string `json:"description"` // ICalURL is the URL to an iCal file containing all occurrences // of the holiday. ICalURL *string `json:"iCalUrl,omitempty"` // ICalTimeZone is the timezone to use for 'All Day' events on the iCal in ICalURL, // if present. This is required because All Day events don't come with time zone information by default, // and there is no well-adhered-to standard for timezones of entire iCal files. ICalTimeZone *string `json:"iCalTimeZone,omitempty"` // CustomPeriods are holiday periods that are specified explicitly. CustomPeriods CustomPeriods `json:"customPeriods,omitempty"` // Jobs is a slice of IDs of Jobs that are using this holiday. // Requests may specify either IDs or names. Responses will always contain IDs. Jobs []string `json:"jobs"` }
Holiday is a collection of time periods indicating where a time series will behave differently than normal.
A holiday may be specified using either an iCal (in which case both the ICalURL and ICalTimeZone fields must be provided), or using a set of custom time periods directly (in which case the CustomPeriods field must be provided).
Holidays can be linked to jobs in three ways: - at holiday creation time, if the job already exists, using the Jobs field - at job creation time, if the holiday already exists, using the Holidays field - using the LinkHolidaysToJob method on a Client.
type Job ¶
type Job struct { ID string `json:"id,omitempty"` // Name is a human readable name for the job. Name string `json:"name"` // Metric is the metric name used to query the job. Must match Prometheus // naming requirements: // https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels. Metric string `json:"metric"` Description string `json:"description"` // GrafanaURL is the full URL to the Grafana instance. For example, // https://myinstance.grafana.net/. GrafanaURL string `json:"grafanaUrl"` // DatasourceID is the numeric ID of the datasource to query when training // data. DatasourceID uint `json:"datasourceId"` // DatasourceUID is the string UID of the datasource to query when training // data. DatasourceUID string `json:"datasourceUid"` DatasourceType string `json:"datasourceType"` CustomLabels map[string]interface{} `json:"customLabels"` QueryParams map[string]interface{} `json:"queryParams"` // Interval is the data resolution in seconds. Interval uint `json:"interval"` // TrainingWindow is the lookback window to train on in seconds. TrainingWindow uint `json:"trainingWindow"` // TrainingFrequency is how often to re-train a model in seconds. TrainingFrequency uint `json:"trainingFrequency"` // Algorithm is the algorithm to use for machine learning. // https://grafana.com/docs/grafana-cloud/machine-learning/models/ contains // information on all supported algorithms. Algorithm string `json:"algorithm"` // HyperParams are the hyperparameters that can be specified. See // https://grafana.com/docs/grafana-cloud/machine-learning/models/ for the // various hyperparameters that can be changed. HyperParams map[string]interface{} `json:"hyperParams"` // Holidays is a slice of IDs or names of Holidays to be linked to this job. // Requests may specify either IDs or names. Responses will always contain IDs. Holidays []string `json:"holidays"` }
Job is a job that will be scheduled.
type NoDataState ¶ added in v0.8.0
type NoDataState string
func (*NoDataState) UnmarshalJSON ¶ added in v0.8.0
func (d *NoDataState) UnmarshalJSON(b []byte) error
type OutlierAlgorithm ¶ added in v0.4.0
type OutlierAlgorithm struct { Name string `json:"name"` Sensitivity float64 `json:"sensitivity"` // used by MAD Config *OutlierAlgorithmConfig `json:"config"` // used by DBSCAN }
type OutlierAlgorithmConfig ¶ added in v0.4.0
type OutlierAlgorithmConfig struct {
Epsilon float64 `json:"epsilon"`
}
type OutlierDetector ¶ added in v0.4.0
type OutlierDetector struct { ID string `json:"id,omitempty"` // Name is a human readable name for the outlier detector. Name string `json:"name"` // Metric is the metric name used to query the outlier detector. Must match Prometheus // naming requirements: // https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels. Metric string `json:"metric"` Description string `json:"description"` // GrafanaURL is the full URL to the Grafana instance. For example, // https://myinstance.grafana.net/. GrafanaURL string `json:"grafanaUrl"` // DatasourceID is the numeric ID of the datasource to query when training // data. DatasourceID uint `json:"datasourceId"` // DatasourceUID is the string UID of the datasource to query when training // data. DatasourceUID string `json:"datasourceUid"` DatasourceType string `json:"datasourceType"` QueryParams map[string]interface{} `json:"queryParams"` // Interval is the data resolution in seconds. Interval uint `json:"interval"` // Algorithm specifies the algorithm to use and its configuration. See // https://grafana.com/docs/grafana-cloud/machine-learning/outlier-detection/ for the // options. Algorithm OutlierAlgorithm `json:"algorithm"` }
OutlierDetector defines an outlier detector instance