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:
cat health API
and evaluating the number of nodes in red
state.
error
, running
, stopped
].pass
if the status is running
, warn
if the status is stopped
, fail
if the status is error
.error
state (status fail
), the error message is shown.cat nodes API
.
cat nodes API
in JSON format.Nodes Health
.pass
if no nodes are in red
state, fail
in other case.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,
},
],
}
undefined
): Node to connect to. If CONFIG_ELASTIC_NODES is set, this is ignored.['http://localhost:9200']
): List of nodes to connect to. If this is set, CONFIG_ELASTIC_NODE is ignored.5
): Maximum number of retries before failing the request.30000
): Time in milliseconds before the request is considered a timeout.3000
): Time in milliseconds before the request is considered a timeout.undefined
): Proxy to use when connecting to the Elasticsearch cluster.CONFIG_ARTIFACT_ID
): Name of the Elasticsearch client.true
): Whether to verify the SSL certificate.undefined
): Path to the CA certificate.undefined
): Path to the client certificate.undefined
): Path to the client key.undefined
): Server name for the TLS certificate.undefined
): Username for the Elasticsearch cluster. If this is set, a password must also be provided.undefined
): Password for the Elasticsearch cluster. If this is set, a username must also be provided.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.