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

New proposal for MQTT Discovery Handler #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

diconico07
Copy link
Contributor

This is a new proposal for an MQTT Discovery Handler, this proposal tries to keep things as simple as possible while still solving most use cases

This is part of project-akri/akri#106

This is a new proposal for an MQTT Discovery Handler, this proposal
tries to keep things as simple as possible while still solving most use
cases

This is part of project-akri/akri#106

Signed-off-by: Nicolas Belouin <nicolas.belouin@suse.com>
@diconico07
Copy link
Contributor Author

I created a reference implementation of a Discovery Handler for this proposal, you can find it at suse-edge/akri-mqtt-discovery-handler.

@abhijith-hr
Copy link

abhijith-hr commented Sep 19, 2023

I took a quick look at all previous discussions regarding this topic and the new proposal. Based on my knowledge, as I work with sub-components of cutting and welding machines that use MQTT, the new proposal from @diconico07 is precise to discover the MQTT-supported devices/machines in the shopfloor backed by a common external MQTT broker running on a centralized location, for eg, on a factory server and also to advertise the discovered device resources to Kubernetes based consumer applications.

One thing to note is that the MQTT Discovery Handler doesn't need to run on every node of the cluster. It is only relevant for something like UDEV device discovery. Every MQTT Discovery Handler is a client of the same MQTT broker in the network. It is better to have a cluster-wide Discovery Handler for this use case.

@diconico07
Copy link
Contributor Author

One thing to note is that the MQTT Discovery Handler doesn't need to run on every node of the cluster. It is only relevant for something like UDEV device discovery. Every MQTT Discovery Handler is a client of the same MQTT broker in the network. It is better to have a cluster-wide Discovery Handler for this use case.

I do not completely agree on this, while in theory you can, you may not want to, as if you lose connection between a node or set of nodes and the MQTT broker, then having a DH per node ensures the workload will be on the working nodes.

Moreover, the current agent architecture doesn't allow to have remote/centralized discovery handlers.

@abhijith-hr
Copy link

I agree with you.

Few more tricky but possible scenarios are,

  1. Two or more devices (same machine models from a manufacturer) publishing using same topic and one of the topic payload contains the differentiator like Device/Model ID.

  2. I have machine here from a manufacturer that doesn't even differentiate two same models but different devices at topic or payload level.

    • In this scenario, the MQTT broker must have "log_dest topic" in its configuration, this way broker logs are published to clients with "$SYS/broker/log/#" topic, and in the connection logs the right device ID/connection ID must be picked as unique indentifier.

Copy link
Collaborator

@kate-goldenring kate-goldenring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great @diconico07! Thank you!


## Instance properties

The ID of the device is the full topic used by the device.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if a device publishes multiple topics? Do we create multiple instances for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the base idea here is to craft the query to only match a channel per device

timeoutSeconds:
type: int64
minimum: 0
exclusiveMinimum: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does exclusiveMinimum mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that 0 is not a valid value

type: string
timeoutSeconds:
type: int64
minimum: 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming "no timeout" is max i64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"No timeout" makes no sense to me here as it would be that a device can never disappear/goes down

Because of these properties, it is impossible to discover devices that do not publish any message.

Usually a device will publish into topics that are specific to that device instance so that it becomes possible to know the origin of the message.
For example a weather station might publish into topics like `weather/<city>/temperature` and `weather/<city>/pressure` with `<city>` the location of station.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to point out a coAP discovery handler that was worked on awhile ago as that protocol has topics and might provide some more inspiration. Proposal is coap.md in the closed pr: https://github.com/project-akri/akri/pull/346/files#diff-0c3abadcc72d01ab2b22fd1f4a2e696f0f3c350909e2d991cf7fea22a4311789

@@ -0,0 +1,83 @@
# [MQTT](https://mqtt.org/) Discovery Handler

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a section on how the Akri broker will use the information provided? If i understand MQTT well enough, doesn't the Akri broker essentially just subscribe to the same MQTT broker as the Akri DH. To me, this makes "discovery" hard to understand, potentially similar to OPC with Akri. Might be worth adding a section that talks about how this is still useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Akri broker would indeed connect to the same MQTT broker.
It might however subscribe to different topics: for the pressure+temperature example, you could do discovery on temperature (so DH subscribe to weather/+/temperature) and have the Akri broker subscribe to all topics of the discovered instance (so subscribe to weather/paris/# for example).
The Akri broker would use the information provided to identify the topics to operate on and really identify the device, as the way the topics are crafted is not standardized, we can't infer a proper device identifier from it, so we just give the whole information, and let the Akri broker know better about what is the device identifier in the topic name.

About why this is needed, see a complex machine for example, you can spawn an application only able to handle one of them at a time and thus spawn it dynamically for every such machine plugged to your MQTT broker, this way you have the same overall configuration whether you have one machine or ten machines.
Similarly, as a manufacturer I could provide a standard set of Akri Configuration to spawn the needed user facing apps depending on what exact model or set of options you as an end-user enabled (so basically if machine talks to topic /mymachine/extension/X then spawn a pod that handles this specific extension, but if not then extension not enable and the pod is not needed).

I'm not sure this is really different from how the other DH are used 🤔

@kate-goldenring
Copy link
Collaborator

@shantanoo-desai copying you here in case you have any thoughts given you've been thinking about Akri + MQTT for awhile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

3 participants