feat: add workbench redis cache runtime config
This commit is contained in:
@@ -938,7 +938,8 @@ function deployServicesForProfile(deploy, profile) {
|
||||
copy.env = mergeEnvMaps(
|
||||
copy.env,
|
||||
serviceDeclarationEnvForProfile(deploy, profile, service.serviceId),
|
||||
runtimeStoreEnvForProfile(deploy, profile, service.serviceId)
|
||||
runtimeStoreEnvForProfile(deploy, profile, service.serviceId),
|
||||
workbenchRuntimeRedisEnvForProfile(deploy, profile, service.serviceId)
|
||||
);
|
||||
return [service.serviceId, copy];
|
||||
}));
|
||||
@@ -950,7 +951,8 @@ function deployServicesForProfile(deploy, profile) {
|
||||
serviceId: override.serviceId,
|
||||
env: mergeEnvMaps(
|
||||
serviceDeclarationEnvForProfile(deploy, profile, override.serviceId),
|
||||
runtimeStoreEnvForProfile(deploy, profile, override.serviceId)
|
||||
runtimeStoreEnvForProfile(deploy, profile, override.serviceId),
|
||||
workbenchRuntimeRedisEnvForProfile(deploy, profile, override.serviceId)
|
||||
)
|
||||
};
|
||||
services.set(override.serviceId, {
|
||||
@@ -1006,6 +1008,47 @@ function runtimeStoreEnvForProfile(deploy, profile, serviceId) {
|
||||
return env;
|
||||
}
|
||||
|
||||
function workbenchRuntimeRedisEnvForProfile(deploy, profile, serviceId) {
|
||||
if (!isRuntimeLane(profile) || serviceId !== "hwlab-workbench-runtime") return {};
|
||||
const redis = runtimeLaneConfig(deploy, profile)?.workbenchRuntime?.cache?.redis;
|
||||
if (!redis || typeof redis !== "object" || Array.isArray(redis)) return {};
|
||||
const env = {
|
||||
HWLAB_WORKBENCH_CACHE_REDIS_ENABLED: booleanEnv(Boolean(redis.enabled))
|
||||
};
|
||||
const namespace = typeof redis.namespace === "string" ? redis.namespace.trim() : "";
|
||||
const serviceName = typeof redis.serviceName === "string" ? redis.serviceName.trim() : "";
|
||||
const port = Number.isInteger(redis.port) ? redis.port : null;
|
||||
if (namespace) env.HWLAB_WORKBENCH_CACHE_REDIS_NAMESPACE = namespace;
|
||||
if (serviceName) env.HWLAB_WORKBENCH_CACHE_REDIS_SERVICE_NAME = serviceName;
|
||||
if (port !== null) env.HWLAB_WORKBENCH_CACHE_REDIS_PORT = String(port);
|
||||
if (namespace && serviceName && port !== null) {
|
||||
env.HWLAB_WORKBENCH_CACHE_REDIS_URL = `redis://${serviceName}.${namespace}.svc.cluster.local:${port}/0`;
|
||||
}
|
||||
const ttl = redis.ttl ?? {};
|
||||
if (Number.isInteger(ttl.sessionsSummaryMs)) env.HWLAB_WORKBENCH_CACHE_REDIS_TTL_SESSIONS_SUMMARY_MS = String(ttl.sessionsSummaryMs);
|
||||
if (Number.isInteger(ttl.terminalTurnMs)) env.HWLAB_WORKBENCH_CACHE_REDIS_TTL_TERMINAL_TURN_MS = String(ttl.terminalTurnMs);
|
||||
if (Number.isInteger(ttl.terminalTracePageMs)) env.HWLAB_WORKBENCH_CACHE_REDIS_TTL_TERMINAL_TRACE_PAGE_MS = String(ttl.terminalTracePageMs);
|
||||
if (Number.isInteger(ttl.runningPageMs)) env.HWLAB_WORKBENCH_CACHE_REDIS_TTL_RUNNING_PAGE_MS = String(ttl.runningPageMs);
|
||||
const limits = redis.limits ?? {};
|
||||
if (Number.isInteger(limits.maxKeyBytes)) env.HWLAB_WORKBENCH_CACHE_REDIS_MAX_KEY_BYTES = String(limits.maxKeyBytes);
|
||||
if (Number.isInteger(limits.maxPayloadBytes)) env.HWLAB_WORKBENCH_CACHE_REDIS_MAX_PAYLOAD_BYTES = String(limits.maxPayloadBytes);
|
||||
const timeouts = redis.timeouts ?? {};
|
||||
if (Number.isInteger(timeouts.connectMs)) env.HWLAB_WORKBENCH_CACHE_REDIS_CONNECT_TIMEOUT_MS = String(timeouts.connectMs);
|
||||
if (Number.isInteger(timeouts.operationMs)) env.HWLAB_WORKBENCH_CACHE_REDIS_OPERATION_TIMEOUT_MS = String(timeouts.operationMs);
|
||||
const labels = redis.metrics?.labels;
|
||||
if (labels && typeof labels === "object" && !Array.isArray(labels)) {
|
||||
env.HWLAB_WORKBENCH_CACHE_REDIS_METRICS_LABELS = JSON.stringify(labels);
|
||||
}
|
||||
const behavior = redis.unavailableBehavior ?? {};
|
||||
if (typeof behavior.livenessFailure === "boolean") env.HWLAB_WORKBENCH_CACHE_REDIS_UNAVAILABLE_LIVENESS_FAILURE = booleanEnv(behavior.livenessFailure);
|
||||
if (typeof behavior.readMode === "string") env.HWLAB_WORKBENCH_CACHE_REDIS_UNAVAILABLE_READ_MODE = behavior.readMode;
|
||||
if (typeof behavior.fallbackStateSource === "boolean") env.HWLAB_WORKBENCH_CACHE_REDIS_UNAVAILABLE_FALLBACK_STATE_SOURCE = booleanEnv(behavior.fallbackStateSource);
|
||||
if (typeof redis.disableSwitchEnv === "string" && redis.disableSwitchEnv.trim()) {
|
||||
env[redis.disableSwitchEnv.trim()] = booleanEnv(Boolean(redis.enabled));
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
function booleanEnv(value) {
|
||||
return value ? "1" : "0";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user