Module @mdf.js/elastic-provider

@mdf.js/elastic-provider

Node Version Typescript Version Known Vulnerabilities Documentation

netin

Mytra Development Framework - @mdf.js/elastic-provider

Typescript tools for development

Elasticsearch provider for @mdf.js based on elasticsearch-js.

Using npm:

npm install @mdf.js/elastic-provider

Using yarn:

yarn add @mdf.js/elastic-provider

Check information about @mdf.js providers in the documentation of the core module @mdf.js/core.

The provider implemented in this module wraps the elasticsearch-js client.

import { Elastic } from '@mdf.js/elastic-provider';

const elastic = Elastic.Factory.create({
name: `myElasticProvider`,
config: {...}, // elasticsearch-js - `ClientOptions`
logger: myLoggerInstance,
useEnvironment: true,
});
  • Defaults:

    {
    nodes: ['http://localhost:9200'],
    maxRetries: 5,
    requestTimeout: 30000,
    pingTimeout: 3000,
    resurrectStrategy: 'ping',
    name: process.env['NODE_APP_INSTANCE'] || 'mdf-elastic',
    }
  • Environment: remember to set the useEnvironment flag to true to use these environment variables.

    {
    nodes: process.env['CONFIG_ELASTIC_NODES'] || process.env['CONFIG_ELASTIC_NODE'], // If CONFIG_ELASTIC_NODES is set, CONFIG_ELASTIC_NODE is ignored. CONFIG_ELASTIC_NODES is split by ','
    maxRetries: process.env['CONFIG_ELASTIC_MAX_RETRIES'],
    requestTimeout: process.env['CONFIG_ELASTIC_REQUEST_TIMEOUT'],
    pingTimeout: process.env['CONFIG_ELASTIC_PING_TIMEOUT'],
    resurrectStrategy: process.env['CONFIG_ELASTIC_RESURRECT_STRATEGY'],
    tls: {
    ca: CA, // file loaded from process.env['CONFIG_ELASTIC_CA_PATH']
    cert: CERT, // file loaded from process.env['CONFIG_ELASTIC_CLIENT_CERT_PATH']
    key: KEY, // file loaded from process.env['CONFIG_ELASTIC_CLIENT_KEY_PATH']
    rejectUnauthorized: process.env['CONFIG_ELASTIC_HTTP_SSL_VERIFY'],
    servername: process.env['CONFIG_ELASTIC_TLS_SERVER_NAME'],
    },
    name: process.env['CONFIG_ELASTIC_NAME'],
    auth, // { username: process.env['CONFIG_ELASTIC_AUTH_USERNAME'], password: process.env['CONFIG_ELASTIC_AUTH_PASSWORD'] } if both are set
    proxy: process.env['CONFIG_ELASTIC_PROXY'],
    }

Checks included in the provider:

  • status: Checks the status of the Elasticsearch nodes using the cat health API and evaluating the number of nodes in red state.
    • observedValue: Actual state of the consumer/producer provider instance [error, running, stopped].
    • status: pass if the status is running, warn if the status is stopped, fail if the status is error.
    • output: in case of error state (status fail), the error message is shown.
  • nodes: Checks and shows the number of nodes in the cluster using the cat nodes API.
    • observedValue: response from the cat nodes API in JSON format.
    • observedUnit: Nodes Health.
    • status: pass if no nodes are in red state, fail in other case.
    • output: in case of fail state At least one of the nodes in the system is red state.
{
"[mdf-elastic:status]": [
{
"status": "pass",
"componentId": "00000000-0000-0000-0000-000000000000",
"observedValue": "running",
"componentType": "database",
"output": undefined,
},
],
"[mdf-elastic:nodes]": [
{
"status": "pass",
"componentId": "00000000-0000-0000-0000-000000000000",
"observedValue": { ... },
"observedUnit": "Nodes Health",
"output": undefined,
},
],
}
  • CONFIG_ELASTIC_NODE (default: undefined): Node to connect to. If CONFIG_ELASTIC_NODES is set, this is ignored.
  • CONFIG_ELASTIC_NODES (default: ['http://localhost:9200']): List of nodes to connect to. If this is set, CONFIG_ELASTIC_NODE is ignored.
  • CONFIG_ELASTIC_MAX_RETRIES (default: 5): Maximum number of retries before failing the request.
  • CONFIG_ELASTIC_REQUEST_TIMEOUT (default: 30000): Time in milliseconds before the request is considered a timeout.
  • CONFIG_ELASTIC_PING_TIMEOUT (default: 3000): Time in milliseconds before the request is considered a timeout.
  • CONFIG_ELASTIC_PROXY (default: undefined): Proxy to use when connecting to the Elasticsearch cluster.
  • CONFIG_ELASTIC_NAME (default: CONFIG_ARTIFACT_ID): Name of the Elasticsearch client.
  • CONFIG_ELASTIC_HTTP_SSL_VERIFY (default: true): Whether to verify the SSL certificate.
  • CONFIG_ELASTIC_CA_PATH (default: undefined): Path to the CA certificate.
  • CONFIG_ELASTIC_CLIENT_CERT_PATH (default: undefined): Path to the client certificate.
  • CONFIG_ELASTIC_CLIENT_KEY_PATH (default: undefined): Path to the client key.
  • CONFIG_ELASTIC_TLS_SERVER_NAME (default: undefined): Server name for the TLS certificate.
  • CONFIG_ELASTIC_AUTH_USERNAME (default: undefined): Username for the Elasticsearch cluster. If this is set, a password must also be provided.
  • CONFIG_ELASTIC_AUTH_PASSWORD (default: undefined): Password for the Elasticsearch cluster. If this is set, a username must also be provided.
  • NODE_APP_INSTANCE (default: undefined): Used as default container id, receiver name, sender name, etc. in cluster configurations.

Copyright 2024 Mytra Control S.L. All rights reserved.

Use of this source code is governed by an MIT-style license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.

Modules

<internal>

Namespaces

Elastic