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

feat: Asset agnostic rule configs #100

Merged
merged 33 commits into from
Oct 14, 2024
Merged

feat: Asset agnostic rule configs #100

merged 33 commits into from
Oct 14, 2024

Conversation

niliayu
Copy link
Collaborator

@niliayu niliayu commented Sep 19, 2024

This PR adds the ability to define rules in YAML separate from the main telemetry config, so that rules may be referenced and reused in the context of multiple assets.

A rule that's defined in a namespace can be referenced in the main telemetry config like so:

  - namespace: voltage
     name: undervoltage
     channel_references:
       - $1: *vehicle_state_channel
       - $2: *voltage_channel

With the corresponding rule defined in a separate YAML like so:

namespace: voltage
   - name: undervoltage
     description: Checks for undervoltage while accelerating
     expression: $1 == "Accelerating" && $2 < 40
     type: review

Or if the user wants to instantiate rules in python directly, the load_rule_namespaces function has been added that will allow them to provide a path to the directory containing their rule YAMLs and load them into memory:

   rule_namespaces = load_rule_namespaces(
         [
             RULE_NAMESPACES_DIR,
         ]
     )

    RuleConfig(
                 name="overvoltage",
                 namespace="voltage",
                 namespace_rules=rule_namespaces,
                 channel_references=[
                     # INFO: Can use either "channel_identifier" or "channel_config"
                     {
                         "channel_reference": "$1",
                         "channel_identifier": vehicle_state_channel.fqn(),
                     },
                     {
                         "channel_reference": "$2",
                         "channel_config": voltage_channel,
                     },
                 ],
             ),

You can see examples of this rules in dev in this run: https://dev.app.siftstack.com/share/3xBUAIQ

@niliayu niliayu marked this pull request as draft September 19, 2024 23:02
@niliayu niliayu force-pushed the ayu/rules-config-spec branch from 1e9ab35 to e20b58e Compare September 27, 2024 18:26
@niliayu
Copy link
Collaborator Author

niliayu commented Sep 27, 2024

Just rebased the branch since it was getting a bit stale.

@niliayu niliayu force-pushed the ayu/rules-config-spec branch from c527ccd to e8a0947 Compare October 3, 2024 18:05
@niliayu
Copy link
Collaborator Author

niliayu commented Oct 3, 2024

@marcsiftstack :
So one of the next things I was looking to do here was update the python ingestion example to be able to read in the same rule yaml CSVs. I made a load_rule_namespaces function that's somewhat similar to the load_named_expression_modules one used here, but I realized I put the logic to reassemble the rules from their namespaces in the yaml-specific TelemetryConfig._from_yaml. I basically set this up so that for the yaml example, the TelemetryConfig & RuleConfigs get reassembled from yaml to look exactly the same as if the rules had been defined in one flat yaml to begin with. So maybe for now that means we need to do some similar logic when creating the RuleConfigs for the example namespace rules, but I haven't had quite enough time to think about how best to make this look for now. I could definitely be missing something super simple here to make this work though!

Edit: This has now been addressed!

@niliayu niliayu force-pushed the ayu/rules-config-spec branch from 7762fb4 to ef3721b Compare October 10, 2024 18:31
@niliayu niliayu marked this pull request as ready for review October 11, 2024 22:10
@niliayu niliayu changed the title [DRAFT]: Asset agnostic rule configs feat: Asset agnostic rule configs Oct 11, 2024
@niliayu niliayu force-pushed the ayu/rules-config-spec branch from f8480d7 to 98631a5 Compare October 14, 2024 22:00
solidiquis
solidiquis previously approved these changes Oct 14, 2024
@niliayu niliayu merged commit 4a14a7d into main Oct 14, 2024
7 checks passed
@niliayu niliayu deleted the ayu/rules-config-spec branch October 14, 2024 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants