feat(worldapi): registered regions and Grid/Asset service health
* feat(worldapi): authoritative registered and online regions plus read-only service health * feat(worldapi): connect GridStore and AssetService to public and authenticated statistics * docs(openapi): declare registered regions, grid and asset service health * fix(worldapi): stable region ordering and honest partial service health * test(worldapi): verify GridStore regions and read-only service probes * docs(worldapi): explain full region inventory and service read-only diagnostics * docs(openapi): include partial statistics detail-level state * test(worldapi): expect combined GridUser, GridStore and AssetService quality metrics
This commit is contained in:
1 parent
9b97b2594f
commit
d31c03168f
5 files changed
+294
-14
No files matched your search
@@ -26,6 +26,8 @@ namespace NexVerse.Server.Api
|
||||
private readonly IGridUserData m_GridUsers;
|
||||
private readonly IPresenceService m_Presence;
|
||||
private readonly IGridService m_Grid;
|
||||
private readonly IRegionData m_RegionData;
|
||||
private readonly IAssetService m_Assets;
|
||||
private readonly NexApiAuthenticator m_Authenticator;
|
||||
private readonly bool m_AllowPublicAggregates;
|
||||
|
||||
@@ -35,12 +37,16 @@ namespace NexVerse.Server.Api
|
||||
IPresenceService presence,
|
||||
IGridService grid,
|
||||
NexApiAuthenticator authenticator,
|
||||
bool allowPublicAggregates)
|
||||
bool allowPublicAggregates,
|
||||
IRegionData regionData = null,
|
||||
IAssetService assets = null)
|
||||
{
|
||||
m_UserAccounts = userAccounts;
|
||||
m_GridUsers = gridUsers;
|
||||
m_Presence = presence;
|
||||
m_Grid = grid;
|
||||
m_RegionData = regionData;
|
||||
m_Assets = assets;
|
||||
m_Authenticator = authenticator;
|
||||
m_AllowPublicAggregates = allowPublicAggregates;
|
||||
}
|
||||
@@ -298,6 +304,9 @@ namespace NexVerse.Server.Api
|
||||
// online counts remain meaningful, otherwise report unknown.
|
||||
bool residentOnlineKnown = gridUserAvailable || presenceAvailable;
|
||||
|
||||
RegionSnapshot regions = ReadRegions();
|
||||
string assetStatus = ReadAssetServiceStatus();
|
||||
|
||||
string correlationId = Correlation(response);
|
||||
|
||||
WriteJson(response, new
|
||||
@@ -347,7 +356,7 @@ namespace NexVerse.Server.Api
|
||||
.Count()
|
||||
: (int?)null
|
||||
},
|
||||
detail_level = !gridUserAvailable
|
||||
detail_level = !gridUserAvailable || !regions.Available || assetStatus != "ok"
|
||||
? "partial"
|
||||
: includeProtectedDetails ? "authenticated" : "aggregate",
|
||||
protected_details = includeProtectedDetails,
|
||||
@@ -359,7 +368,35 @@ namespace NexVerse.Server.Api
|
||||
: Array.Empty<object>()
|
||||
},
|
||||
account_states = accountStates,
|
||||
regions = includeProtectedDetails
|
||||
// Grid region registration is public map metadata, not an
|
||||
// online-avatar breakdown. Include offline and reserved local
|
||||
// regions; never expose simulator internal endpoints or secrets.
|
||||
regions = regions.Rows,
|
||||
region_summary = new
|
||||
{
|
||||
registered_total = regions.Registered,
|
||||
online_total = regions.Online,
|
||||
offline_total = regions.Offline,
|
||||
reserved_total = regions.Reserved,
|
||||
hypergrid_links = regions.HypergridLinks,
|
||||
status_source = "GridStore RegionOnline flag (registration state, not an active network probe)"
|
||||
},
|
||||
services = new
|
||||
{
|
||||
grid = new
|
||||
{
|
||||
status = m_Grid == null
|
||||
? "unavailable"
|
||||
: regions.Available ? "ok" : "degraded",
|
||||
data_available = regions.Available
|
||||
},
|
||||
asset = new
|
||||
{
|
||||
status = assetStatus,
|
||||
probe = "read_only_missing_asset_existence_query"
|
||||
}
|
||||
},
|
||||
region_online_users = includeProtectedDetails
|
||||
? regionBreakdown
|
||||
: Array.Empty<object>(),
|
||||
hypergrid_home_grids = includeProtectedDetails
|
||||
@@ -367,11 +404,16 @@ namespace NexVerse.Server.Api
|
||||
: Array.Empty<object>(),
|
||||
data_quality = new
|
||||
{
|
||||
complete = gridUserAvailable && completeAccountEnumeration,
|
||||
complete = gridUserAvailable && completeAccountEnumeration && regions.Available && assetStatus == "ok",
|
||||
griduser_source = gridUserAvailable ? "available" : "unavailable",
|
||||
missing_metrics = gridUserAvailable
|
||||
region_source = regions.Available ? "GridStore" : "unavailable",
|
||||
asset_service_probe = assetStatus,
|
||||
missing_metrics = (gridUserAvailable
|
||||
? Array.Empty<string>()
|
||||
: new[] { "activity_history", "hypergrid_visitors", "hypergrid_online", "total_online" },
|
||||
: new[] { "activity_history", "hypergrid_visitors", "hypergrid_online", "total_online" })
|
||||
.Concat(regions.Available ? Array.Empty<string>() : new[] { "registered_regions", "online_regions" })
|
||||
.Concat(assetStatus == "ok" ? Array.Empty<string>() : new[] { "asset_service_health" })
|
||||
.ToArray(),
|
||||
registered_source =
|
||||
completeAccountEnumeration
|
||||
? "UserAccountService aggregate"
|
||||
@@ -393,6 +435,115 @@ namespace NexVerse.Server.Api
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Use the authoritative GridStore instead of deriving regions from
|
||||
// avatar presence: empty grids still have registered/offline regions.
|
||||
private RegionSnapshot ReadRegions()
|
||||
{
|
||||
if (m_RegionData == null)
|
||||
return new RegionSnapshot();
|
||||
|
||||
try
|
||||
{
|
||||
List<RegionData> rows = m_RegionData.Get("%", UUID.Zero);
|
||||
if (rows == null)
|
||||
return new RegionSnapshot();
|
||||
|
||||
RegionData[] distinct = rows
|
||||
.Where(x => x != null && !x.RegionID.IsZero())
|
||||
.GroupBy(x => x.RegionID)
|
||||
.Select(group => group.First())
|
||||
.OrderBy(x => x.RegionName, StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
|
||||
int online = 0, reserved = 0, links = 0;
|
||||
List<object> visible = new List<object>();
|
||||
foreach (RegionData region in distinct)
|
||||
{
|
||||
int flags = 0;
|
||||
if (region.Data != null &&
|
||||
region.Data.TryGetValue("flags", out object raw))
|
||||
int.TryParse(Convert.ToString(raw), out flags);
|
||||
|
||||
bool isLink =
|
||||
(flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0;
|
||||
if (isLink)
|
||||
{
|
||||
links++;
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isReserved =
|
||||
(flags & (int)OpenSim.Framework.RegionFlags.Reservation) != 0;
|
||||
bool isOnline = !isReserved &&
|
||||
(flags & (int)OpenSim.Framework.RegionFlags.RegionOnline) != 0;
|
||||
if (isReserved)
|
||||
reserved++;
|
||||
if (isOnline)
|
||||
online++;
|
||||
|
||||
visible.Add(new
|
||||
{
|
||||
region_id = region.RegionID.ToString(),
|
||||
region_name = region.RegionName ?? string.Empty,
|
||||
grid_x = region.posX / 256,
|
||||
grid_y = region.posY / 256,
|
||||
size_x = region.sizeX,
|
||||
size_y = region.sizeY,
|
||||
online = isOnline,
|
||||
status = isReserved ? "reserved" : isOnline ? "online" : "offline"
|
||||
});
|
||||
}
|
||||
|
||||
return new RegionSnapshot
|
||||
{
|
||||
Available = true,
|
||||
Registered = visible.Count,
|
||||
Online = online,
|
||||
Offline = visible.Count - online - reserved,
|
||||
Reserved = reserved,
|
||||
HypergridLinks = links,
|
||||
Rows = visible
|
||||
.ToArray()
|
||||
};
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_Log.Warn("[NEX-STATS]: GridStore region inventory unavailable; other statistics remain accessible.", e);
|
||||
return new RegionSnapshot();
|
||||
}
|
||||
}
|
||||
|
||||
// A read-only query for a known missing UUID tests the actual asset
|
||||
// datastore. A false existence result is SUCCESS; no asset is changed.
|
||||
private string ReadAssetServiceStatus()
|
||||
{
|
||||
if (m_Assets == null)
|
||||
return "unavailable";
|
||||
try
|
||||
{
|
||||
bool[] found = m_Assets.AssetsExist(
|
||||
new[] { UUID.Zero.ToString() });
|
||||
return found != null && found.Length == 1 ? "ok" : "degraded";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_Log.Warn("[NEX-STATS]: AssetService read-only health probe failed.", e);
|
||||
return "degraded";
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class RegionSnapshot
|
||||
{
|
||||
public bool Available;
|
||||
public int? Registered;
|
||||
public int? Online;
|
||||
public int? Offline;
|
||||
public int? Reserved;
|
||||
public int? HypergridLinks;
|
||||
public object[] Rows = Array.Empty<object>();
|
||||
}
|
||||
|
||||
private List<UserAccount> LoadAccounts(
|
||||
Dictionary<string, ActivityRecord> localActivity,
|
||||
out bool completeEnumeration)
|
||||
|
||||
@@ -84,7 +84,9 @@ namespace NexVerse.Server.Api
|
||||
LoadOptionalService<IPresenceService>(m_Config, "PresenceService"),
|
||||
LoadOptionalService<IGridService>(m_Config, "GridService"),
|
||||
null,
|
||||
true);
|
||||
true,
|
||||
LoadRegionData(m_Config),
|
||||
LoadOptionalService<IAssetService>(m_Config, "AssetService"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -914,7 +916,9 @@ namespace NexVerse.Server.Api
|
||||
presence,
|
||||
grid,
|
||||
authenticator,
|
||||
true);
|
||||
true,
|
||||
LoadRegionData(config),
|
||||
assets);
|
||||
|
||||
INexSecurityStore securityStore =
|
||||
new PersistentNexSecurityStore(
|
||||
@@ -1220,6 +1224,43 @@ namespace NexVerse.Server.Api
|
||||
return headers;
|
||||
}
|
||||
|
||||
// GridStore contains *all* locally registered regions, including
|
||||
// offline records. GridService.GetOnlineRegions alone is insufficient.
|
||||
private static IRegionData LoadRegionData(IConfigSource config)
|
||||
{
|
||||
IConfig database = config.Configs["DatabaseService"];
|
||||
IConfig grid = config.Configs["GridService"];
|
||||
string provider = grid?.GetString(
|
||||
"StorageProvider",
|
||||
database?.GetString("StorageProvider", string.Empty)) ??
|
||||
database?.GetString("StorageProvider", string.Empty) ?? string.Empty;
|
||||
string connection = grid?.GetString(
|
||||
"ConnectionString",
|
||||
database?.GetString("ConnectionString", string.Empty)) ??
|
||||
database?.GetString("ConnectionString", string.Empty) ?? string.Empty;
|
||||
string realm = grid?.GetString("Realm", "regions") ?? "regions";
|
||||
|
||||
if (string.IsNullOrWhiteSpace(provider))
|
||||
{
|
||||
m_Log.Warn("[NEX-WORLD-API]: GridStore statistics source has no StorageProvider.");
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return ServerUtils.LoadPlugin<IRegionData>(
|
||||
provider,
|
||||
new object[] { connection, realm });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_Log.WarnFormat(
|
||||
"[NEX-WORLD-API]: GridStore statistics source unavailable: {0}",
|
||||
e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static IGridUserData LoadGridUserData(IConfigSource config)
|
||||
{
|
||||
string dllName = string.Empty;
|
||||
|
||||
@@ -5397,11 +5397,11 @@ namespace NexVerse.Server.Api
|
||||
["StatisticsSummaryResponse"] = new
|
||||
{
|
||||
type = "object",
|
||||
required = new[] { "generated_at", "detail_level", "protected_details", "residents", "hypergrid", "online", "regions", "correlation_id" },
|
||||
required = new[] { "generated_at", "detail_level", "protected_details", "residents", "hypergrid", "online", "regions", "region_summary", "services", "correlation_id" },
|
||||
properties = new Dictionary<string, object>
|
||||
{
|
||||
["generated_at"] = new { type = "string", format = "date-time" },
|
||||
["detail_level"] = new { type = "string", @enum = new[] { "aggregate", "authenticated" } },
|
||||
["detail_level"] = new { type = "string", @enum = new[] { "aggregate", "authenticated", "partial" } },
|
||||
["protected_details"] = new { type = "boolean" },
|
||||
["residents"] = new
|
||||
{
|
||||
@@ -5446,7 +5446,51 @@ namespace NexVerse.Server.Api
|
||||
}
|
||||
}
|
||||
},
|
||||
["regions"] = new { type = "array", items = new { type = "object" } },
|
||||
["regions"] = new
|
||||
{
|
||||
type = "array",
|
||||
description = "All locally registered GridStore regions (online, offline and reserved), excluding Hypergrid links. No internal connection endpoints.",
|
||||
items = new
|
||||
{
|
||||
type = "object",
|
||||
properties = new Dictionary<string, object>
|
||||
{
|
||||
["region_id"] = new { type = "string", format = "uuid" },
|
||||
["region_name"] = new { type = "string" },
|
||||
["grid_x"] = new { type = "integer" },
|
||||
["grid_y"] = new { type = "integer" },
|
||||
["size_x"] = new { type = "integer" },
|
||||
["size_y"] = new { type = "integer" },
|
||||
["online"] = new { type = "boolean" },
|
||||
["status"] = new { type = "string", @enum = new[] { "online", "offline", "reserved" } }
|
||||
}
|
||||
}
|
||||
},
|
||||
["region_summary"] = new
|
||||
{
|
||||
type = "object",
|
||||
description = "GridStore RegionOnline flags represent registration state, not an independent live network probe.",
|
||||
properties = new Dictionary<string, object>
|
||||
{
|
||||
["registered_total"] = new { type = "integer", nullable = true },
|
||||
["online_total"] = new { type = "integer", nullable = true },
|
||||
["offline_total"] = new { type = "integer", nullable = true },
|
||||
["reserved_total"] = new { type = "integer", nullable = true },
|
||||
["hypergrid_links"] = new { type = "integer", nullable = true },
|
||||
["status_source"] = new { type = "string" }
|
||||
}
|
||||
},
|
||||
["services"] = new
|
||||
{
|
||||
type = "object",
|
||||
description = "Read-only GridStore and AssetService checks; ok / degraded / unavailable are not host-wide health guarantees.",
|
||||
properties = new Dictionary<string, object>
|
||||
{
|
||||
["grid"] = new { type = "object" },
|
||||
["asset"] = new { type = "object" }
|
||||
}
|
||||
},
|
||||
["region_online_users"] = new { type = "array", items = new { type = "object" } },
|
||||
["hypergrid_home_grids"] = new { type = "array", items = new { type = "object" } },
|
||||
["account_states"] = new { type = "object" },
|
||||
["data_quality"] = new { type = "object" },
|
||||
|
||||
@@ -73,7 +73,11 @@ These endpoints are public and read-only.
|
||||
|
||||
`GET /api/v1/statistics/summary` is registered independently of `EnablePrivilegedEndpoints`.
|
||||
|
||||
Without credentials, the endpoint returns a privacy-safe aggregate view when the configured account/GridUser data services are available. Aggregate mode contains headline counts such as registered residents, current total presence, recent activity and Hypergrid totals, but deliberately omits individual names, principal IDs, concrete online-region rows and Hypergrid home-grid detail lists.
|
||||
Without credentials, the endpoint returns resident/Hypergrid aggregates plus **all locally registered regions from authoritative GridStore** (including offline and reserved records). Public region metadata includes only region UUID, name, position, size and GridStore online flag; it never includes avatars, personal identities, estate owners, simulator connection endpoints or region secrets. Hypergrid link entries are counted separately and excluded from local region totals. The pre-existing avatar-based region online-population breakdown is available only as `region_online_users` with `statistics:read` authentication. Hypergrid home-grid identity details remain protected.
|
||||
|
||||
`region_summary` gives `registered_total`, `online_total`, `offline_total`, `reserved_total` and `hypergrid_links`. Count fields are `null` when GridStore cannot be read, rather than a misleading 0. `RegionOnline` reflects **GridService registration state**; it is not a separate live network heartbeat and may be stale after a sudden simulator crash. VAR regions count once by region UUID, not by their occupied 256m map cells.
|
||||
|
||||
`services.grid.status` and `services.asset.status` report `ok`, `degraded` or `unavailable`. Grid service `ok` requires the local GridService and successful GridStore inventory access. Asset service `ok` requires successful read-only `AssetsExist` datastore probing with a nonexistent UUID (both `true` and `false` are valid answers). These checks do not guarantee remote simulator reachability, upload success, disk space or end-to-end asset delivery. Probe failures leave the resident statistics available but set `data_quality.complete=false` and list missing metrics.
|
||||
|
||||
When privileged World API authentication is enabled, a Bearer token or `X-NexVerse-Api-Key` with `statistics:read` may request the protected detail view. Protected credentials must only be used over TLS or an equivalent trusted transport.
|
||||
|
||||
@@ -90,7 +94,7 @@ disappear as a 404 merely because privileged endpoints are disabled.
|
||||
|
||||
The response reports its effective privacy level through:
|
||||
|
||||
- `detail_level=aggregate|authenticated`
|
||||
- `detail_level=aggregate|authenticated|partial`
|
||||
- `protected_details=false|true`
|
||||
|
||||
## LunaTexture diagnostics projection
|
||||
|
||||
@@ -19,7 +19,7 @@ for marker in (
|
||||
'active_last_7_days = gridUserAvailable',
|
||||
'online_now = gridUserAvailable ? hypergridOnline.Count : (int?)null',
|
||||
'total = gridUserAvailable ? allOnline.Count : (int?)null',
|
||||
'missing_metrics = gridUserAvailable',
|
||||
'missing_metrics = (gridUserAvailable',
|
||||
'griduser_source = gridUserAvailable ? "available" : "unavailable"',
|
||||
'complete = gridUserAvailable && completeAccountEnumeration',
|
||||
):
|
||||
@@ -43,4 +43,44 @@ assert "$('apiKey').value.trim()" not in start, "Unrelated explorer API key must
|
||||
assert "Teilweise (Datenquelle fehlt)" in start
|
||||
assert "feh" in ui
|
||||
|
||||
# The public region inventory must enumerate GridStore rows even with no online
|
||||
# avatars; do not fall back to the avatar-derived region breakdown.
|
||||
for marker in (
|
||||
"IRegionData m_RegionData",
|
||||
"IAssetService m_Assets",
|
||||
'm_RegionData.Get("%", UUID.Zero)',
|
||||
"GroupBy(x => x.RegionID)",
|
||||
"RegionFlags.Hyperlink",
|
||||
"RegionFlags.Reservation",
|
||||
"RegionFlags.RegionOnline",
|
||||
"region_summary = new",
|
||||
"registered_total = regions.Registered",
|
||||
"online_total = regions.Online",
|
||||
"offline_total = regions.Offline",
|
||||
"regions = regions.Rows",
|
||||
"services = new",
|
||||
"ReadAssetServiceStatus()",
|
||||
"m_Assets.AssetsExist(",
|
||||
"region_source = regions.Available",
|
||||
"asset_service_probe = assetStatus",
|
||||
"region_online_users = includeProtectedDetails",
|
||||
):
|
||||
assert marker in stats, "World regions and service health contract missing: " + marker
|
||||
|
||||
for marker in (
|
||||
"LoadRegionData(m_Config)",
|
||||
"LoadRegionData(config)",
|
||||
'LoadOptionalService<IAssetService>(m_Config, "AssetService")',
|
||||
"return ServerUtils.LoadPlugin<IRegionData>(",
|
||||
'grid?.GetString("Realm", "regions")',
|
||||
):
|
||||
assert marker in routes, "GridStore/AssetService load contract missing: " + marker
|
||||
|
||||
# Verify public region detail does not accidentally publish simulator internal
|
||||
# endpoints, database connection strings, owner data, tokens or secrets.
|
||||
public_regions = stats.split("private RegionSnapshot ReadRegions()", 1)[1].split("private string ReadAssetServiceStatus()", 1)[0]
|
||||
for disallowed in ("ServerURI", "ExternalHostName", "RegionSecret", ".Token", "connectionString", "EstateOwner"):
|
||||
assert disallowed not in public_regions, "Sensitive region field exposed: " + disallowed
|
||||
|
||||
|
||||
print("OGL statistics partial-data and public aggregate routing: PASS")
|
||||
Reference in new issue
Block a user