cloudfoundry / app-autoscaler-release

Automated scaling for apps running on Cloud Foundry
Apache License 2.0
27 stars 52 forks source link

Custom metric creation is not working #531

Closed mmavrudiev closed 2 years ago

mmavrudiev commented 2 years ago

Hi all,

I have tried to create a custom-metric using the below procedure but I can't see any value in the database to be populated, can you advise what could be the issue?

Autoscaler version v5.0.3

1. Create a policy: ❯ cat custom_metric.json { "instance_min_count":1, "instance_max_count":4, "scaling_rules":[ { "metric_type":"testmetric", "breach_duration_secs":60, "threshold":100, "operator":">=", "cool_down_secs":120, "adjustment":"+1" } ] }

2. Bind the autoscaler service to an app with the metric policy cf bind-service cf-nodejs autoscaler-test -c custom_metric.json

Can see that some records are already created in the db: autoscaler=> select * from app_metric where metric_type='testmetric_2'; app_id | metric_type | unit | timestamp | value --------------------------------------+--------------+------+---------------------+------- a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647001806553860452 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647001846542041787 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647001886538669255 | (3 rows)

3. Trying to push some metric curl -u username:password "https://autoscalermetrics.system.domain/v1/apps/a5632a69-e90f-48bd-ba07-45eb3d5a8786/metrics" -X POST -d @metric.json -H "Content-Type: application/json"

metric.json: ❯ cat metric.json { "instance_index": 0, "metrics": [ { "name": "testmetric_2", "value": 333, "unit": "jobs" } ] }

getting

If I change the user/pass I am getting Unauthorized so seems the above one is correct. The instance index I have verified from the app container, env var.. The app guid is taken directly from the cf..

But in the database there are no values at all: autoscaler=> select * from app_metric where metric_type='testmetric_2'; app_id | metric_type | unit | timestamp | value --------------------------------------+--------------+------+---------------------+------- a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647001806553860452 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647001846542041787 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647001886538669255 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647001926536958248 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647001966536982463 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647002006536657510 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647002046540756381 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647002086536247502 | a5632a69-e90f-48bd-ba07-45eb3d5a8786 | testmetric_2 | | 1647002126536876872 | (9 rows)

autoscaler=>

Those records above seems are creating due to some get function, so actually automatially it is trying to get the values from the app? but I want to PUT/POST them.

While debugging I was the following errors in asapi node - loggregator_agent logs: 2022/03/11 13:17:44.042103 failed to connect: unable to lookup a log consumer 2022/03/11 13:17:44.042158 failed to connect: unable to lookup a log consumer

But not sure if that is related to the metrics?

All built-in metrics like cpu, memory in use and etc., are properly displayed, the scaling is properly working based on them.

On the asmetrics node I can't see any errors in the logs...

I am attaching the running manifest of app-autoscaler that we are using in CF as a bosh deployment.

`addons:

Any clue will be much appreciated.

Thanks a lot,

silvestre commented 2 years ago

Hi @mmavrudiev ,

as discussed on slack, you should investigate

While debugging I was the following errors in asapi node - loggregator_agent logs: 2022/03/11 13:17:44.042103 failed to connect: unable to lookup a log consumer 2022/03/11 13:17:44.042158 failed to connect: unable to lookup a log consumer

The loggregator_agent is used to inject the custom metrics into the loggerator, and is a reused component documented at https://github.com/cloudfoundry/loggregator-agent-release/blob/main/docs/loggregator-agent.md.

silvestre commented 2 years ago

This issue seems to have been resolved - please reopen if there's still something to do.