8000 Do not report clustered caches without configuration in the server info by costa-chown · Pull Request #55573 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
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 @@ -484,9 +484,16 @@ public boolean isCoordinatorSupported() {
}

private void addEmbeddedOperationalInfo(Map<String, String> info) {
addEmbeddedOperationalInfo(cacheManager, info);
}

// Only caches with a configuration: login-failures:v2 and stateless remove some of
// CLUSTERED_CACHE_NAMES, and Infinispan reports a cache it does not know as FAILED.
static void addEmbeddedOperationalInfo(EmbeddedCacheManager cacheManager, Map<String, String> info) {
var cacheManagerInfo = cacheManager.getCacheManagerInfo();
info.put("clusterSize", Integer.toString(cacheManagerInfo.getClusterSize()));
var cacheNames = Arrays.stream(CLUSTERED_CACHE_NAMES)
.filter(cacheManager::cacheConfigurationExists)
.sorted()
.collect(Collectors.toCollection(LinkedHashSet::new));
for (CacheHealth health : cacheManager.getHealth().getCacheHealth(cacheNames)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2026 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.connections.infinispan;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager;
import org.junit.Assert;
import org.junit.Test;

import static org.keycloak.connections.infinispan.InfinispanConnectionProvider.CLUSTERED_CACHE_NAMES;
import static org.keycloak.connections.infinispan.InfinispanConnectionProvider.LOGIN_FAILURE_CACHE_NAME;

public class EmbeddedOperationalInfoTest {

@Test
public void testCacheWithoutConfigurationIsNotReported() throws IOException {
// As with login-failures:v2: every clustered cache but loginFailures is defined.
try (DefaultCacheManager cacheManager = new DefaultCacheManager(new GlobalConfigurationBuilder().nonClusteredDefault().build())) {
for (String name : CLUSTERED_CACHE_NAMES) {
if (!LOGIN_FAILURE_CACHE_NAME.equals(name)) {
cacheManager.defineConfiguration(name, new ConfigurationBuilder().build());
cacheManager.getCache(name);
}
}

Map<String, String> info = new HashMap<>();
DefaultInfinispanConnectionProviderFactory.addEmbeddedOperationalInfo(cacheManager, info);

Assert.assertFalse(info.containsKey(LOGIN_FAILURE_CACHE_NAME + ":Cache"));
for (String name : CLUSTERED_CACHE_NAMES) {
if (!LOGIN_FAILURE_CACHE_NAME.equals(name)) {
Assert.assertEquals(name, "HEALTHY", info.get(name + ":Cache"));
}
}
Assert.assertFalse(info.containsValue("FAILED"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,15 @@ public void testServerInfo() {
Map<String, ProviderRepresentation> jpaProviders = info.getProviders().get("connectionsJpa").getProviders();
ProviderRepresentation jpaProvider = jpaProviders.values().iterator().next();
Assertions.assertNotNull(jpaProvider.getOperationalInfo());

// Caches that the features in use do not define, such as loginFailures with
// login-failures:v2, are not reported, so no cache reads as FAILED.
Map<String, ProviderRepresentation> infinispanProviders = info.getProviders().get("connectionsInfinispan").getProviders();
for (ProviderRepresentation infinispanProvider : infinispanProviders.values()) {
Map<String, String> operationalInfo = infinispanProvider.getOperationalInfo();
if (operationalInfo != null) {
Assertions.assertFalse(operationalInfo.containsValue("FAILED"), operationalInfo.toString());
}
}
}
}
0