npm.io
5.2.1 • Published 3 months ago

@mimik/cluster

Licence
MIT
Version
5.2.1
Deps
5
Size
36 kB
Vulns
0
Weekly
0

cluster

The following environment variables are set:

Env variable name Description Default Comments
REGISTRATION_STATUS Status of the registration with mIT
CLUSTER_STATUS_SERVERS Number of servers in the cluster
CLUSTER_STATUS_UPDATED_AT Timestamp of the last cluster status update
CLUSTER_STATUS_LEASE_TIME Lease time interval

Example

import cluster from '@mimik/cluster';

cluster~cluster(config, metrics) ⇒ object

Create a cluster instance.

Kind: inner method of cluster
Returns: object - - An object exposing rpCluster, createItResource, deleteServer, register, and unRegister.
Requires: module:@mimik/oauth-helper

Param Type Description
config object Configuration object. Requires cluster.management ('off' disables cluster broadcasts), cluster.timeout (per-node request timeout), registration.retry (registration retry interval in ms), serverSettings (id, type, port, basePath, public.location, ip.local, optional clusterStatus), and optional dependencies.mIT.url (mIT base URL; 'n/a' when absent).
metrics object Metrics object. Requires HTTPRequestDuration (the request-duration metric passed through to the underlying HTTP client).

cluster~rpCluster(options) ⇒ Promise

The response is an object with the following structure:

{
  "data": [ 'array of all successful response payloads' ],
  "results": [
    {
      "result": (response from the underlying HTTP client),
      "server": (cluster node that produced the result)
    }
  ],
  "failures": [
    {
      "error": (error thrown for a request to a cluster node),
      "server": (cluster node that produced the error)
    }
  ]
}

Kind: inner method of cluster
Category: async
Requires: module:@mimik/sumologic-winston-logger, module:@mimik/oauth-helper, module:@mimik/response-helper
Fulfil: object - Aggregated response of the request.

Param Type Description
options object Options for the request (similar to axios options). The url MUST be a path only; the base URL is supplied by each cluster node. If options.token is provided, it is augmented with { cluster: true }; otherwise a { cluster: true } token is attached.

cluster~createItResource(con, req, res)

Create IT resource endpoint.

Kind: inner method of cluster
Category: async
Requires: module:@mimik/swagger-helper, module:@mimik/response-helper, module:@mimik/sumologic-winston-logger

Param Type Description
con object Request context (from OpenAPI).
req object The HTTP request.
res object The HTTP response.

cluster~deleteServer(con, req, res)

Delete server endpoint.

Kind: inner method of cluster
Category: async
Requires: module:@mimik/swagger-helper, module:@mimik/response-helper

Param Type Description
con object Request context (from OpenAPI).
req object The HTTP request.
res object The HTTP response.

cluster~register(correlationId, retry) ⇒ Promise

Register a server with mIT.

Kind: inner method of cluster
Category: async
Requires: module:@mimik/sumologic-winston-logger, module:@mimik/oauth-helper, module:@mimik/address-helper
Fulfil: null

Registration with mIT is retried at the interval defined by config.registration.retry. When registration completes, a lease call is made to mIT at a regular interval. The lease interval is defined by mIT; if unspecified, it defaults to 2 hours. When cluster management is enabled, a concurrent registration is executed after approximately 60 seconds to guarantee cluster integrity.

Param Type Description
correlationId string Correlation ID to associate with the request.
retry boolean Pass false for the initial registration. Used internally when the module recursively invokes itself for concurrent registration (~60s after first success) to guarantee cluster integrity.

cluster~unRegister(correlationId) ⇒ Promise

The returned object is:

{
  nbServers: "number of servers in the cluster",
  serverId: "server ID",
  errors: "optional array of errors that occurred while unregistering"
}

Kind: inner method of cluster
Category: async
Requires: module:@mimik/sumologic-winston-logger, module:@mimik/oauth-helper
Fulfil: An object containing the number of servers, the serverId, and any errors (if present).

Param Type Description
correlationId string Correlation ID to associate with the request.

Keywords