-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat: mqtt wildcards support #6043
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good.
There are a few parts regarding formating, where CI is not happy. Those should be striaght forward enough to fix.
server/monitor-types/mqtt.js
Outdated
static mqttTopicRegex(subcribedTopic) { | ||
subcribedTopic = subcribedTopic.replace(/([$.|?*{}()\[\]\\])/g, '\\$1'); // Escape special regex chars except + and # | ||
subcribedTopic = subcribedTopic.replace(/\+/g, '[^/]+'); // Replace + with regex for one or more characters except slash | ||
subcribedTopic = subcribedTopic.replace(/#/g, '.*'); // Replace # with regex for zero or more characters until next slash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think \#
would also be affected under the current implementation.
Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, i don't know to much of the js regex engine but #
is not considered as special char
I can add a test to check it
server/monitor-types/mqtt.js
Outdated
const { log, UP } = require("../../src/util"); | ||
const mqtt = require("mqtt"); | ||
const jsonata = require("jsonata"); | ||
const { regex } = require("nostr-tools/nip30"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MQtt and nostr don't seem really connected.
Can you add a comment explaining this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong import, auto import from vs-code ...
assert.ok(regex.test('sensor.pomme/temperature') === true); | ||
assert.ok(regex.test('sensor.pomme/humidity') === false); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a testcase specifically for the escaping of #
, +
and the other regex characters.
server/monitor-types/mqtt.js
Outdated
*/ | ||
static mqttTopicRegex(subcribedTopic) { | ||
subcribedTopic = subcribedTopic.replace(/([$.|?*{}()\[\]\\])/g, '\\$1'); // Escape special regex chars except + and # | ||
subcribedTopic = subcribedTopic.replace(/\+/g, '[^/]+'); // Replace + with regex for one or more characters except slash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this quite works when the start of the string is "+", or am I misunderstanding the syntax here wrong?
This would meann that \+
=> \[^/]+
which likely won't work as you want it to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request adds MQTT wildcard support (+
and #
) to the MQTT monitor type, allowing subscription to multiple topics using MQTT wildcard patterns. The implementation converts MQTT wildcard patterns into regular expressions for topic matching.
- Implements MQTT wildcard support by adding regex-based topic matching
- Replaces exact string matching with regex pattern matching for topic subscription
- Adds comprehensive test coverage for wildcard functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
File | Description |
---|---|
server/monitor-types/mqtt.js |
Adds mqttTopicRegex() method and replaces exact topic matching with regex-based matching |
test/backend-test/test-mqtt.js |
Adds comprehensive test cases for wildcard matching scenarios |
server/monitor-types/mqtt.js
Outdated
clientId: "uptime-kuma_" + Math.random().toString(16).substr(2, 8) | ||
}); | ||
|
||
var regexTopic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 'let' instead of 'var' for block-scoped variable declaration following modern JavaScript best practices.
var regexTopic; | |
let regexTopic; |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOPE here explicit usage of var
for global scope of the instance
0679efa
to
67cc26e
Compare
adf384c
to
2ba8568
Compare
Still in progress, please don't close |
We generally only close PRs which are irrevocably stuck. |
📋 Overview
What problem does this pull request address?
+
/#
)Resolves [mqtt] Add Monitoring of Wildcard Topics like
"/device/#"
#5041 [mqtt] Add Monitoring of Wildcard Topics like"/device/#"
#5041I used an LLM for the contributions Assisted by Copilot but need to readapt
One potential Issue:
With wildcards, many simultaneous messages arriving to the client, can slow the process of handling and impact.
The added regex check doesn't help. I am not good enough in JS to produce some enhancement for performance
🛠️ Type of change
📄 Checklist