Open ezekg opened 3 years ago
Meter by entitlement? E.g. a license has many meters/consumables through entitlements.
Should be able to meter by "use count" as well as by aggregate "use time." These would both be the same, backed by a number, but just consumed and displayed differently.
Should be able to meter by "uniques", via a unique ID. For example, metering by unique client pings per-month.
POST /uses
{
"data": {
"type": "use",
"id": "some-client-id",
"attributes": {
"created": "<timestamp>",
"amount": 1
},
"relationships": {
"meter": {
"data": { "type": "meter", "id": "..." }
}
}
}
}
Add consumption strategy to a meter. Options: DECREMENT
, INCREMENT
.
Maybe we should set this up similarly to entitlements, allowing meters to be attached via the policy or the license.
class Meter
belongs_to :account
has_many :policy_meters
has_many :license_meters
attribute :consumption_strategy,
options: %w[INCREMENT DECREMENT]
end
class PolicyMeter
belongs_to :policy
belongs_to :meter
end
class LicenseMeter
belongs_to :license
belongs_to :meter
end
class LicenseUse
belongs_to :policy_meter, optional: true
belongs_to :license_meter, optional: true
belongs_to :license
validates :meter?,
message: 'meter is missing'
# Used for tracking when a use occurred
has_timestamps
def meter = policy_meter.presence || license_meter
def meter? = meter.present?
end
My big fear here is volume. This may require us to offload to a third-party, or use a different DB such as Clickhouse.
Performance is already hard enough for request/event logs.
This would allow a license to have many meters/consumables, each metering an action.