computeConnectionUsage returns the raw billable usage for one connection in integer milli-units, using the *provisioned* worker size over the whole connection lifetime. millicores and mib are the worker pod's provisioned CPU (millicores) and memory (MiB). A single ceil over the connection's wall-clo
(millicores, mib int64, dur time.Duration)
| 68 | // seconds is shared by both metrics (per the design). Returns (0, 0) when the |
| 69 | // worker size is unknown (millicores == 0) — non-remote / unknown profile, so |
| 70 | // metering is skipped. |
| 71 | func computeConnectionUsage(millicores, mib int64, dur time.Duration) (milliCPUSeconds, mibSeconds int64) { |
| 72 | if millicores <= 0 { |
| 73 | return 0, 0 |
| 74 | } |
| 75 | secs := int64(math.Ceil(dur.Seconds())) |
| 76 | if secs < 1 { |
| 77 | secs = 1 // a connection that ends within the same second still bills one second |
| 78 | } |
| 79 | return millicores * secs, mib * secs |
| 80 | } |
| 81 | |
| 82 | // Record adds one connection's usage to the in-process counter, bucketed by |
no outgoing calls