diff --git a/docs/content/en/docs/implementing/evaluatemetrics.md b/docs/content/en/docs/implementing/evaluatemetrics.md index 662862980f..6d5f9dfd23 100644 --- a/docs/content/en/docs/implementing/evaluatemetrics.md +++ b/docs/content/en/docs/implementing/evaluatemetrics.md @@ -103,6 +103,30 @@ $ kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta2/namespaces/podtato-kube } ``` +## Querying Metrics over a Timerange + +You can query metrics over a specified timeframe. +Let's suppose you set the `range.interval` field to be `3m`, +the Keptn Metrics Operator would query the metrics for the +last 3 minutes which means the +`from = currentTime - range.interval` and `to = currentTime`. + +The default value is set to be `5m` if the `range.interval` is not set. + +```yaml +apiVersion: metrics.keptn.sh/v1alpha3 +kind: KeptnMetric +metadata: + name: good-metric +spec: + provider: + name: my-provider + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 10 + range: + interval: "3m" +``` + ## Using the HorizontalPodAutoscaler Use the Kubernetes Custom Metrics API diff --git a/docs/content/en/docs/yaml-crd-ref/metric.md b/docs/content/en/docs/yaml-crd-ref/metric.md index 85af5668d1..6cefe44f7f 100644 --- a/docs/content/en/docs/yaml-crd-ref/metric.md +++ b/docs/content/en/docs/yaml-crd-ref/metric.md @@ -26,6 +26,8 @@ spec: name: "" query: "" fetchIntervalSeconds: <#-seconds> + range: + interval: "" ``` ## Fields @@ -59,6 +61,9 @@ spec: * **query** -- String in the provider-specific query language, used to obtain a metric. * **fetchIntervalSeconds** -- Number of seconds between updates of the metric. + * **range** + * **interval** -- Timeframe for which the metric would be queried. + Defaults to 5m. ## Usage @@ -96,6 +101,8 @@ spec: name: "my-provider" query: "sum(kube_pod_container_resource_limits{resource='cpu'})" fetchIntervalSeconds: 5 + range: + interval: "5m" ``` ## Files diff --git a/examples/support/metrics/metric.yaml b/examples/support/metrics/metric.yaml index 15e8bb6f0b..98e2cc1892 100644 --- a/examples/support/metrics/metric.yaml +++ b/examples/support/metrics/metric.yaml @@ -15,5 +15,7 @@ metadata: spec: provider: name: my-provider - query: 'avg(rate(container_cpu_cfs_throttled_seconds_total{container="server", namespace="podtato-metrics"}[1m]))' + query: 'avg(rate(container_cpu_cfs_throttled_seconds_total{container="server", namespace="podtato-metrics"}))' fetchIntervalSeconds: 10 + range: + interval: "1m" diff --git a/metrics-operator/config/samples/metrics_v1alpha3_keptnmetric.yaml b/metrics-operator/config/samples/metrics_v1alpha3_keptnmetric.yaml index 5717b6b735..3d5cde2784 100644 --- a/metrics-operator/config/samples/metrics_v1alpha3_keptnmetric.yaml +++ b/metrics-operator/config/samples/metrics_v1alpha3_keptnmetric.yaml @@ -13,3 +13,5 @@ spec: name: some-name query: "sum(kube_pod_container_resource_limits{resource='cpu'}) - sum(kube_node_status_capacity{resource='cpu'})" fetchIntervalSeconds: 10 + range: + interval: "5m"