Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

FR: Constant features #183

Open
zepatrik opened this issue Nov 29, 2022 · 2 comments
Open

FR: Constant features #183

zepatrik opened this issue Nov 29, 2022 · 2 comments
Labels
fr Feature request

Comments

@zepatrik
Copy link

What are you trying to do?

We have a feature that is not usage based. Our upper rate-limiting depends on the plan, so it is kind of a constant feature value I have to get when applying rate-limits.

How should we solve this?

Allow defining constant features in the pricing.json.

What is the impact of not solving this?

One has to manually manage those features, which kind of defeats the purpose of this project.

Anything else?

No response

@zepatrik zepatrik added the fr Feature request label Nov 29, 2022
@isaacs
Copy link
Contributor

isaacs commented Nov 29, 2022

Can you elaborate a little bit on this? (Happy to do a call or something if that's easier for you.)

If I understand you correctly, it sounds like something where you have some set "value" that's determined by the plan. For example, customers on the "pro" plan can make 100 requests per second, but those on the basic plan can make 25 requests per second. But you're not billing them per-request or anything, it's just a setting in a load balancer config or something.

You could express this now in pricing.json by setting a limit and then using that as the source of truth, even though you're not using tier.report() to track charges for the customer. Just look at the limit returned in tier.limit(org, feature) to decide what to set their rate limiting at.

{
  "plans": {
    "plan:pro@0": {
      "features": {
        "feature:ratelimit:requestpersecond": {
          "tiers": [{ "upto": 100 }]
        }
      }
    },
    "plan:basic@0": {
      "features": {
        "feature:ratelimit:requestpersecond": {
          "tiers": [{ "upto": 25 }]
        }
      }
    }
  }
}

Using the sdk:

import { limit } from 'tier'
limit('org:prouser', 'feature:ratelimit:requestpersecond').then(console.log)
/*
{ feature: 'feature:ratelimit:requestpersecond', used: 0, limit: 100 }
 */

I agree it feels like a tiny bit of a hack, though. It might be nice to have a more "blessed" approach.

@zepatrik
Copy link
Author

Yes exactly what you described. Thanks for the workaround, but maybe you want to consider a more native approach to this 😉
Feel free to close if applicable.

@zepatrik zepatrik mentioned this issue Dec 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fr Feature request
Projects
None yet
Development

No branches or pull requests

2 participants