Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listener for node addition / deletion #334

Open
anuragagarwal561994 opened this issue Aug 25, 2024 · 4 comments
Open

Add listener for node addition / deletion #334

anuragagarwal561994 opened this issue Aug 25, 2024 · 4 comments

Comments

@anuragagarwal561994
Copy link

anuragagarwal561994 commented Aug 25, 2024

I am trying to record metrics of aerospike via micrometer client.

So for example if I need to record the connections stats as a gauge I would need to declare it like

Gauge.builder(MetricName.AEROSPIKE_SYNC_CONNECTION_STATS, node, c -> c.sync.closed)
                .tags("state", CLOSED)
                .description("Aerospike sync connection closed stats")
                .register(meterRegistry);

Node I can touch the node instance here, once the guage is configured it is done, it will keep monitoring the node.

I can set this up at the start of the client, but when new nodes get added or removed, this is not changed.

If I would have had a listener of when the node is added or removed, I can create a new gauge with the new instance and remove the old one respectively from recording via micrometer.

There exists a MetricListener with the help of which I can somewhat achieve this, in a way:

public class AerospikeMetricListener implements MetricsListener {
    private final Map<String, Node> nodeMap = new ConcurrentHashMap<>();

    @Override
    public void onEnable(Cluster cluster, MetricsPolicy policy) {
        for (var node : cluster.getNodes()) {
            nodeMap.put(node.getName(), node);
        }
    }

    @Override
    public void onSnapshot(Cluster cluster) {
        for (var node : cluster.getNodes()) {
            nodeMap.putIfAbsent(node.getName(), node);
        }
    }

    @Override
    public void onNodeClose(Node node) {
        nodeMap.remove(node.getName());
    }

    @Override
    public void onDisable(Cluster cluster) {
        nodeMap.clear();
    }
}

Now when I know there is a new entry, I can start tracking the gauge. But this metric listener also starts recording the aerospike internal latency metrics as well on which I don't have much control and managing this listener is like an added responsibility for the client.

I think aerospike can provide listeners on addition and deletion of new nodes and moreover if possible I would say do provide the micromerter implementation itself, because that will help larger audience to consistently track client metrics.

@BrianNichols
Copy link
Member

The deletion of a node is already covered by onNodeClose(). If a node is added and logging is enabled (https://aerospike.com/developer/client/logging?client=java), the client sends a log message starting with "Add node".

If this is not sufficient, an extra MetricsListener method called "onNodeOpen(Node node)" could be added. We are currently busy with other tasks, so it needs to wait for now.

@anuragagarwal561994
Copy link
Author

I think reading the log message is not the right way, moreover it won't give me the instance of the new node.

I think I can contribute for this simple functionality, also what are your thoughts about using micrometer or any instrumentation in the client?

@BrianNichols
Copy link
Member

The goal is to minimize dependencies on 3rd party libraries, so adding an extra instrumentation library dependency is not likely.

@anuragagarwal561994
Copy link
Author

May be if possible a separate module can be provided which adds the support or help with OpenTelemetry auto instrumentation.

We tried it ourselves but it will be helpful if done from the side of aerospike I feel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants