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

Adapt the logging method of the plugins to the provided by the platform #6137

Closed
19 tasks done
Tracked by #6127
Desvelao opened this issue Nov 20, 2023 · 4 comments · Fixed by #6161, wazuh/wazuh-documentation#6810 or #6875
Closed
19 tasks done
Tracked by #6127
Assignees
Labels
level/task Task issue type/enhancement Enhancement issue

Comments

@Desvelao
Copy link
Member

Desvelao commented Nov 20, 2023

Description
As part of the issue that pretends to remove the stateful of the Wazuh dashboard plugins, we need to adapt the logging of the plugins to use the method provided by the platform.

Tasks:

  • Adapt the usage of logging on the backend side:
    • Endpoints
    • Tasks
      • Initialize
      • Monitoring
      • Statistics
      • Migration
      • Queue
    • Services
  • Remove the creation of folders and files
  • Remove the custom logger of the plugins
    • Remove the winston plugin dependency because of unused anymore
  • Remove the logs.level setting
  • Desirable. Research how to display the logs in the frontend to keep the functionality of the App logs module of the Wazuh dashboard.
    • If this is not possible, the App logs application should be removed
    • Remove backend endpoint to retrieve the logs
    • Remove the application to register
    • Remove the UI of the application
@Desvelao Desvelao self-assigned this Nov 20, 2023
@Desvelao Desvelao added type/enhancement Enhancement issue level/task Task issue labels Nov 20, 2023
@wazuhci wazuhci moved this to Triage in Release 4.9.0 Nov 20, 2023
@Desvelao Desvelao moved this from Triage to In progress in Release 4.9.0 Nov 20, 2023
@Desvelao
Copy link
Member Author

Desvelao commented Nov 21, 2023

Design - Backend

Tasks

The backend tasks already receive the logger through parameters. We will remove the old logging system in favor of the platform.

Endpoints

Most of the API endpoints of the plugins use the old logging method that we want to remove. This method defines tags to identify the related controllers of endpoints. We will replace it with an instance whose tag is related to the method and endpoint path.

Services

Some current services use the current logging service through an import. Because the logging method of the platform is available in runtime, the usage of the logging depends on this. We will rework the services to initialize with the logger of the platform. We will move these services to the core plugin and adapt the rest of the plugin to use this definition. This approach was discussed with @asteriscos in a meeting.

@Desvelao Desvelao linked a pull request Nov 28, 2023 that will close this issue
6 tasks
@Desvelao Desvelao linked a pull request Nov 28, 2023 that will close this issue
7 tasks
@wazuhci wazuhci moved this from In progress to On hold in Release 4.9.0 Nov 29, 2023
@wazuhci wazuhci moved this from On hold to In progress in Release 4.9.0 Dec 1, 2023
@Desvelao
Copy link
Member Author

Desvelao commented Dec 1, 2023

Research the possibility to display the related logs on App logs application

I was reviewing the source code of the logging service of the platform and this doesn't have a way to retrieve the logs.

The provided logger is an instance of LoggerAdapter https://github.com/opensearch-project/OpenSearch-Dashboards/blob/2.11.0/src/core/server/logging/logger_adapter.ts#L34-L80 that doesn't save the logs in memory.

As a possible workaround, we could create a wrapper that stores the logs in memory which means any restart causes the previous logs to be lost. This would allow the related logs to the Wazuh dashboard plugins could be displayed in the current App logs application.

class WzLogger(){
  constructor(private platformLoggerAdapter){
    this._store = []

    // implement each logging method of the platform logger instance
    ['info', 'warn', 'error', 'debug', 'trace'].forEach(level => {
      this.[level] = (message, meta) => {
       this._log(level, message, meta)
      }
    })
  }

  
  _log(level, message, meta){
    this._store.push({level, message, meta})
    this.platformLoggerAdapter[level](message, meta)
  }

  getLogs(){
   return this._store
  }
}

Note the suggested wrapper only works for one logger and the application creates multiple loggers with different contexts, so we must store all the logs of the loggers in one store instead.

If we decide to advance with this approach, we should consider implementing a limit of logs that can be stored else could cause memory problems due to this increase indefinitely.

@Desvelao
Copy link
Member Author

Desvelao commented Dec 4, 2023

Proposition - Remove the possibility to see the plugins logs through the UI

I was analyzing the utility of access to app logs and I consider these could be removed.

The current functionality only reports the last 50 logs of the wazuhapp.log file https://github.com/wazuh/wazuh-dashboard-plugins/blob/v4.6.0-2.8.0/plugins/main/server/controllers/wazuh-utils/wazuh-utils.ts#L110-L113, so it seems this could not be useful for the users and maybe we could remove it in favor of exploring the logs through the provided mechanism of the platform (see console or file output depending on the configuration of Wazuh dashboard)

So, I was working on a patch to remove the App logs application. This includes the following modifications:

Changes

  • Remove GET /utils/logs endpoint

    • Remove related tests
  • Remove App logs application

    • Remove UI view
    • Remove the fetching of data in AngularJS controllers

    remove-app-logs-application.txt

@asteriscos and I had a meeting where we were talking about my proposition of removing the App logs application. This must be approved by @gdiazlo .

@wazuhci wazuhci moved this from In progress to On hold in Release 4.9.0 Dec 4, 2023
@wazuhci wazuhci moved this from On hold to In progress in Release 4.9.0 Dec 5, 2023
@wazuhci wazuhci moved this from In progress to On hold in Release 4.9.0 Dec 7, 2023
@Desvelao
Copy link
Member Author

We have decided in a meeting to remove the ability to see the plugin logs through a specific application (App logs) in favor of using the default way to retrieve the logs of the platform.

@wazuhci wazuhci moved this from On hold to Pending review in Release 4.9.0 Dec 11, 2023
@wazuhci wazuhci moved this from Pending review to In review in Release 4.9.0 Dec 20, 2023
@wazuhci wazuhci moved this from In review to Done in Release 4.9.0 Dec 27, 2023
@Desvelao Desvelao reopened this Feb 7, 2024
@wazuhci wazuhci moved this from Done to Triage in Release 4.9.0 Feb 7, 2024
@wazuhci wazuhci moved this from Triage to In progress in Release 4.9.0 Feb 7, 2024
@wazuhci wazuhci moved this from In progress to On hold in Release 4.9.0 Feb 9, 2024
@wazuhci wazuhci moved this from On hold to Done in Release 4.9.0 Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment