Skip to content

ZOOKEEPER-4930: Add metrics for TTL node deletion #2261

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ public void deleteNode(String path, long zxid) throws NoNodeException {
containers.remove(path);
} else if (ephemeralType == EphemeralType.TTL) {
ttls.remove(path);
ServerMetrics.getMetrics().TTL_NODE_DELETED_COUNT.add(1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create Node need metrics alse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This JIRA is for TTL deletion metrics.

Copy link
Contributor Author

@li4wang li4wang Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeekling Opened a JIRA for TTL creation metrics.

https://issues.apache.org/jira/browse/ZOOKEEPER-4934

I can submit a PR for it.

} else if (owner != 0) {
Set<String> nodes = ephemerals.get(owner);
if (nodes != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ private ServerMetrics(MetricsProvider metricsProvider) {
JVM_PAUSE_TIME = metricsContext.getSummary("jvm_pause_time_ms", DetailLevel.ADVANCED);

QUOTA_EXCEEDED_ERROR_PER_NAMESPACE = metricsContext.getCounterSet(QuotaMetricsUtils.QUOTA_EXCEEDED_ERROR_PER_NAMESPACE);

TTL_NODE_DELETED_COUNT = metricsContext.getCounter("ttl_node_deleted_count");
}

/**
Expand Down Expand Up @@ -547,6 +549,11 @@ private ServerMetrics(MetricsProvider metricsProvider) {

public final CounterSet QUOTA_EXCEEDED_ERROR_PER_NAMESPACE;

/**
* Count of deleted TTL nodes
*/
public final Counter TTL_NODE_DELETED_COUNT;

private final MetricsProvider metricsProvider;

public void resetAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
Expand All @@ -38,6 +40,7 @@
import org.apache.zookeeper.TestableZooKeeper;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.metrics.MetricsUtils;
import org.apache.zookeeper.proto.CreateResponse;
import org.apache.zookeeper.proto.CreateTTLRequest;
import org.apache.zookeeper.proto.ReplyHeader;
Expand Down Expand Up @@ -91,6 +94,10 @@ public void testCreate() throws KeeperException, InterruptedException {
fakeElapsed.set(1000);
containerManager.checkContainers();
assertNull(zk.exists("/foo", false), "Ttl node should have been deleted");

// validate deleted TTL nodes count
Map<String, Object> metrics = MetricsUtils.currentServerMetrics();
assertTrue((long) metrics.get("ttl_node_deleted_count") >= 1);
}

@Test
Expand Down