mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Fix NPE in cluster state collector for monitoring. (#52371)
Take into account a null license may be returned by the license service. Closes #52317
This commit is contained in:
parent
c9f72a0116
commit
d3db6cbf50
@ -105,7 +105,8 @@ public class ClusterStatsCollector extends Collector {
|
|||||||
final List<XPackFeatureSet.Usage> xpackUsage = collect(usageSupplier);
|
final List<XPackFeatureSet.Usage> xpackUsage = collect(usageSupplier);
|
||||||
final boolean apmIndicesExist = doAPMIndicesExist(clusterState);
|
final boolean apmIndicesExist = doAPMIndicesExist(clusterState);
|
||||||
// if they have any other type of license, then they are either okay or already know
|
// if they have any other type of license, then they are either okay or already know
|
||||||
final boolean clusterNeedsTLSEnabled = license.operationMode() == License.OperationMode.TRIAL &&
|
final boolean clusterNeedsTLSEnabled = license != null &&
|
||||||
|
license.operationMode() == License.OperationMode.TRIAL &&
|
||||||
settings.hasValue(SECURITY_ENABLED.getKey()) &&
|
settings.hasValue(SECURITY_ENABLED.getKey()) &&
|
||||||
SECURITY_ENABLED.get(settings) &&
|
SECURITY_ENABLED.get(settings) &&
|
||||||
TRANSPORT_SSL_ENABLED.get(settings) == false;
|
TRANSPORT_SSL_ENABLED.get(settings) == false;
|
||||||
|
@ -260,4 +260,64 @@ public class ClusterStatsCollectorTests extends BaseCollectorTestCase {
|
|||||||
verify(clusterAdminClient).prepareClusterStats();
|
verify(clusterAdminClient).prepareClusterStats();
|
||||||
verify(client).execute(same(XPackUsageAction.INSTANCE), any(XPackUsageRequest.class));
|
verify(client).execute(same(XPackUsageAction.INSTANCE), any(XPackUsageRequest.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDoCollectNoLicense() throws Exception {
|
||||||
|
final TimeValue timeout;
|
||||||
|
{
|
||||||
|
final String clusterName = randomAlphaOfLength(10);
|
||||||
|
whenClusterStateWithName(clusterName);
|
||||||
|
final String clusterUUID = UUID.randomUUID().toString();
|
||||||
|
whenClusterStateWithUUID(clusterUUID);
|
||||||
|
timeout = TimeValue.timeValueSeconds(randomIntBetween(1, 120));
|
||||||
|
withCollectionTimeout(ClusterStatsCollector.CLUSTER_STATS_TIMEOUT, timeout);
|
||||||
|
}
|
||||||
|
final IndexNameExpressionResolver indexNameExpressionResolver;
|
||||||
|
{
|
||||||
|
indexNameExpressionResolver = mock(IndexNameExpressionResolver.class);
|
||||||
|
when(indexNameExpressionResolver.concreteIndices(clusterState, IndicesOptions.lenientExpandOpen(), "apm-*"))
|
||||||
|
.thenReturn(new Index[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Client client = mock(Client.class);
|
||||||
|
{
|
||||||
|
final ClusterStatsResponse mockClusterStatsResponse = mock(ClusterStatsResponse.class);
|
||||||
|
final ClusterHealthStatus clusterStatus = randomFrom(ClusterHealthStatus.values());
|
||||||
|
when(mockClusterStatsResponse.getStatus()).thenReturn(clusterStatus);
|
||||||
|
when(mockClusterStatsResponse.getNodesStats()).thenReturn(mock(ClusterStatsNodes.class));
|
||||||
|
|
||||||
|
final ClusterStatsIndices mockClusterStatsIndices = mock(ClusterStatsIndices.class);
|
||||||
|
|
||||||
|
when(mockClusterStatsIndices.getIndexCount()).thenReturn(0);
|
||||||
|
when(mockClusterStatsResponse.getIndicesStats()).thenReturn(mockClusterStatsIndices);
|
||||||
|
|
||||||
|
final ClusterStatsRequestBuilder clusterStatsRequestBuilder = mock(ClusterStatsRequestBuilder.class);
|
||||||
|
when(clusterStatsRequestBuilder.get(eq(timeout))).thenReturn(mockClusterStatsResponse);
|
||||||
|
|
||||||
|
final ClusterAdminClient clusterAdminClient = mock(ClusterAdminClient.class);
|
||||||
|
when(clusterAdminClient.prepareClusterStats()).thenReturn(clusterStatsRequestBuilder);
|
||||||
|
|
||||||
|
final AdminClient adminClient = mock(AdminClient.class);
|
||||||
|
when(adminClient.cluster()).thenReturn(clusterAdminClient);
|
||||||
|
when(client.admin()).thenReturn(adminClient);
|
||||||
|
|
||||||
|
final XPackUsageResponse xPackUsageResponse = new XPackUsageResponse(
|
||||||
|
singletonList(new MonitoringFeatureSetUsage(true, true, false, null)));
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final ActionFuture<XPackUsageResponse> xPackUsageFuture = (ActionFuture<XPackUsageResponse>) mock(ActionFuture.class);
|
||||||
|
when(client.execute(same(XPackUsageAction.INSTANCE), any(XPackUsageRequest.class))).thenReturn(xPackUsageFuture);
|
||||||
|
when(xPackUsageFuture.actionGet()).thenReturn(xPackUsageResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
final long interval = randomNonNegativeLong();
|
||||||
|
final Settings.Builder settings = Settings.builder();
|
||||||
|
final MonitoringDoc.Node node = MonitoringTestUtils.randomMonitoringNode(random());
|
||||||
|
|
||||||
|
final ClusterStatsCollector collector =
|
||||||
|
new ClusterStatsCollector(settings.build(), clusterService, licenseState,
|
||||||
|
client, licenseService, indexNameExpressionResolver);
|
||||||
|
final Collection<MonitoringDoc> results = collector.doCollect(node, interval, clusterState);
|
||||||
|
assertEquals(1, results.size());
|
||||||
|
final ClusterStatsMonitoringDoc doc = (ClusterStatsMonitoringDoc) results.iterator().next();
|
||||||
|
assertThat(doc.getLicense(), nullValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user