Giter Site home page Giter Site logo

Comments (6)

mikkeloscar avatar mikkeloscar commented on May 28, 2024 1

Using something like $.measurements[:].value does work though, but I don't know if it represents the thing you want?

However this does not work with the kube-metrics-adapter because we expect a single value to be the result rather than a list. I think you need to do: $.measurements[0].value to get something that makes sense.

from kube-metrics-adapter.

balamuru avatar balamuru commented on May 28, 2024 1

You are correct. It should be $.measurements[0].value. Custom autoscaling now works
Thanks
The valid command / yaml is

cat <<EOF | kubectl apply -f -
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: springboot-custom-hpa
  namespace: default
  labels:
    application: custom-metrics-consumer
  annotations:
    # metric-config.<metricType>.<metricName>.<collectorName>/<configKey>
    metric-config.pods.load-per-min.json-path/json-key: "$.measurements[0].value"
    metric-config.pods.load-per-min.json-path/path: /actuator/metrics/system.load.average.1m
    metric-config.pods.load-per-min.json-path/port: "7070"
    metric-config.pods.load-per-min.json-path/scheme: "http"
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: springboot-webapp
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Pods
    pods:
      metricName: load-per-min
      targetAverageValue: 1
EOF

Sample output

$ kubectl get hpa --watch
NAME                    REFERENCE                      TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
springboot-custom-hpa   Deployment/springboot-webapp   189m/1    1         10        1          44h
springboot-custom-hpa   Deployment/springboot-webapp   435m/1    1         10        1          44h
springboot-custom-hpa   Deployment/springboot-webapp   1351m/1   1         10        1          44h
springboot-custom-hpa   Deployment/springboot-webapp   1351m/1   1         10        2          44h
springboot-custom-hpa   Deployment/springboot-webapp   2388m/1   1         10        2          44h
springboot-custom-hpa   Deployment/springboot-webapp   2388m/1   1         10        4          44h
springboot-custom-hpa   Deployment/springboot-webapp   2388m/1   1         10        8          44h
springboot-custom-hpa   Deployment/springboot-webapp   2644m/1   1         10        8          44h
springboot-custom-hpa   Deployment/springboot-webapp   2644m/1   1         10        10         44h
`

from kube-metrics-adapter.

mikkeloscar avatar mikkeloscar commented on May 28, 2024

Thanks for a detailed report, could you also show the logs of the kube-metrics-adapter pod. I would imagine it would log some kind of error when trying to pull the metrics.

from kube-metrics-adapter.

balamuru avatar balamuru commented on May 28, 2024

Here you go . Looks like some sort out of range error

sh-4.2$ kubectl get hpa
NAME                    REFERENCE                      TARGETS       MINPODS   MAXPODS   REPLICAS   AGE
springboot-custom-hpa   Deployment/springboot-webapp   <unknown>/1   1         10        2          40h
sh-4.2$ kubectl get po -n kube-system |grep metrics
kube-metrics-adapter-55cbb64dc9-g22pb   1/1     Running   0          3d22h
metrics-server-9cb648b76-4j6tf          1/1     Running   2          10d
sh-4.2$ kubectl logs  kube-metrics-adapter-55cbb64dc9-g22pb -n kube-system
.
.
.
time="2019-08-23T14:50:06Z" level=error msg="Failed to get metrics from pod 'default/springboot-webapp-79475bc7c-gc6pm': index [to] out of range: len: 1, to: 1" Collector=Pod
time="2019-08-23T14:50:06Z" level=error msg="Failed to get metrics from pod 'default/springboot-webapp-79475bc7c-tdvkr': index [to] out of range: len: 1, to: 1" Collector=Pod
time="2019-08-23T14:50:06Z" level=info msg="Collected 0 new metric(s)" provider=hpa
time="2019-08-23T14:50:08Z" level=info msg="Looking for HPAs" provider=hpa
time="2019-08-23T14:50:08Z" level=info msg="Found 0 new/updated HPA(s)" provider=hpa
time="2019-08-23T14:50:38Z" level=info msg="Looking for HPAs" provider=hpa
time="2019-08-23T14:50:38Z" level=info msg="Found 0 new/updated HPA(s)" provider=hpa
time="2019-08-23T14:51:06Z" level=error msg="Failed to get metrics from pod 'default/springboot-webapp-79475bc7c-gc6pm': index [to] out of range: len: 1, to: 1" Collector=Pod
time="2019-08-23T14:51:06Z" level=error msg="Failed to get metrics from pod 'default/springboot-webapp-79475bc7c-tdvkr': index [to] out of range: len: 1, to: 1" Collector=Pod
time="2019-08-23T14:51:06Z" level=info msg="Collected 0 new metric(s)" provider=hpa
time="2019-08-23T14:51:08Z" level=info msg="Looking for HPAs" provider=hpa
time="2019-08-23T14:51:08Z" level=info msg="Found 0 new/updated HPA(s)" provider=hpa

from kube-metrics-adapter.

mikkeloscar avatar mikkeloscar commented on May 28, 2024

Then the question is if this query $.measurements[:1].value is valid in https://github.com/oliveagle/jsonpath

At least it would not be so hard to test this with all the data you provided :)

from kube-metrics-adapter.

mikkeloscar avatar mikkeloscar commented on May 28, 2024

I tested it like this and it is not valid at least with the json defined:

package main

import (
	"encoding/json"
	"fmt"

	"github.com/oliveagle/jsonpath"
)

const v = `{
  "name" : "system.load.average.1m",
  "description" : "The sum of the number of runnable entities queued to available processors and the number of runnable entities running on the available processors averaged over a period of time",
  "baseUnit" : null,
  "measurements" : [ {
    "statistic" : "VALUE",
    "value" : 0.0439453125
  } ],
  "availableTags" : [ ]
}`

func main() {
	var json_data interface{}
	json.Unmarshal([]byte(v), &json_data)

	res, err := jsonpath.JsonPathLookup(json_data, "$.measurements[:1].value")
	fmt.Println(err)
	fmt.Println(res)
}

Output is:

index [to] out of range: len: 1, to: 1
<nil>

Using something like $.measurements[:].value does work though, but I don't know if it represents the thing you want?

from kube-metrics-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.