Skip to content

Commit e735f39

Browse files
committed
Enh 37233934 - Add metrics for ViewMBean (main -> ce-main @112700)
[git-p4: depot-paths = "//dev/coherence-ce/main/": change = 112710]
1 parent ebae11b commit e735f39

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

prj/coherence-core/src/main/java/com/tangosol/net/management/ViewMBean.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77

88
package com.tangosol.net.management;
99

1010
import com.tangosol.net.NamedCache;
11+
1112
import com.tangosol.net.management.annotation.Description;
13+
import com.tangosol.net.management.annotation.MetricsScope;
14+
import com.tangosol.net.management.annotation.MetricsValue;
15+
16+
import com.tangosol.net.metrics.MBeanMetric;
1217

1318
import com.tangosol.util.Filter;
1419
import com.tangosol.util.ValueExtractor;
1520

21+
@MetricsScope(MBeanMetric.Scope.VENDOR)
1622
@Description("Provides View Cache statistics.")
1723
public interface ViewMBean
1824
{
@@ -87,6 +93,7 @@ public interface ViewMBean
8793
*
8894
* @return the number of key-value mappings in this cache
8995
*/
90-
@Description("The number of entries in the cache.")
96+
@Description("The number of entries in the view cache.")
97+
@MetricsValue
9198
long getSize();
9299
}

prj/test/functional/metrics/src/main/java/metrics/SimpleMetricsTests.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -11,9 +11,14 @@
1111

1212
import com.tangosol.internal.net.metrics.MetricsHttpHelper;
1313

14+
import com.tangosol.net.NamedCache;
15+
1416
import org.junit.AfterClass;
1517
import org.junit.BeforeClass;
18+
import org.junit.Test;
1619

20+
import java.util.LinkedHashMap;
21+
import java.util.Map;
1722
import java.util.Properties;
1823

1924
import static com.oracle.bedrock.deferred.DeferredHelper.invoking;
@@ -40,8 +45,8 @@ public static void startup()
4045
{
4146
Properties props = setupProperties();
4247

43-
CoherenceClusterMember clusterMember = startCacheServer("SimpleMetricsTests", "metrics", FILE_SERVER_CFG_CACHE, props);
44-
Eventually.assertThat(invoking(clusterMember).isServiceRunning(MetricsHttpHelper.getServiceName()), is(true));
48+
m_clusterMember = startCacheServer("SimpleMetricsTests", "metrics", FILE_SERVER_CFG_CACHE, props);
49+
Eventually.assertThat(invoking(m_clusterMember).isServiceRunning(MetricsHttpHelper.getServiceName()), is(true));
4550
}
4651

4752
/**
@@ -52,4 +57,29 @@ public static void shutdown()
5257
{
5358
stopCacheServer("SimpleMetricsTests");
5459
}
60+
61+
@Test
62+
public void testViewCache()
63+
throws Exception
64+
{
65+
if (m_clusterMember == null) // no metrics server, return
66+
{
67+
return;
68+
}
69+
70+
NamedCache cache = m_clusterMember.getCache("view-cache");
71+
72+
cache.put(1, "hello");
73+
cache.put(2, "world");
74+
cache.put(3, "bye");
75+
76+
Map<String, String> tags = new LinkedHashMap<>();
77+
tags.put("name", "view-cache");
78+
Eventually.assertThat(invoking(this).getCacheMetric(s_nMetricsHttpPort, "Coherence.View.Size", tags), is(3L));
79+
cache.destroy();
80+
}
81+
82+
// ----- member variables -----------------------------------------------
83+
84+
private static CoherenceClusterMember m_clusterMember;
5585
}

prj/test/functional/metrics/src/main/resources/server-cache-config-metrics.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<!--
3-
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
3+
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
44
55
Licensed under the Universal Permissive License v 1.0 as shown at
66
https://oss.oracle.com/licenses/upl.
@@ -34,6 +34,10 @@
3434
<cache-name>write-through-*</cache-name>
3535
<scheme-name>write-through</scheme-name>
3636
</cache-mapping>
37+
<cache-mapping>
38+
<cache-name>view-*</cache-name>
39+
<scheme-name>view-scheme</scheme-name>
40+
</cache-mapping>
3741
</caching-scheme-mapping>
3842

3943
<caching-schemes>
@@ -148,6 +152,11 @@
148152
<autostart system-property="test.persistence.enabled">true</autostart>
149153
</distributed-scheme>
150154

155+
<view-scheme>
156+
<scheme-name>view-scheme</scheme-name>
157+
<autostart>true</autostart>
158+
</view-scheme>
159+
151160
<proxy-scheme>
152161
<service-name>ExtendTcpProxyService</service-name>
153162
<acceptor-config>

0 commit comments

Comments
 (0)