You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using custom metrics for canary analysis requires the query to be inlined in the Canary spec.
To allow these queries to be parameterised, shared across namespaces and canary objects,
the Canary spec could contain a reference to a metric template that defines the metrics provider and the query.
Metric template specifications
Kubernetes custom resource:
typeMetricTemplateSpecstruct {
// Provider of this metricProviderMetricTemplateProvider`json:"provider,omitempty"`// Query template of this metricQuerystring`json:"query,omitempty"`
}
typeMetricTemplateProviderstruct {
// Type of providerTypestring`json:"type,omitempty"`// Address of this provider APIAddressstring`json:"address,omitempty"`// Secret reference containing the provider credentials// +optionalSecretRef*corev1.LocalObjectReference`json:"secretRef,omitempty"`
}
The provider type could be prometheus, influxdb, datadog, wavefront, etc.
Depending on the provider, the secret could contain basic-auth credentials, org/token, an API key or a TLS cert.
A canary analysis metric can reference a template with templateRef:
apiVersion: flagger.app/v1beta1kind: Canarymetadata:
name: podinfonamespace: devspec:
targetRef:
apiVersion: apps/v1kind: Deploymentname: podinfocanaryAnalysis:
metrics:
- name: "max database connections"templateRef:
name: max-db-con# namespace is optional# when not specified, the canary namespace will be usednamespace: flaggerthreshold: 100interval: 1m
When a metric has a template reference, Flagger will render the query and using the provider's client will execute that query.
The query runner takes the first result and converts it to type float64.
If the result is below the threshold, the metric check passes, otherwise the check fails and the rollout advancement is paused or stopped.
Metric provider specifications
To add a provider one should implement the provider interface:
typeInterfaceinterface {
// RunQuery executes the query and converts the first result to float64RunQuery(querystring) (float64, error)
// IsOnline calls the provider endpoint and returns an error if the API is unreachableIsOnline() (bool, error)
}
An implementation will be available for Prometheus and it will replace the current metrics client.
Prometheus provider example:
// PrometheusProvider executes promQL queries against the Prometheus API// using basic authentication if username and password are supplied typePrometheusProviderstruct {
timeout time.Durationurl url.URLusernamestringpasswordstring
}
// NewPrometheusProvider takes a provider spec and the credentials map,// validates the HTTP(S) address, extracts the username and password values if provided and// returns a Prometheus client ready to execute queries against the HTTP APIfuncNewPrometheusProvider(provider flaggerv1.MetricTemplateProvider, credentialsmap[string][]byte) (*PrometheusProvider, error) { }
// RunQuery executes the promQL query and returns the first result as float64func (p*PrometheusProvider) RunQuery(querystring) (float64, error) { }
// IsOnline calls the Prometheus status endpoint and returns an error if the API is unreachablefunc (p*PrometheusProvider) IsOnline() (bool, error) { }
Using custom metrics for canary analysis requires the query to be inlined in the Canary spec.
To allow these queries to be parameterised, shared across namespaces and canary objects,
the Canary spec could contain a reference to a metric template that defines the metrics provider and the query.
Metric template specifications
Kubernetes custom resource:
The provider type could be prometheus, influxdb, datadog, wavefront, etc.
Depending on the provider, the secret could contain basic-auth credentials, org/token, an API key or a TLS cert.
Prometheus example:
The following variables are available in templates:
name
(canary.metadata.name)namespace
(canary.metadata.namespace)target
(canary.spec.targetRef.name)service
(canary.spec.service.name)ingress
(canary.spec.ingresRef.name)interval
(canary.spec.canaryAnalysis.metrics[].interval)The query is rendered with go
text/template
.InfluxDB example:
Canary analysis specifications
A canary analysis metric can reference a template with
templateRef
:When a metric has a template reference, Flagger will render the query and using the provider's client will execute that query.
The query runner takes the first result and converts it to type float64.
If the result is below the threshold, the metric check passes, otherwise the check fails and the rollout advancement is paused or stopped.
Metric provider specifications
To add a provider one should implement the provider interface:
An implementation will be available for Prometheus and it will replace the current metrics client.
Prometheus provider example:
Ref: #241 #283 #284
The text was updated successfully, but these errors were encountered: