Skip to content

Listeners in cluster workers #747

Description

@guapter

When i tried to make clusterMetrics() collector i had an issue where this function always get errorTimeout.
Master process code:

private aggregator: Client.AggregatorRegistry<Client.RegistryContentType>

constructor() {
    this.aggregator = new Client.AggregatorRegistry()
}

getMetrics = async () => {
    const workersMetrics = await this.aggregator.clusterMetrics()
    return workersMetrics
}

worker code:

private registry: Client.Registry

constructor() {
    this.registry = new Client.Registry()
    Client.AggregatorRegistry.setRegistries(this.registry)
    //some metrics
}

After searching source code i found that listeners for message GET_METRICS_REQ only apply if Client.AggregatorRegistry class constructor is runned (basically worker need new Client.AggregatorRegistry() too)

Source code in node_modules/prom-client/lib/cluster.js
Image
setRegistries:
Image

Suggestions(variants):

  • add listeners when setRegistries run - function for listeners already have check for duplicate run
  • add static call for addListeners() function and add it to guide - so it could be run separately and manually

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions