We don't advise using /v2/events for metering/billing for precisely the reason you mention, that order of events is not guaranteed. You can find more information about app usage events and service usage events which are guaranteed to be in order here: http://docs.cloudfoundry.org/running/managing-cf/usage-events.html-Dieu CF Runtime PMC Lead
toggle quoted message
Show quoted text
On Wed, Mar 9, 2016 at 10:27 AM, KRuelY <kevinyudhiswara(a)gmail.com> wrote: Hi,
I am currently working on metering runtime usage, and one issue I'm facing is that there is a possibility that usage submission comes in out of order(due to network error / other possibilities). Before the issue, the way metering runtime usage works is quiet simple. There is an app that will look at cf_events and submit usages to [cf-abacus](https://github.com/cloudfoundry-incubator/cf-abacus).
{ "metadata": { "guid": "40afe01a-b15a-4b8d-8bd1-e36a0ba2f6f5", "url": "/v2/app_usage_events/40afe01a-b15a-4b8d-8bd1-e36a0ba2f6f5", "created_at": "2016-03-02T09:48:09Z" }, "entity": { "state": "STARTED", "memory_in_mb_per_instance": 512, "instance_count": 1, "app_guid": "a2ab1b5a-94c0-4344-9a71-a1d2b11f483a", "app_name": "abacus-usage-collector", "space_guid": "d34d770d-4cd0-4bdc-8c83-8fdfa5f0b3cb", "space_name": "dev", "org_guid": "238a3e78-3fc8-4542-928a-88ee99643732", "buildpack_guid": "b77d0ef8-da1f-4c0a-99cc-193449324706", "buildpack_name": "nodejs_buildpack", "package_state": "STAGED", "parent_app_guid": null, "parent_app_name": null, "process_type": "web" } }
The way this app works is by looking at the state. If the state is STARTED, it will submit usage to abacus with the instance_memory = memory_in_mb_per_instance, running_instances = instance_count, and since = created_at. If the state is STOPPED, it will submit usage to abacus with the instance_memory = 0, running_instances = 0, and since = created_at.
In ideal situation, where there is no out of order submission this is fine. 'Simple, but Exaggerated' Example: Usage instance_memory = 1GB, running_instances = 1, since = 3/9 00:00 comes in. (STARTED) Usage instance_memory = 0GB, running_instances = 0, since = 3/10 00:00 comes in. (STOPPED) Then Abacus know that the app consumed 1GB * (3/10 - 3/9 = 24 hours) = 24 GB-hour.
But when the usage comes in out of order: Usage instance_memory = 0GB, running_instances = 0, since = 3/10 00:00 comes in. (STOPPED) Usage instance_memory = 1GB, running_instances = 1, since = 3/9 00:00 comes in. (STARTED) The formula that Abacus currently have would not works.
Abacus has another formula that would take care of this out of order submission, but it would only works if we have previous_instance_memory and previous_running_instances.
When looking for a way to have this fields, we concluded that the cleanest way would be to add previous_memory_in_mb_per_instance and previous_instance_count to the cf_event. It will make App reconfigure or cf scale makes more sense too because currently cf scale is a STOP and a START.
To sum up, the cf_event state submitted would include information:
// Starting { "state": "STARTED", "memory_in_mb_per_instance": 512, "instance_count": 1, "previous_memory_in_mb_per_instance": 0, "previous_instance_count": 0 }
// Scaling up { "state": "SCALE"?, "memory_in_mb_per_instance": 512, "instance_count": 2, "previous_memory_in_mb_per_instance": 512, "previous_instance_count": 1 }
// Scale down { "state": "SCALE"?, "memory_in_mb_per_instance": 512, "instance_count": 1, "previous_memory_in_mb_per_instance": 512, "previous_instance_count": 2 }
// Stopping { "state": "STOPPED", "memory_in_mb_per_instance": 0, "instance_count": 0, "previous_memory_in_mb_per_instance": 512, "previous_instance_count": 1 }
Any thoughts/feedbacks/guidance?
-- View this message in context: http://cf-dev.70369.x6.nabble.com/cf-dev-Adding-previous-instances-and-previous-memory-fields-to-cf-event-tp4100.html Sent from the CF Dev mailing list archive at Nabble.com.
|