amazon-archives / k8s-cloudwatch-adapter

An implementation of Kubernetes Custom Metrics API for Amazon CloudWatch
Apache License 2.0
158 stars 98 forks source link

The math is not working #7

Closed ghost closed 5 years ago

ghost commented 5 years ago

The following configuration returns 0 while each of metric returns valid values:

kind: ExternalMetric
metadata:
  name: elb-request-count-per-instance
spec:
  name: elb-request-count-per-instance
  resource:
    resource: "deployment"
  queries:
    - id: elb_request_count_per_instance
      expression: "elb_external_request_count / elb_external_healthy_host_count"
    - id: elb_external_request_count
      metricLabels: "elb_external_request_count"
      metricStat:
        metric:
          namespace: "AWS/ELB"
          metricName: "RequestCount"
          dimensions:
            - name: LoadBalancerName
              value: "my-load-balancer"
        period: 60
        stat: Sum
        unit: Count
      returnData: false
    - id: elb_external_healthy_host_count
      metricStat:
        metric:
          namespace: "AWS/ELB"
          metricName: "HealthyHostCount"
          dimensions:
            - name: LoadBalancerName
              value: "my-load-balancer"
        period: 60
        stat: Average
        unit: Count
      returnData: false
$ kubectl get --raw  "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/elb-request-count-per-instance" | jq .
{
  "kind": "ExternalMetricValueList",
  "apiVersion": "external.metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/elb-request-count-per-instance"
  },
  "items": [
    {
      "metricName": "elb-request-count-per-instance",
      "metricLabels": null,
      "timestamp": "2019-07-29T14:32:46Z",
      "value": "0"
    }
  ]
}
chankh commented 5 years ago

Hi @RomanSytnik the default value for returnData is false, so for the first query that you have (elb_request_count_per_instance), you will need to specify returnData: true

ghost commented 5 years ago

@chankh Thanks for the suggestion. In this case, I`m receiving zero as well. Also I want to pay attention that I need to get the math "elb_external_request_count / elb_external_healthy_host_count" but not the values of any separate two metrics.

chankh commented 5 years ago

you can leave the returnData for the other queries as false and only the one you wish to receive as true

kind: ExternalMetric
metadata:
  name: elb-request-count-per-instance
spec:
  name: elb-request-count-per-instance
  resource:
    resource: "deployment"
  queries:
    - id: elb_request_count_per_instance
      expression: "elb_external_request_count / elb_external_healthy_host_count"
      returnData: true
    - id: elb_external_request_count
      metricLabels: "elb_external_request_count"
      metricStat:
        metric:
          namespace: "AWS/ELB"
          metricName: "RequestCount"
          dimensions:
            - name: LoadBalancerName
              value: "my-load-balancer"
        period: 60
        stat: Sum
        unit: Count
      returnData: false
    - id: elb_external_healthy_host_count
      metricStat:
        metric:
          namespace: "AWS/ELB"
          metricName: "HealthyHostCount"
          dimensions:
            - name: LoadBalancerName
              value: "my-load-balancer"
        period: 60
        stat: Average
        unit: Count
      returnData: false
ghost commented 5 years ago

I`ve also tried this suggestion as well. Unfortunately, the request returns 0.

{
  "kind": "ExternalMetricValueList",
  "apiVersion": "external.metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/elb-request-count-per-instance"
  },
  "items": [
    {
      "metricName": "elb-request-count-per-instance",
      "metricLabels": null,
      "timestamp": "2019-08-12T12:05:15Z",
      "value": "0"
    }
  ]
}

Could it be related to the hardcoded first value which is not always first? https://github.com/awslabs/k8s-cloudwatch-adapter/blob/v0.4.0/pkg/provider/provider_external.go#L36

ghost commented 5 years ago

@chankh I`ve checked the PR https://github.com/awslabs/k8s-cloudwatch-adapter/pull/9 and as can I see it fixes this issue. When will it be merged?

chankh commented 5 years ago

@RomanSytnik PR #9 is merged, latest release is v0.6.0

chankh commented 5 years ago

@RomanSytnik does the latest release solve your issue?

ghost commented 5 years ago

@chankh yes, this issue is solved now. Thanks!