From 067b3aa38960dd12bf7807fc9faf799556f071ca Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik Date: Thu, 12 Jan 2023 13:41:06 +0100 Subject: [PATCH 1/2] scaledobject name needs to be part of the query for metrics Signed-off-by: Zbynek Roubalik --- content/docs/2.9/operate/metrics-server.md | 26 +++------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/content/docs/2.9/operate/metrics-server.md b/content/docs/2.9/operate/metrics-server.md index ccee9b4df..e9b485018 100644 --- a/content/docs/2.9/operate/metrics-server.md +++ b/content/docs/2.9/operate/metrics-server.md @@ -37,14 +37,14 @@ This will return a json with the list of metrics exposed by KEDA: You can also query for the value of a specific metric using `kubectl`: ```bash -kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/YOUR_NAMESPACE/YOUR_METRIC_NAME" +kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/YOUR_NAMESPACE/YOUR_METRIC_NAME?labelSelector=scaledobject.keda.sh%2Fname%3D{SCALED_OBJECT_NAME}" ``` At this point, you should take in consideration that KEDA metrics are namespaced, this means that you have to specify the namespace where the `ScaledObject` is placed inside. -For example, if you want to get the value of the metric named `s1-rabbitmq-queueName2` in namespace `sample-ns`, the query will be like this: +For example, if you want to get the value of the metric named `s1-rabbitmq-queueName2`, that is used by ScaledObject named `my-scaled-object` in namespace `sample-ns`, the query will be like this: ```bash -kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/sample-ns/s1-rabbitmq-queueName2" +kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/sample-ns/s1-rabbitmq-queueName2?labelSelector=scaledobject.keda.sh%2Fname%3Dmy-scaled-object" ``` And it will show a json like this: @@ -75,23 +75,3 @@ You can recover the metric names from a ScaledObject using `kubectl`: ```bash kubectl get scaledobject SCALEDOBJECT_NAME -n NAMESPACE -o jsonpath={.status.externalMetricNames} ``` - -## How to get metric when multiple ScaledObjects have the same metric name - -KEDA will try to select the proper `ScaledObject` for your metric and there should only be one. In case of having multiple `ScaledObject`s in the same namespace with the same metric name, an error like this will be thrown: - -``` -Error from server: exactly one ScaledObject should match label -``` - -In this case, you should add in the query string the `labelSelector` to match the proper `ScaledObject` (in url format). The needed selector is `scaledobject.keda.sh/name: {ScaledObjectName}`. You can achieve this as following: - -```bash - kubectl get scaledobject SCALEDOBJECT_NAME -n NAMESPACE -o jsonpath={.metadata.labels} -``` - -Once you have the selector, you have to add it to your query string as following: - -```bash -kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/sample-ns/s1-rabbitmq-queueName2?labelSelector=scaledobject.keda.sh%2Fname%3D{ScaledObjectName}" -``` \ No newline at end of file From ec1edb3a3a71877c02a1f1b4b9febe6e7b5112db Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik Date: Thu, 12 Jan 2023 13:51:46 +0100 Subject: [PATCH 2/2] add 2.10 docs Signed-off-by: Zbynek Roubalik --- content/docs/2.10/operate/metrics-server.md | 26 +++------------------ 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/content/docs/2.10/operate/metrics-server.md b/content/docs/2.10/operate/metrics-server.md index ccee9b4df..e9b485018 100644 --- a/content/docs/2.10/operate/metrics-server.md +++ b/content/docs/2.10/operate/metrics-server.md @@ -37,14 +37,14 @@ This will return a json with the list of metrics exposed by KEDA: You can also query for the value of a specific metric using `kubectl`: ```bash -kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/YOUR_NAMESPACE/YOUR_METRIC_NAME" +kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/YOUR_NAMESPACE/YOUR_METRIC_NAME?labelSelector=scaledobject.keda.sh%2Fname%3D{SCALED_OBJECT_NAME}" ``` At this point, you should take in consideration that KEDA metrics are namespaced, this means that you have to specify the namespace where the `ScaledObject` is placed inside. -For example, if you want to get the value of the metric named `s1-rabbitmq-queueName2` in namespace `sample-ns`, the query will be like this: +For example, if you want to get the value of the metric named `s1-rabbitmq-queueName2`, that is used by ScaledObject named `my-scaled-object` in namespace `sample-ns`, the query will be like this: ```bash -kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/sample-ns/s1-rabbitmq-queueName2" +kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/sample-ns/s1-rabbitmq-queueName2?labelSelector=scaledobject.keda.sh%2Fname%3Dmy-scaled-object" ``` And it will show a json like this: @@ -75,23 +75,3 @@ You can recover the metric names from a ScaledObject using `kubectl`: ```bash kubectl get scaledobject SCALEDOBJECT_NAME -n NAMESPACE -o jsonpath={.status.externalMetricNames} ``` - -## How to get metric when multiple ScaledObjects have the same metric name - -KEDA will try to select the proper `ScaledObject` for your metric and there should only be one. In case of having multiple `ScaledObject`s in the same namespace with the same metric name, an error like this will be thrown: - -``` -Error from server: exactly one ScaledObject should match label -``` - -In this case, you should add in the query string the `labelSelector` to match the proper `ScaledObject` (in url format). The needed selector is `scaledobject.keda.sh/name: {ScaledObjectName}`. You can achieve this as following: - -```bash - kubectl get scaledobject SCALEDOBJECT_NAME -n NAMESPACE -o jsonpath={.metadata.labels} -``` - -Once you have the selector, you have to add it to your query string as following: - -```bash -kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/sample-ns/s1-rabbitmq-queueName2?labelSelector=scaledobject.keda.sh%2Fname%3D{ScaledObjectName}" -``` \ No newline at end of file