Skip to content

Commit 44ada74

Browse files
insight-bitclaude
andcommitted
refactor: rename FC3 to FC throughout codebase
- Rename fc3.py to fc.py, FC3Deployment to FCDeployment - Rename fc3_rocklet/ to fc_rocklet/ - Update all FC3/FC3 references to FC in comments and strings - Remove FC3DeploymentConfig backward compatibility alias - Remove auto_clear_time property (use sandbox_ttl directly) - Fix async methods in tests (is_session_alive, get_session_stats) - Update test fixtures to include region and function_name FC (Function Compute) is Alibaba Cloud serverless compute service. The naming is simplified from FC3 to FC for clarity. Change-Id: I4053ac81b47f818cd8644a013857e99415fb9168 Co-developed-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6efd297 commit 44ada74

File tree

22 files changed

+777
-508
lines changed

22 files changed

+777
-508
lines changed

rock-conf/rock-fc.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# =============================================================================
2+
# ROCK Admin 运行时配置 - FC 环境
3+
# =============================================================================
4+
#
5+
# 用途:ROCK Admin 服务启动时加载的运行时配置
6+
#
7+
# 使用方式:
8+
# rock admin start --env fc
9+
# 或 export ROCK_CONFIG=rock-conf/rock-fc.yml
10+
#
11+
# 注意:此文件不是函数部署配置,FC 函数部署使用
12+
# rock/deployments/fc_rocklet/*/s.yaml + s deploy
13+
#
14+
# =============================================================================
15+
#
16+
# 配置层级说明:
17+
#
18+
# ┌─────────────────────────────────────────────────────────────────────┐
19+
# │ FCConfig (Admin 服务级) - 本文件 │
20+
# │ - Admin 启动时加载,提供默认值和凭证 │
21+
# │ - 服务级设置 (region, account_id, credentials) │
22+
# └─────────────────────────────────────────────────────────────────────┘
23+
#
24+
# │ merge_with_fc_config()
25+
#
26+
# ┌─────────────────────────────────────────────────────────────────────┐
27+
# │ FCDeploymentConfig (API 调用级) │
28+
# │ - 每个 sandbox API 请求创建 │
29+
# │ - 可覆盖特定字段 (memory, cpus, timeout 等) │
30+
# │ - session_id 与 ROCK sandbox_id 1:1 映射 │
31+
# └─────────────────────────────────────────────────────────────────────┘
32+
#
33+
# │ 用于调用 FC 函数
34+
#
35+
# ┌─────────────────────────────────────────────────────────────────────┐
36+
# │ s.yaml (FC 函数部署配置) │
37+
# │ - 定义 FC 函数资源规格 │
38+
# │ - Session affinity, memory, CPU, timeout 等 │
39+
# │ - 通过 `s deploy` 命令部署 │
40+
# │ - 位置: rock/deployments/fc_rocklet/{runtime,container,adapter}/ │
41+
# └─────────────────────────────────────────────────────────────────────┘
42+
#
43+
# =============================================================================
44+
45+
# Ray 配置(FC 环境不使用 Ray 进行沙箱调度,但可用于其他分布式任务)
46+
ray:
47+
runtime_env:
48+
working_dir: ./
49+
pip: ./requirements_sandbox_actor.txt
50+
namespace: "rock-sandbox-fc"
51+
52+
# FC 配置(阿里云函数计算服务级别配置)
53+
# FC (Function Compute) 是阿里云的无服务器计算服务
54+
fc:
55+
# 连接设置
56+
region: "cn-hangzhou"
57+
account_id: null # 阿里云账号 ID,运行时从环境变量或 STS 获取
58+
function_name: "rock-rocklet-rt" # 沙箱运行时函数名
59+
60+
# 凭证(建议通过环境变量或 STS 临时凭证提供)
61+
# access_key_id: null
62+
# access_key_secret: null
63+
# security_token: null
64+
65+
# 资源默认值(可被 API 调用覆盖)
66+
default_memory: 4096 # MB
67+
default_cpus: 2.0
68+
69+
# 超时默认值(单位:秒)
70+
default_session_ttl: 600 # 会话生命周期(秒),对应 s.yaml 中的 sessionTTLInSeconds
71+
default_timeout: 30.0 # API 请求超时(秒)
72+
default_session_idle_timeout: 60 # 会话空闲超时(秒),对应 s.yaml 中的 sessionIdleTimeoutInSeconds
73+
74+
# 协议设置
75+
session_affinity_header: "x-rock-session-id"
76+
77+
# 预热配置(FC 环境无本地镜像需预热)
78+
warmup:
79+
images: []

rock-conf/rock-fc3.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

rock/config.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,83 @@ class OssConfig:
6262
role_arn: str = ""
6363

6464

65+
@dataclass
66+
class FCConfig:
67+
"""FC (Function Compute) 服务级配置,用于 Admin。
68+
69+
提供 FC 沙箱部署的默认值和凭证。
70+
API 调用可通过 FCDeploymentConfig 覆盖特定字段。
71+
72+
FC (Function Compute) 是阿里云的无服务器计算服务:
73+
https://www.alibabacloud.com/product/function-compute
74+
75+
配置层级:
76+
┌─────────────────────────────────────────────────────────────────────┐
77+
│ FCConfig (Admin 服务级) - 本文件 │
78+
│ - Admin 启动时加载,提供默认值和凭证 │
79+
│ - 服务级设置 (region, account_id, credentials) │
80+
└─────────────────────────────────────────────────────────────────────┘
81+
82+
│ merge_with_fc_config()
83+
84+
┌─────────────────────────────────────────────────────────────────────┐
85+
│ FCDeploymentConfig (API 调用级) │
86+
│ - 每个 sandbox API 请求创建 │
87+
│ - session_id 与 ROCK sandbox_id 1:1 映射 │
88+
│ - 用于调用已部署的 FC 函数,不涉及函数部署 │
89+
└─────────────────────────────────────────────────────────────────────┘
90+
91+
│ 调用已部署的 FC 函数
92+
93+
┌─────────────────────────────────────────────────────────────────────┐
94+
│ s.yaml (FC 函数部署配置) │
95+
│ - 定义 FC 函数资源规格,通过 `s deploy` 部署 │
96+
│ - 函数部署是前置条件,Admin 调用时函数已存在 │
97+
└─────────────────────────────────────────────────────────────────────┘
98+
"""
99+
100+
# Connection settings (service-level defaults)
101+
region: str = "cn-hangzhou"
102+
"""Alibaba Cloud region for FC function."""
103+
104+
account_id: str | None = None
105+
"""Alibaba Cloud account ID."""
106+
107+
function_name: str = "rock-rocklet-rt"
108+
"""Default FC function name for sandbox runtime."""
109+
110+
# Credentials (service-level, sensitive)
111+
access_key_id: str | None = None
112+
"""Alibaba Cloud AccessKey ID for authentication."""
113+
114+
access_key_secret: str = field(default="", repr=False)
115+
"""Alibaba Cloud AccessKey Secret for authentication."""
116+
117+
security_token: str | None = None
118+
"""Alibaba Cloud STS security token for temporary credentials."""
119+
120+
# Resource defaults (can be overridden by API)
121+
default_memory: int = 4096
122+
"""Default memory allocation in MB for FC function."""
123+
124+
default_cpus: float = 2.0
125+
"""Default CPU cores for FC function."""
126+
127+
# Timeout defaults (can be overridden by API, all in seconds)
128+
default_session_ttl: int = 600
129+
"""Default session time-to-live in seconds for sandbox auto-cleanup."""
130+
131+
default_timeout: float = 30.0
132+
"""Default request timeout in seconds for FC API calls."""
133+
134+
default_session_idle_timeout: int = 60
135+
"""Default session idle timeout in seconds. Matches s.yaml sessionIdleTimeoutInSeconds."""
136+
137+
# Protocol settings (service-level fixed)
138+
session_affinity_header: str = "x-rock-session-id"
139+
"""Header field name for session affinity routing."""
140+
141+
65142
@dataclass
66143
class ProxyServiceConfig:
67144
timeout: float = 180.0
@@ -200,6 +277,7 @@ class RockConfig:
200277
redis: RedisConfig = field(default_factory=RedisConfig)
201278
sandbox_config: SandboxConfig = field(default_factory=SandboxConfig)
202279
oss: OssConfig = field(default_factory=OssConfig)
280+
fc: FCConfig = field(default_factory=FCConfig)
203281
runtime: RuntimeConfig = field(default_factory=RuntimeConfig)
204282
proxy_service: ProxyServiceConfig = field(default_factory=ProxyServiceConfig)
205283
scheduler: SchedulerConfig = field(default_factory=SchedulerConfig)
@@ -238,6 +316,8 @@ def from_env(cls, config_path: str | None = None):
238316
kwargs["sandbox_config"] = SandboxConfig(**config["sandbox_config"])
239317
if "oss" in config:
240318
kwargs["oss"] = OssConfig(**config["oss"])
319+
if "fc" in config:
320+
kwargs["fc"] = FCConfig(**config["fc"])
241321
if "runtime" in config:
242322
kwargs["runtime"] = RuntimeConfig(**config["runtime"])
243323
if "proxy_service" in config:

rock/deployments/config.py

Lines changed: 97 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -214,58 +214,126 @@ def get_deployment(self) -> AbstractDeployment:
214214
return RemoteDeployment.from_config(self)
215215

216216

217-
class FC3DeploymentConfig(DeploymentConfig):
218-
"""Configuration for Alibaba Cloud Function Compute 3.0 deployment.
217+
class FCDeploymentConfig(DeploymentConfig):
218+
"""Configuration for Alibaba Cloud Function Compute deployment.
219219
220-
This deployment type enables serverless sandbox execution using FC3
220+
This deployment type enables serverless sandbox execution using FC
221221
with WebSocket session management for stateful operations.
222+
223+
FC (Function Compute) is Alibaba Cloud's serverless compute service:
224+
https://www.alibabacloud.com/product/function-compute
225+
226+
Configuration Hierarchy:
227+
┌─────────────────────────────────────────────────────────────────────┐
228+
│ FCConfig (Admin 服务级) - 本文件 │
229+
│ - Admin 启动时加载,提供默认值和凭证 │
230+
│ - 服务级设置 (region, account_id, credentials) │
231+
└─────────────────────────────────────────────────────────────────────┘
232+
233+
│ merge_with_fc_config()
234+
235+
┌─────────────────────────────────────────────────────────────────────┐
236+
│ FCDeploymentConfig (API 调用级) │
237+
│ - 每个 sandbox API 请求创建 │
238+
│ - session_id 与 ROCK sandbox_id 1:1 映射 │
239+
│ - 用于调用已部署的 FC 函数,不涉及函数部署 │
240+
│ - sandbox_ttl/sandbox_idle_timeout: ROCK 内部沙箱生命周期管理 │
241+
└─────────────────────────────────────────────────────────────────────┘
242+
243+
│ 调用已部署的 FC 函数
244+
245+
┌─────────────────────────────────────────────────────────────────────┐
246+
│ s.yaml (FC 函数部署配置) │
247+
│ - 定义 FC 函数资源规格,通过 `s deploy` 部署 │
248+
│ - Session affinity, memory, CPU, timeout 等 │
249+
│ - 位置: rock/deployments/fc_rocklet/{runtime,container,adapter}/ │
250+
│ - 函数部署是前置条件,Admin 调用时函数已存在 │
251+
└─────────────────────────────────────────────────────────────────────┘
252+
253+
The session_id serves as both the FC session identifier (for WebSocket
254+
stateful invocation routing) and the ROCK sandbox_id (for business logic).
222255
"""
223256

224-
type: Literal["fc3"] = "fc3"
225-
"""Deployment type discriminator."""
257+
type: Literal["fc"] = "fc"
258+
"""Deployment type discriminator for JSON/YAML parsing."""
259+
260+
session_id: str | None = None
261+
"""FC session identifier for stateful invocation routing.
262+
263+
This serves as both:
264+
- FC native session_id: Routes WebSocket requests to the same function instance
265+
- ROCK sandbox_id: Used for lifecycle management, billing, and state tracking
226266
227-
function_name: str = "rock-rocklet-rt"
228-
"""FC3 function name for the sandbox runtime."""
267+
If None, will be auto-generated as 'fc-{uuid}'.
268+
"""
269+
270+
# Connection settings (optional, use FCConfig defaults if not provided)
271+
function_name: str | None = None
272+
"""FC function name. If None, uses FCConfig.function_name."""
229273

230-
region: str = "cn-hangzhou"
231-
"""Alibaba Cloud region for the FC3 function."""
274+
region: str | None = None
275+
"""Alibaba Cloud region. If None, uses FCConfig.region."""
232276

233277
account_id: str | None = None
234-
"""Alibaba Cloud account ID."""
278+
"""Alibaba Cloud account ID. If None, uses FCConfig.account_id."""
235279

236280
access_key_id: str | None = None
237-
"""Alibaba Cloud AccessKey ID for authentication."""
281+
"""AccessKey ID. If None, uses FCConfig.access_key_id."""
238282

239283
access_key_secret: str | None = Field(default=None, repr=False, exclude=True)
240-
"""Alibaba Cloud AccessKey Secret for authentication."""
284+
"""AccessKey Secret. If None, uses FCConfig.access_key_secret."""
241285

242286
security_token: str | None = None
243-
"""Alibaba Cloud STS security token for temporary credentials."""
287+
"""STS security token. If None, uses FCConfig.security_token."""
244288

245-
memory: int = 4096
246-
"""Memory allocation in MB for the FC3 function."""
289+
# Resource settings (optional, use FCConfig defaults if not provided)
290+
memory: int | None = None
291+
"""Memory in MB. If None, uses FCConfig.default_memory."""
247292

248-
cpus: float = 2.0
249-
"""CPU cores allocated for the FC3 function."""
293+
cpus: float | None = None
294+
"""CPU cores. If None, uses FCConfig.default_cpus."""
250295

251-
session_affinity_header: str = "x-rock-session-id"
252-
"""Header field name for session affinity."""
296+
# Timeout settings (optional, use FCConfig defaults if not provided, all in seconds)
297+
sandbox_ttl: int | None = None
298+
"""Sandbox time-to-live in seconds. If None, uses FCConfig.default_session_ttl."""
253299

254-
sandbox_ttl_minutes: int = 10
255-
"""Time-to-live in minutes for sandbox auto-cleanup."""
300+
sandbox_idle_timeout: int | None = None
301+
"""Sandbox idle timeout in seconds. If None, uses FCConfig.default_session_idle_timeout."""
256302

257-
timeout: float = 30.0
258-
"""Request timeout in seconds for FC3 API calls."""
303+
timeout: float | None = None
304+
"""Request timeout in seconds. If None, uses FCConfig.default_timeout."""
259305

260306
def get_deployment(self) -> AbstractDeployment:
261-
from rock.deployments.fc3 import FC3Deployment
307+
from rock.deployments.fc import FCDeployment
262308

263-
return FC3Deployment.from_config(self)
309+
return FCDeployment.from_config(self)
264310

265-
@property
266-
def auto_clear_time(self) -> int:
267-
"""Alias for sandbox_ttl_minutes for compatibility."""
268-
return self.sandbox_ttl_minutes
311+
def merge_with_fc_config(self, fc_config: "FCConfig") -> "FCDeploymentConfig":
312+
"""Merge this config with FCConfig defaults.
313+
314+
Args:
315+
fc_config: Admin-level FC configuration with defaults.
316+
317+
Returns:
318+
New FCDeploymentConfig with all fields populated.
319+
"""
320+
from rock.config import FCConfig
321+
322+
return FCDeploymentConfig(
323+
type=self.type,
324+
session_id=self.session_id,
325+
function_name=self.function_name or fc_config.function_name,
326+
region=self.region or fc_config.region,
327+
account_id=self.account_id or fc_config.account_id,
328+
access_key_id=self.access_key_id or fc_config.access_key_id,
329+
access_key_secret=self.access_key_secret or fc_config.access_key_secret,
330+
security_token=self.security_token or fc_config.security_token,
331+
memory=self.memory or fc_config.default_memory,
332+
cpus=self.cpus or fc_config.default_cpus,
333+
sandbox_ttl=self.sandbox_ttl or fc_config.default_session_ttl,
334+
sandbox_idle_timeout=self.sandbox_idle_timeout or fc_config.default_session_idle_timeout,
335+
timeout=self.timeout or fc_config.default_timeout,
336+
)
269337

270338

271339
def get_deployment(config: DeploymentConfig) -> AbstractDeployment:

0 commit comments

Comments
 (0)