wazuh / wazuh-indexer-plugins

GNU Affero General Public License v3.0
1 stars 3 forks source link

Create UML diagrams for the `wazuh-indexer-setup` plugin #11

Closed AlexRuiz7 closed 4 months ago

AlexRuiz7 commented 4 months ago

Description

Create UML diagrams for the proposed design (#3) of the wazuh-indexer-setup plugin. We want to complement the new plugins with properly documented designs from the beginning of the development.

Tasks

AlexRuiz7 commented 4 months ago

Sequence diagram

[!Note] Calls to Client are asynchronous.

sequenceDiagram
    actor Node
    participant SetupPlugin
    participant WazuhIndices
    participant Client
    Node->>SetupPlugin: plugin.onNodeStarted()
    activate SetupPlugin
    Note over Node,SetupPlugin: Invoked on Node::start()

    activate WazuhIndices
    SetupPlugin->>WazuhIndices: initialize()

    Note over SetupPlugin,WazuhIndices: Create index templates and indices
    loop i..n templates
        WazuhIndices-)Client: templateExists(i)
        Client--)WazuhIndices: response
        alt template i does not exist
            WazuhIndices-)Client: putTemplate(i)
            Client--)WazuhIndices: response
        end
    end
    loop i..n indices
        WazuhIndices-)Client: indexExists(i)
        Client--)WazuhIndices: response
        alt index i does not exist
            WazuhIndices-)Client: putIndex(i)
            Client--)WazuhIndices: response
        end
    end
    deactivate WazuhIndices
    deactivate SetupPlugin

Class diagram

---
title: Wazuh Indexer setup plugin
---
classDiagram
    direction LR
    SetupPlugin"1"-->WazuhIndices
    WazuhIndices"1"-->Client
    <<service>> Client

    SetupPlugin : -WazuhIndices indices
    SetupPlugin : +createComponents()
    SetupPlugin : +onNodeStarted()

    WazuhIndices : -Client client
    WazuhIndices : -ClusterService clusterService
    WazuhIndices : +WazuhIndices(Client client, ClusterService clusterService)
    WazuhIndices : +putTemplate(String template) void
    WazuhIndices : +putIndex(String index) void
    WazuhIndices : +indexExists(String index) bool
    WazuhIndices : +templateExists(String template) bool
    WazuhIndices : +initialize() void

[!NOTE]
rev 0.1 - July 10, 2024: Add initial diagrams rev 0.2 - July 11, 2024: Add index templates operations rev 0.3 - August 29, 2024: Update diagrams to lastest design

AlexRuiz7 commented 4 months ago

Closing notes

Having diagrammed the plugin, I wonder where it would make more sense to include the loop to create the indices. Creating an index consists of invoking client.admin().indices().create(indexRequest, actionListener), where actionListener is a callback and indexRequest contains the index's name, mappings and settings. These are read from separate YML files. This is a problem as the index templates we are defining on https://github.com/wazuh/wazuh-indexer/issues/270 follow a different format (JSON, API compliant).

On the other hand, the filenames for these mappings and settings are currently included in the code of the WazuhIndices class as constants. Future updates to the indices will require updating this class manually. This could be avoided by automatically reading the resources' folder of the plugin. In this case, a matching strategy between the index name, its mappings filename and its settings filename needs to be created.

We need to explore how to create index templates (using the Index Management plugin), as a way to overcome the problems stated above. The strategy of creating single indices with mappings and settings only works for that particular index, and won't apply to rotated stream indices.

AlexRuiz7 commented 4 months ago

We need to explore how to create index templates (using the Index Management plugin), as a way to overcome the problems stated above. The strategy of creating single indices with mappings and settings only works for that particular index, and won't apply to rotated stream indices.

OpenSearch Playground has 2 composable index templates. Searching the name .opensearch-sap-detectors-queries-index-template, I found out there is an API at opensearch.admin.indices.template.put.

  1. playground.opensearch.org
  2. DetectorMonitorConfig.java#L22
  3. RuleTopicIndices.java#L16
  4. PutComposableIndexTemplateAction.java#L61