Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tracking api usage #81

Open
FoxxMD opened this issue Mar 14, 2022 · 0 comments
Open

Implement tracking api usage #81

FoxxMD opened this issue Mar 14, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@FoxxMD
Copy link
Owner

FoxxMD commented Mar 14, 2022

Since configurations are arbitrary and api usage is dependent on how the config is built usage can be highly variable. Currently CM can only keep track of total api usage per bot by looking at api quota response from snoowrap -- could also count debug calls from snoowrap for more time-awareness but granularity would still be per bot.

It would be greatly advantageous to be able to break down api usage based on check/rule/filter/etc... for each configuration in each subreddit. This would allow insight into two things:

  • generally, CM api usage for individual components (to find optimizations and bugs where usage can be reduced by re-use/caching)
  • to help moderators gain insight into how they can better optimize their configs

To this end the goal would be to "tag" api calls from snoowrap:

  • on oauthRequest invocation directly by extending/overriding the function on the client OR
  • providing an enhanced debug log function to snoowrap that can automatically retrieve a tag within context -- which we can then aggregate using a listening on winston

To implement the context the only lead I have right now is thanks to @thislooksfun from here where they introduced me to AsyncLocalStorage built into node and cls-hooked.

This might be straightforward to implement:

  • instantiate an asyncLocalStorage object that gets passed to the created snoowrap client and the Bot at creation.
  • pass the object down the execution stack to each subreddit (manager), subredditresource, rule, etc... and wrap each level with known calls to snoowrap with a new run context.
    • Pass some meta info about the type of context??
  • gather the unique info using either winston logger context or with an event emitter from snoowrap on oauthRequest
    • Should the snoowrap execution be responsible for passing meta info on the "level" or should we iterate through each event execution to find an object by id and get meta info from the object statically??
  • at the end of the event lifecycle aggregate meta info and store, if requested

Some resources for AsyncLocalStorage

@FoxxMD FoxxMD added the enhancement New feature or request label Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant