feat: custom cloud mappers#4009
Conversation
|
|
||
| Custom mapper config is isolated — only the custom mapper itself uses it, unlike the global `tedge_config` schema which is referenced throughout thin-edge. This suggests custom mapper settings should live in the mapper's own `tedge.toml` (e.g. `/etc/tedge/mappers/_thingsboard/tedge.toml`), separate from the `define_tedge_config!` macro. Users edit this file directly rather than using `tedge config set/get`. | ||
|
|
||
| This avoids the complexity of fitting dynamic/unknown mapper names into the compile-time config macro, and is acceptable because the users writing custom mappers are technical enough to edit TOML files. The bridge template system would need a new `${mapper.*}` variable namespace to let bridge rule templates reference the mapper's own config (analogous to how `${config.c8y.url}` references global config today). `tedge config` support could potentially be added later if demand warrants it (though this might prove complex to implement in practice). |
There was a problem hiding this comment.
IIRC, the primary use-case for tedge config over editing these toml files by hand was to enable easier iterative updates to the config from automation scripts. So, I wouldn't rule out its utility.
96b1101 to
80e8738
Compare
f04ef32 to
90ce6c9
Compare
Robot Results
|
| use tedge_config::models::HostPort; | ||
| use tedge_config::models::MQTT_TLS_PORT; | ||
|
|
||
| /// Parsed custom mapper `tedge.toml` configuration. |
There was a problem hiding this comment.
Since the contents of this file are read from the mapper.* namespace, wondering if naming the config file mapper.toml instead of tedge.toml would make it easier for the users even us to easily do that association in our heads. I might even go one step further and change the config.* namespace into `tedge.*.
There was a problem hiding this comment.
I have now renamed tedge.toml to mapper.toml following discussion with @reubenmiller on Friday
I might even go one step further and change the config.* namespace into `tedge.*.
That's an interesting thought, I'll give it some consideration
4b2bff6 to
0e2746a
Compare
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
…en deciding if mapper.toml is empty Signed-off-by: James Rhodes <jarhodes314@gmail.com>
…t flows-only mappers
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
- Make cert CN take precedence over manually configured device.id, like we do for other clouds - Make device.id required for a custom mapper bridge connection Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
${mapper.*} variables in bridge rules were expanded against an empty table,
causing them to always produce empty strings. The fix threads the fully
resolved mapper configuration through to the rule expansion step for both
built-in (c8y) and custom mappers.
To support this, EffectiveMapperConfig gains two new methods:
- `to_template_table()`: builds the TOML table used for ${mapper.*}
expansion, overlaying schema-resolved values (cert CN, tedge.toml
fallbacks) onto the raw mapper.toml table so non-schema keys like
bridge.topic_prefix are also reachable
- `get(key) -> ConfigGetResult`: source-aware key lookup distinguishing
Value / NotSet / UnknownKey, used by `tedge mapper config get`
`resolve_effective_config` gains two new parameters: an optional overlay
table (built-in mappers pass their full serialised config so CLI commands
reflect real runtime values) and an optional JSON schema override (to
distinguish NotSet from UnknownKey for keys absent from the TOML).
A new `resolve_effective_mapper_config` function on the c8y mapper
serialises the full C8y reader as a base overlay and JSON schema, shared
between bridge rule loading and the CLI.
`tedge mapper config get` is rewritten to use the new API: it handles
built-in and custom mappers uniformly, produces precise error messages
("Key not set" vs "Unknown key", with a cert-specific hint for device.id),
and prints a `tedge config set` suggestion for built-in mapper keys. The
execute body is extracted into `run(out, err)` so tests can assert on the
actual printed output and stderr annotations.
`cloud_type` in mapper.toml is now parsed as `tedge_config::models::CloudType`
rather than a free-form string, so unknown values are a hard error at
parse time.
A new startup warning is emitted for mapper directories that contain a
`bridge/` subdirectory but no `mapper.toml` — these mappers will always
fail to start and the warning points the user at the fix.
`resolve_cloud` is deduplicated into cli::common, shared by bridge and
mapper CLI code.
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
f4ee313 to
6c75d45
Compare
reubenmiller
left a comment
There was a problem hiding this comment.
Really nice PR and brings some really exciting features
Proposed changes
In addition to the openspec proposal, this PR adds a custom cloud mapper that can be run using
tedge-mapper custom(the idea being that the user names their custom cloud implementation and then runs this like any other mapper).The mapper reads its config from a mapper config directory (e.g.
/etc/tedge/mappers/thingsboardfortedge-mapper thingsboard). You can (optionally) connect a built-in bridge by adding amapper.tomlfile:You can then add bridge config templates to the
bridge/subdirectory and flows to theflows/subdirectory.Still TODO
tedge mapper/tedge bridgesubcommands (currently they are totally unsupported)tedge connect --testsupporttedge mapper config getwill currently display the naively generated path including any..${config.}to${tedge.}in bridge templatesProposal
A proposal for how to implement a generic mapper using Openspec. In short, openspec is an IMO very useful tool for making design decisions with AI agents that can later serve as a source of truth.
The first commit is a bunch of files generated by openspec to make it actually work. It's probably worth some discussion about whether we think it's a useful tool.
The (at the time of writing, only) other commit is the actual proposal and design docs for implementing a generic mapper that can tie together the flows and configurable bridge. I would suggest reading it in the order
proposal.md,design.mdthen the twospec.mds.Types of changes
Paste Link to the issue
Checklist
just prepare-devonce)just formatas mentioned in CODING_GUIDELINESjust checkas mentioned in CODING_GUIDELINESFurther comments