Skip to main content

Analyzing rules and flows

Deprecated

The ewx-cli analyze command family is deprecated and will be removed in release 27.02. Use the Profiler to find slow rules and flows on a live environment.

ewx-cli analyze runs a complexity analysis on the rules and flows of a namespace to find code that is overly complicated or inefficient. It works on a local cache of the namespace, so the analysis runs on a snapshot and the configurations are fetched once. Every analyze command takes --namespace <project/namespace>.

Build the cache​

ewx-cli analyze update --namespace demo/enrx_org_001

The cache lives under ~/.cache/ewx-cli/analyze/<project>/<namespace> and is refreshed when older than a week. --no-cache forces a refresh; --no-cache 3 refreshes when older than three days. analyze info describes the cache, analyze list lists all cached namespaces, analyze stats writes an Excel overview of all flows and rules, and analyze diff compares two namespace caches.

Rules​

ewx-cli analyze rules extract --namespace demo/enrx_org_001 # store all rule code in the cache
ewx-cli analyze rules mccabe my_rule --namespace demo/enrx_org_001 # McCabe complexity of one rule
ewx-cli analyze rules pylint my_rule --namespace demo/enrx_org_001 # PyLint incl. Energyworx checkers
ewx-cli analyze rules find my_rule --namespace demo/enrx_org_001 # which flows use it, at which index
ewx-cli analyze rules copy my_rule --namespace demo/enrx_org_001 # local copy of the rule code

mccabe and pylint accept a rule name, all cached rules, or a local Python file. Results are printed and stored in the cache; --output_dir also writes local copies.

Energyworx PyLint checkers​

rules pylint always adds three checkers written for rules. --only_ewx runs only those, without caching the result.

CheckerMessagesWhat it catches
IdempotencyF9000 non-idempotent methodCalls such as datetime.now() whose result differs between two runs of the same flow on the same data
CostlyW9000 costly I/O method, W9001 too many costly methods (default max 3, --max-costly-method), W9002 too many logging calls (default max 30, --max-logging-calls), W9003 logging in a loopSlow pandas patterns such as apply and iterrows, and excessive logging
Rule useW9100 imported rule module, W9101 initialized rule class, W9102 called a rule class methodRules that import or call other rules, which makes them hard to maintain

Flows​

ewx-cli analyze flows list --namespace demo/enrx_org_001
ewx-cli analyze flows inspect my_flow --mccabe --namespace demo/enrx_org_001

flows inspect lists every rule a flow uses and how often. With --mccabe it adds each rule's complexity score, which points straight at the rule that makes a slow flow slow.