fix: fetch actual agent/environment counts from server for tenant dashboard
All checks were successful
CI / build (push) Successful in 1m8s
CI / docker (push) Successful in 43s

The dashboard was showing hardcoded zeroes for agent and environment usage.
Now fetches real counts via M2M API from the tenant's server.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-10 20:35:24 +02:00
parent cab6e409b9
commit a5445e332e
5 changed files with 51 additions and 5 deletions

View File

@@ -124,6 +124,38 @@ public class ServerApiClient {
}
}
/** Fetch agent count from a tenant's server. */
public int getAgentCount(String serverEndpoint) {
try {
var resp = RestClient.create().get()
.uri(serverEndpoint + "/api/v1/agents")
.header("Authorization", "Bearer " + getAccessToken())
.header("X-Cameleer-Protocol-Version", "1")
.retrieve()
.body(java.util.List.class);
return resp != null ? resp.size() : 0;
} catch (Exception e) {
log.warn("Agent count fetch failed for {}: {}", serverEndpoint, e.getMessage());
return 0;
}
}
/** Fetch environment count from a tenant's server. */
public int getEnvironmentCount(String serverEndpoint) {
try {
var resp = RestClient.create().get()
.uri(serverEndpoint + "/api/v1/admin/environments")
.header("Authorization", "Bearer " + getAccessToken())
.header("X-Cameleer-Protocol-Version", "1")
.retrieve()
.body(java.util.List.class);
return resp != null ? resp.size() : 0;
} catch (Exception e) {
log.warn("Environment count fetch failed for {}: {}", serverEndpoint, e.getMessage());
return 0;
}
}
public record ServerHealthResponse(boolean healthy, String status) {}
private synchronized String getAccessToken() {

View File

@@ -47,7 +47,8 @@ public class TenantPortalService {
String name, String slug, String tier, String status,
boolean serverHealthy, String serverStatus, String serverEndpoint,
String licenseTier, long licenseDaysRemaining,
Map<String, Object> limits, Map<String, Object> features
Map<String, Object> limits, Map<String, Object> features,
int agentCount, int environmentCount
) {}
public record LicenseData(
@@ -82,10 +83,16 @@ public class TenantPortalService {
boolean serverHealthy = false;
String serverStatus = "NO_ENDPOINT";
int agentCount = 0;
int environmentCount = 0;
if (endpoint != null && !endpoint.isBlank()) {
var health = serverApiClient.getHealth(endpoint);
serverHealthy = health.healthy();
serverStatus = health.status();
if (serverHealthy) {
agentCount = serverApiClient.getAgentCount(endpoint);
environmentCount = serverApiClient.getEnvironmentCount(endpoint);
}
}
String licenseTier = null;
@@ -107,7 +114,7 @@ public class TenantPortalService {
tenant.getTier().name(), tenant.getStatus().name(),
serverHealthy, serverStatus, endpoint,
licenseTier, licenseDaysRemaining,
limits, features
limits, features, agentCount, environmentCount
);
}