https://emqx.atlassian.net/browse/EMQX-8548 Currently, we face several issues trying to keep resource metrics reasonable. For example, when a resource is re-created and has its metrics reset, but then its durable queue resumes its previous work and leads to strange (often negative) metrics. Instead using `counters` that are shared by more than one worker to manage gauges, we introduce an ETS table whose key is not only scoped by the Resource ID as before, but also by the worker ID. This way, when a worker starts/terminates, they should set their own gauges to their values (often 0 or `replayq:count` when resuming off a queue). With this scoping and initialization procedure, we'll hopefully avoid hitting those strange metrics scenarios and have better control over the gauges. |
||
|---|---|---|
| .. | ||
| i18n | ||
| include | ||
| src | ||
| test | ||
| README.md | ||
| rebar.config | ||
emqx_resource
The emqx_resource is a behavior that manages configuration specs and runtime states
for resources like mysql or redis backends.
It is intended to be used by the emqx_bridges and all other resources that need CRUD operations to their configs, and need to initialize the states when creating.
There can be foreign references between resource instances via resource-id. So they may find each other via this Id.
The main idea of the emqx resource is to put all the general code in a common lib, including
the config operations (like config validation, config dump back to files), and the state management.
And we put all the specific codes to the callback modules.
See
test/emqx_connector_demo.erlfor a minimalemqx_resourceimplementation;test/emqx_resource_SUITE.erlfor examples ofemqx_resourceusage.