99
1010package org .elasticsearch .cluster .routing .allocation .allocator ;
1111
12+ import org .elasticsearch .cluster .ClusterInfoService ;
13+ import org .elasticsearch .cluster .ClusterInfoServiceUtils ;
14+ import org .elasticsearch .cluster .InternalClusterInfoService ;
1215import org .elasticsearch .cluster .node .DiscoveryNode ;
1316import org .elasticsearch .common .util .CollectionUtils ;
17+ import org .elasticsearch .core .TimeValue ;
1418import org .elasticsearch .plugins .Plugin ;
1519import org .elasticsearch .plugins .PluginsService ;
1620import org .elasticsearch .telemetry .TestTelemetryPlugin ;
@@ -56,8 +60,15 @@ public void testDesiredBalanceGaugeMetricsAreOnlyPublishedByCurrentMaster() thro
5660 public void testDesiredBalanceMetrics () {
5761 internalCluster ().startNodes (2 );
5862 prepareCreate ("test" ).setSettings (indexSettings (2 , 1 )).get ();
59- indexRandom (randomBoolean (), "test" , between (50 , 100 ));
6063 ensureGreen ();
64+
65+ indexRandom (randomBoolean (), "test" , between (50 , 100 ));
66+ flush ("test" );
67+ // Make sure new cluster info is available
68+ final var infoService = (InternalClusterInfoService ) internalCluster ().getCurrentMasterNodeInstance (ClusterInfoService .class );
69+ ClusterInfoServiceUtils .setUpdateFrequency (infoService , TimeValue .timeValueMillis (200 ));
70+ assertNotNull ("info should not be null" , ClusterInfoServiceUtils .refresh (infoService ));
71+
6172 final var telemetryPlugin = getTelemetryPlugin (internalCluster ().getMasterName ());
6273 telemetryPlugin .collect ();
6374 assertThat (telemetryPlugin .getLongGaugeMeasurement (DesiredBalanceMetrics .UNASSIGNED_SHARDS_METRIC_NAME ), not (empty ()));
@@ -73,7 +84,7 @@ public void testDesiredBalanceMetrics() {
7384 );
7485 assertThat (desiredBalanceNodeWeightsMetrics .size (), equalTo (2 ));
7586 for (var nodeStat : desiredBalanceNodeWeightsMetrics ) {
76- assertThat (nodeStat .value (). doubleValue (), greaterThanOrEqualTo ( 0.0 ));
87+ assertTrue (nodeStat .isDouble ( ));
7788 assertThat ((String ) nodeStat .attributes ().get ("node_id" ), is (in (nodeIds )));
7889 assertThat ((String ) nodeStat .attributes ().get ("node_name" ), is (in (nodeNames )));
7990 }
@@ -122,15 +133,16 @@ public void testDesiredBalanceMetrics() {
122133 assertThat ((String ) nodeStat .attributes ().get ("node_id" ), is (in (nodeIds )));
123134 assertThat ((String ) nodeStat .attributes ().get ("node_name" ), is (in (nodeNames )));
124135 }
125- final var currentNodeDiskUsageMetrics = telemetryPlugin .getDoubleGaugeMeasurement (
136+ final var currentNodeDiskUsageMetrics = telemetryPlugin .getLongGaugeMeasurement (
126137 DesiredBalanceMetrics .CURRENT_NODE_DISK_USAGE_METRIC_NAME
127138 );
128139 assertThat (currentNodeDiskUsageMetrics .size (), equalTo (2 ));
129140 for (var nodeStat : currentNodeDiskUsageMetrics ) {
130- assertThat (nodeStat .value ().doubleValue (), greaterThanOrEqualTo (0.0 ));
141+ assertThat (nodeStat .value ().longValue (), greaterThanOrEqualTo (0L ));
131142 assertThat ((String ) nodeStat .attributes ().get ("node_id" ), is (in (nodeIds )));
132143 assertThat ((String ) nodeStat .attributes ().get ("node_name" ), is (in (nodeNames )));
133144 }
145+ assertTrue (currentNodeDiskUsageMetrics .stream ().anyMatch (m -> m .getLong () > 0L ));
134146 final var currentNodeUndesiredShardCountMetrics = telemetryPlugin .getLongGaugeMeasurement (
135147 DesiredBalanceMetrics .CURRENT_NODE_UNDESIRED_SHARD_COUNT_METRIC_NAME
136148 );
@@ -140,15 +152,16 @@ public void testDesiredBalanceMetrics() {
140152 assertThat ((String ) nodeStat .attributes ().get ("node_id" ), is (in (nodeIds )));
141153 assertThat ((String ) nodeStat .attributes ().get ("node_name" ), is (in (nodeNames )));
142154 }
143- final var currentNodeForecastedDiskUsageMetrics = telemetryPlugin .getDoubleGaugeMeasurement (
155+ final var currentNodeForecastedDiskUsageMetrics = telemetryPlugin .getLongGaugeMeasurement (
144156 DesiredBalanceMetrics .CURRENT_NODE_FORECASTED_DISK_USAGE_METRIC_NAME
145157 );
146158 assertThat (currentNodeForecastedDiskUsageMetrics .size (), equalTo (2 ));
147159 for (var nodeStat : currentNodeForecastedDiskUsageMetrics ) {
148- assertThat (nodeStat .value ().doubleValue (), greaterThanOrEqualTo (0.0 ));
160+ assertThat (nodeStat .value ().longValue (), greaterThanOrEqualTo (0L ));
149161 assertThat ((String ) nodeStat .attributes ().get ("node_id" ), is (in (nodeIds )));
150162 assertThat ((String ) nodeStat .attributes ().get ("node_name" ), is (in (nodeNames )));
151163 }
164+ assertTrue (currentNodeForecastedDiskUsageMetrics .stream ().anyMatch (m -> m .getLong () > 0L ));
152165 }
153166
154167 private static void assertOnlyMasterIsPublishingMetrics () {
@@ -182,10 +195,10 @@ private static void assertMetricsAreBeingPublished(String nodeName, boolean shou
182195 matcher
183196 );
184197 assertThat (testTelemetryPlugin .getDoubleGaugeMeasurement (DesiredBalanceMetrics .CURRENT_NODE_WRITE_LOAD_METRIC_NAME ), matcher );
185- assertThat (testTelemetryPlugin .getDoubleGaugeMeasurement (DesiredBalanceMetrics .CURRENT_NODE_DISK_USAGE_METRIC_NAME ), matcher );
198+ assertThat (testTelemetryPlugin .getLongGaugeMeasurement (DesiredBalanceMetrics .CURRENT_NODE_DISK_USAGE_METRIC_NAME ), matcher );
186199 assertThat (testTelemetryPlugin .getLongGaugeMeasurement (DesiredBalanceMetrics .CURRENT_NODE_SHARD_COUNT_METRIC_NAME ), matcher );
187200 assertThat (
188- testTelemetryPlugin .getDoubleGaugeMeasurement (DesiredBalanceMetrics .CURRENT_NODE_FORECASTED_DISK_USAGE_METRIC_NAME ),
201+ testTelemetryPlugin .getLongGaugeMeasurement (DesiredBalanceMetrics .CURRENT_NODE_FORECASTED_DISK_USAGE_METRIC_NAME ),
189202 matcher
190203 );
191204 assertThat (
0 commit comments