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

Feature/async diag collect #703

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

vdromanov
Copy link
Contributor

@vdromanov vdromanov commented Feb 20, 2025

переделал бек wb-diag-collect, чтобы не стрелял rpc-таймаутом на загруженных wb

ux никак не поменялся

Summary by CodeRabbit

  • New Features
    • Upgraded the diagnostic data collection to an asynchronous process for improved performance and responsiveness.
  • Style
    • Updated user language support with standardized formatting and streamlined error messaging by removing timeout notifications.

@vdromanov vdromanov requested a review from a team as a code owner February 20, 2025 23:17
Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

This pull request updates the wb-mqtt-homeui package to version 2.111.0 by reworking the diagnostic collection process to use an asynchronous backend. The changes modify the diagnostic controller to include an additional mqttClient parameter and shift from a synchronous call to an event-driven MQTT subscription. Additionally, the i18n JSON files for English and Russian have been updated to standardize formatting and remove timeout error messages, ensuring consistency across localization files.

Changes

File(s) Change Summary
debian/changelog Updated version to 2.111.0; reworked diagnostic collection to use an asynchronous backend.
frontend/app/.../diagnosticController.js Modified DiagnosticCtrl constructor to require mqttClient; replaced synchronous diagnostic method with an MQTT subscription on /wb-diag-collect/artifact and JSON payload parsing.
frontend/app/.../i18n/system/(en ru).json

Sequence Diagram(s)

sequenceDiagram
    participant Ctrl as DiagnosticCtrl
    participant MQTT as mqttClient
    participant FileChecker

    Ctrl->>MQTT: addStickySubscription("/wb-diag-collect/artifact")
    MQTT-->>Ctrl: Receive message(payload)
    Ctrl->>Ctrl: Parse payload (extract fullname & basename)
    Ctrl->>FileChecker: Invoke fileIsOk(basename)
Loading

Suggested reviewers

  • sikmir

Poem

Hopping through the code with glee,
I found async magic waiting for me!
MQTT messages hop along so free,
Diagnostics now dance in harmony.
With every change, my circuits sing,
A bunny's delight in each new ping!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae3896c and 67cb3d6.

📒 Files selected for processing (4)
  • debian/changelog (1 hunks)
  • frontend/app/scripts/controllers/diagnosticController.js (2 hunks)
  • frontend/app/scripts/i18n/system/en.json (1 hunks)
  • frontend/app/scripts/i18n/system/ru.json (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/app/scripts/controllers/diagnosticController.js

[error] 79-79: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 78-78: Use let or const instead of var.

A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
See MDN web docs for more details.
Unsafe fix: Use 'const' instead.

(lint/style/noVar)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (4)
frontend/app/scripts/controllers/diagnosticController.js (1)

2-2: Confirm proper handling of new mqttClient parameter.

You have introduced a mqttClient parameter in the constructor. Verify that all upstream constructors and dependency injections properly instantiate this parameter, ensuring it is never null or undefined.

debian/changelog (1)

1-5: Changelog entry approved.

No issues found in the new version entry. The asynchronous rework is noted and consistent with the PR’s objectives.

frontend/app/scripts/i18n/system/en.json (1)

6-6: Confirm removal of the timeout error key.

Removing the “timeout” entry helps declutter the error messages. Verify there are no references to it elsewhere in the codebase that may lead to undefined string lookups.

frontend/app/scripts/i18n/system/ru.json (1)

6-10: Standardizing Collector Section and Removing Deprecated Error Message

The updated collector title now uses standardized spacing, making it clearer and more consistent with other localization entries. Additionally, the removal of the "timeout" error message is in line with the asynchronous diagnostic collection, but please verify that no frontend component still references this key to avoid any missing key issues.

Comment on lines +73 to +82
mqttClient.addStickySubscription('/wb-diag-collect/artifact', function (msg) {
if (msg.payload) {
const data = JSON.parse(msg.payload)
$scope.path = data['fullname'];
$scope.basename = data['basename'];
var url = getUrl();
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk);
}
}
)
Copy link

@coderabbitai coderabbitai bot Feb 20, 2025

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider managing sticky subscriptions gracefully.

You invoke mqttClient.addStickySubscription without unsubscribing later. Ensure this indefinite subscription does not cause excess resource usage or memory leaks, especially if multiple subscriptions are created over time.

🧰 Tools
🪛 Biome (1.9.4)

[error] 79-79: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 78-78: Use let or const instead of var.

A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
See MDN web docs for more details.
Unsafe fix: Use 'const' instead.

(lint/style/noVar)

Copy link
Contributor

Choose a reason for hiding this comment

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

Кролик прав. Стоит сделать подписку один раз, а в теле обработчика проверять $scope.collecting

Copy link

Choose a reason for hiding this comment

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

@KraPete Here's how we can implement the subscription:

constructor($scope, $translate, DiagnosticProxy, errors, whenMqttReady, mqttClient) {
  // ... existing code ...

  mqttClient.addStickySubscription('/wb-diag-collect/artifact', function (msg) {
    if ($scope.collecting && msg.payload) {
      const data = JSON.parse(msg.payload);
      $scope.path = data['fullname'];
      $scope.basename = data['basename'];
      const url = getUrl();
      fileIsOk(`${location.protocol}//${url}/diag/${$scope.basename}`, callbackFileIsOk);
    }
  });

  var diag = function () {
    $scope.btnEnabled = false;
    changeBtnText('collector.states.collecting');
    $scope.collecting = true;
    DiagnosticProxy.diag();
  };
}

(`^´)


✏️ Learnings added
Learnt from: KraPete
PR: wirenboard/homeui#703
File: frontend/app/scripts/controllers/diagnosticController.js:73-82
Timestamp: 2025-02-21T03:55:57.764Z
Learning: In Angular controllers using MQTT, subscribe to topics once in the constructor and use scope variables to control when the subscription handler should process messages, rather than creating new subscriptions for each operation.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines +78 to +79
var url = getUrl();
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk);
Copy link

@coderabbitai coderabbitai bot Feb 20, 2025

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Adopt modern variable declarations and template literals.

Replacing var url = getUrl(); with a block-scoped declaration and using a template literal for building the URL improves readability and prevents accidental reassignments.

-            var url = getUrl();
-            fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk);
+            const url = getUrl();
+            fileIsOk(`${location.protocol}//${url}/diag/${$scope.basename}`, callbackFileIsOk);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var url = getUrl();
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk);
const url = getUrl();
fileIsOk(`${location.protocol}//${url}/diag/${$scope.basename}`, callbackFileIsOk);
🧰 Tools
🪛 Biome (1.9.4)

[error] 79-79: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 78-78: Use let or const instead of var.

A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
See MDN web docs for more details.
Unsafe fix: Use 'const' instead.

(lint/style/noVar)

Copy link
Contributor

Choose a reason for hiding this comment

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

И тут кролик прав

Copy link

Choose a reason for hiding this comment

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

@KraPete Thank you for confirming! Would you like me to suggest any other modern JavaScript improvements in the codebase?


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link
Contributor

@KraPete KraPete left a comment

Choose a reason for hiding this comment

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

Давай ещё вернём обработку ошибок, как выше в коде через catch.
Ну и кролик везде прав

Comment on lines +73 to +82
mqttClient.addStickySubscription('/wb-diag-collect/artifact', function (msg) {
if (msg.payload) {
const data = JSON.parse(msg.payload)
$scope.path = data['fullname'];
$scope.basename = data['basename'];
var url = getUrl();
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk);
}
}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Кролик прав. Стоит сделать подписку один раз, а в теле обработчика проверять $scope.collecting

Comment on lines +78 to +79
var url = getUrl();
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk);
Copy link
Contributor

Choose a reason for hiding this comment

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

И тут кролик прав

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.

2 participants