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

Files under directory /etc/tedge/operations/c8y are loaded many times on c8y-mapper startup #3160

Open
rina23q opened this issue Oct 4, 2024 · 0 comments
Labels
bug Something isn't working theme:c8y Theme: Cumulocity related topics

Comments

@rina23q
Copy link
Member

rina23q commented Oct 4, 2024

Describe the bug
The supported operation files under /etc/tedge/operations/c8y should be ideally loaded only once on c8y-mapper startup. However, it is actually loaded many times. This can be explained by tracing how get_operations() functions are called.

  1. init messages
    let supported_operations_message = self.create_supported_operations(
  2. constructing CumulocityConverter
    let operations = Operations::try_new(&*config.ops_dir)?;
  3. registering a new command registration message (as many times as command registration messages received)
    let need_cloud_update = self.update_operations(ops_dir.as_std_path())?;

My comments:

(2) is actually redundant. Since already operations get created during init, they should parse to CumulocityConverter.

(3) is most problematic. CumulocityConverter::register_operation() is called by receiving a command registration message. It means, if user has 5 command registration messages, the supported operation directory will be loaded 5 times. I have a doubt if mapper has to load the directory every time when a command registration message arrives.

To Reproduce
Easy check is to use validation for custom operation handler. If the contents of a custom handler is invalid, it logs a warning message. This validation is called inside the get_operations() function.

Prepare the version of #3144.

  1. Create a invalid custom operation handler file, e.g. /etc/tedge/operations/c8y/my_CustomOperation
[exec]
topic = "c8y/devicecontrol/notifications"
on_fragment = "com_cumulocity_model_WebCamDevice"
command_name = "/usr/bin/do_something.sh ${.payload.com_cumulocity_model_WebCamDevice.parameters}"
  1. Restart c8y-mapper.
  2. See the output of the c8y-mapper. You'll find 7 times of the warning message.
WARN c8y_api::smartrest::operations: ''command' is missing in the JSON custom operation handler mapping 'my_CustomOperation'

Expected behavior
The operation files should be scanned as few times as possible.

Screenshots

Environment (please complete the following information):

  • OS [incl. version]
  • Hardware [incl. revision]
  • System-Architecture [e.g. result of "uname -a"]
  • thin-edge.io version [e.g. 1.3.0]: 1.3.1

Additional context
The directory will be loaded when file change is detected, however, this should be good.

@rina23q rina23q added bug Something isn't working theme:c8y Theme: Cumulocity related topics labels Oct 4, 2024
@Bravo555 Bravo555 removed their assignment Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working theme:c8y Theme: Cumulocity related topics
Projects
None yet
Development

No branches or pull requests

3 participants