-
Notifications
You must be signed in to change notification settings - Fork 83
feat(api): Add docker compose service for API server. #1575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the main function seems a bit long now. would extracting helpers improve readability? e.g., |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| from typing import Any, Optional | ||
|
|
||
| from clp_py_utils.clp_config import ( | ||
| API_SERVER_COMPONENT_NAME, | ||
| AwsAuthType, | ||
| CLPConfig, | ||
| COMPRESSION_JOBS_TABLE_NAME, | ||
|
|
@@ -619,6 +620,30 @@ def _set_up_env_for_garbage_collector(self) -> EnvVarsDict: | |
|
|
||
| return env_vars | ||
|
|
||
| def _set_up_env_for_api_server(self) -> EnvVarsDict: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry for not starting the discussion before you implement - since both the MCP server and the garbage collector are optionally launched, we previously list them after the "always" launched services. (that - skipping the query services when Presto is enabled - is tricky but another story) can we list the api-server before the webui? ditto in other files |
||
| """ | ||
| Sets up environment variables and directories for the API server component. | ||
| :return: Dictionary of environment variables necessary to launch the component. | ||
| """ | ||
| component_name = API_SERVER_COMPONENT_NAME | ||
|
|
||
| logger.info(f"Setting up environment for {component_name}...") | ||
|
|
||
| logs_dir = self._clp_config.logs_directory / component_name | ||
| resolved_logs_dir = resolve_host_path_in_container(logs_dir) | ||
| resolved_logs_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| env_vars = EnvVarsDict() | ||
|
|
||
| # Connection config | ||
| env_vars |= { | ||
| "CLP_API_SERVER_HOST": _get_ip_from_hostname(self._clp_config.api_server.host), | ||
| "CLP_API_SERVER_PORT": str(self._clp_config.api_server.port), | ||
| } | ||
|
|
||
| return env_vars | ||
|
|
||
| def _read_and_update_settings_json( | ||
| self, settings_file_path: pathlib.Path, updates: dict[str, Any] | ||
| ) -> dict[str, Any]: | ||
|
|
@@ -747,6 +772,7 @@ def set_up_env(self) -> None: | |
| env_vars |= self._set_up_env_for_webui(container_clp_config) | ||
| env_vars |= self._set_up_env_for_mcp_server() | ||
| env_vars |= self._set_up_env_for_garbage_collector() | ||
| env_vars |= self._set_up_env_for_api_server() | ||
|
|
||
| # Write the environment variables to the `.env` file. | ||
| with open(f"{self._clp_home}/.env", "w") as env_file: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |||||||||
| WEBUI_COMPONENT_NAME = "webui" | ||||||||||
| MCP_SERVER_COMPONENT_NAME = "mcp_server" | ||||||||||
| GARBAGE_COLLECTOR_COMPONENT_NAME = "garbage_collector" | ||||||||||
| API_SERVER_COMPONENT_NAME = "api_server" | ||||||||||
|
|
||||||||||
| # Action names | ||||||||||
| ARCHIVE_MANAGER_ACTION_NAME = "archive_manager" | ||||||||||
|
|
@@ -592,6 +593,19 @@ class GarbageCollector(BaseModel): | |||||||||
| sweep_interval: SweepInterval = SweepInterval() | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class QueryJobPollingConfig(BaseModel): | ||||||||||
| initial_backoff_ms: int = Field(default=100, alias="initial_backoff") | ||||||||||
|
|
||||||||||
| max_backoff_ms: int = Field(default=5000, alias="max_backoff") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class ApiServer(BaseModel): | ||||||||||
| host: str = "localhost" | ||||||||||
| port: int = 3001 | ||||||||||
|
Comment on lines
+603
to
+604
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| query_job_polling: QueryJobPollingConfig = QueryJobPollingConfig() | ||||||||||
| default_max_num_query_results: int = 1000 | ||||||||||
|
|
||||||||||
|
Comment on lines
+602
to
+607
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Consider adding consistency features to align with other component classes. The
Additionally, Apply this diff to add consistency: class ApiServer(BaseModel):
- host: str = "localhost"
- port: int = 3001
+ DEFAULT_PORT: ClassVar[int] = 3001
+
+ host: DomainStr = "localhost"
+ port: Port = DEFAULT_PORT
query_job_polling: QueryJobPollingConfig = QueryJobPollingConfig()
default_max_num_query_results: int = 1000
+
+ def transform_for_container(self):
+ self.host = API_SERVER_COMPONENT_NAME
+ self.port = self.DEFAULT_PORTThen add this line in self.reducer.transform_for_container()
+ # Note: API server doesn't need container transformation as it's not accessed from other containers🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont think the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @junhaoliao, that's a valid point! If the API server is only accessed from the host and not by other containerized services, then Would you still like to apply the other consistency improvements for type safety and clarity?
These would make the ✏️ Learnings added
🧠 Learnings used |
||||||||||
|
|
||||||||||
| class Presto(BaseModel): | ||||||||||
| DEFAULT_PORT: ClassVar[int] = 8080 | ||||||||||
|
|
||||||||||
|
|
@@ -627,6 +641,7 @@ class CLPConfig(BaseModel): | |||||||||
| query_worker: QueryWorker = QueryWorker() | ||||||||||
| webui: WebUi = WebUi() | ||||||||||
| garbage_collector: GarbageCollector = GarbageCollector() | ||||||||||
| api_server: ApiServer = ApiServer() | ||||||||||
| credentials_file_path: SerializablePath = CLP_DEFAULT_CREDENTIALS_FILE_PATH | ||||||||||
|
|
||||||||||
| mcp_server: Optional[McpServer] = None | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,6 +30,7 @@ vars: | |||||||||||||||||
| G_PYTHON_LIBS_DIR: "{{.G_BUILD_DIR}}/python-libs" | ||||||||||||||||||
| G_WEBUI_BUILD_DIR: "{{.G_BUILD_DIR}}/webui" | ||||||||||||||||||
| G_SPIDER_BUILD_DIR: "{{.G_BUILD_DIR}}/spider" | ||||||||||||||||||
| G_RUST_BUILD_DIR: "{{.G_BUILD_DIR}}/rust" | ||||||||||||||||||
|
Comment on lines
32
to
+33
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these two seem not alphabetized |
||||||||||||||||||
|
|
||||||||||||||||||
| # Taskfile paths | ||||||||||||||||||
| G_UTILS_TASKFILE: "{{.ROOT_DIR}}/tools/yscope-dev-utils/exports/taskfiles/utils/utils.yaml" | ||||||||||||||||||
|
|
@@ -73,6 +74,7 @@ tasks: | |||||||||||||||||
| vars: | ||||||||||||||||||
| COMPONENT: "job-orchestration" | ||||||||||||||||||
| - task: "clean-webui" | ||||||||||||||||||
| - task: "clean-rust" | ||||||||||||||||||
|
Comment on lines
76
to
+77
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| - task: "tests:integration:cache-clear" | ||||||||||||||||||
|
|
||||||||||||||||||
| clean-core: | ||||||||||||||||||
|
|
@@ -103,6 +105,10 @@ tasks: | |||||||||||||||||
| - "rm -rf '{{.G_WEBUI_SRC_DIR}}/server/node_modules'" | ||||||||||||||||||
| - "rm -rf '{{.G_WEBUI_SRC_DIR}}/yscope-log-viewer/node_modules'" | ||||||||||||||||||
|
|
||||||||||||||||||
| clean-rust: | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't remember why we placed the |
||||||||||||||||||
| cmds: | ||||||||||||||||||
| - "rm -rf '{{.G_RUST_BUILD_DIR}}'" | ||||||||||||||||||
|
|
||||||||||||||||||
| package: | ||||||||||||||||||
| vars: | ||||||||||||||||||
| CHECKSUM_FILE: "{{.G_PACKAGE_CHECKSUM_FILE}}" | ||||||||||||||||||
|
|
@@ -191,6 +197,13 @@ tasks: | |||||||||||||||||
| JOBS: "{{.G_CPP_MAX_PARALLELISM_PER_BUILD_TASK}}" | ||||||||||||||||||
| TARGETS: ["clg", "clo", "clp", "clp-s", "indexer", "log-converter", "reducer-server"] | ||||||||||||||||||
|
|
||||||||||||||||||
| rust: | ||||||||||||||||||
| deps: ["toolchains:rust"] | ||||||||||||||||||
| dir: "{{.ROOT_DIR}}" | ||||||||||||||||||
| cmd: |- | ||||||||||||||||||
| . "$HOME/.cargo/env" | ||||||||||||||||||
| cargo build --release --bins --target-dir {{.G_RUST_BUILD_DIR}} | ||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cargo does an excellent job in detecting changes in both sources and output binary. We don't need to do checksum here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we also document this inline for future developers?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to to make sure the cargo binary is available in the build environment? |
||||||||||||||||||
|
|
||||||||||||||||||
| clp-mcp-server: | ||||||||||||||||||
| - task: "uv-component" | ||||||||||||||||||
| vars: | ||||||||||||||||||
|
|
@@ -218,6 +231,7 @@ tasks: | |||||||||||||||||
| - "init" | ||||||||||||||||||
| - "python-libs" | ||||||||||||||||||
| - "webui" | ||||||||||||||||||
| - "rust" | ||||||||||||||||||
|
Comment on lines
235
to
+238
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| webui: | ||||||||||||||||||
| env: | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -486,3 +486,30 @@ services: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "-f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "http://mcp_server:8000/health" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| api-server: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's also update |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <<: *service_defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hostname: "api_server" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| environment: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CLP_LOGS_DIR: "/var/log/api_server" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CLP_DB_PASS: "${CLP_DB_PASS:?Please set a value.}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CLP_DB_USER: "${CLP_DB_USER:?Please set a value.}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RUST_LOG: "TRACE" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ports: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - host_ip: "${CLP_API_SERVER_HOST:-127.0.0.1}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| published: "${CLP_API_SERVER_PORT:-3001}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target: 3001 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| volumes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - *volume_clp_config_readonly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - *volume_clp_logs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| depends_on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| db-table-creator: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| condition: "service_completed_successfully" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| results-cache-indices-creator: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| condition: "service_completed_successfully" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| command: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "/opt/clp/bin/api_server", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--host", "0.0.0.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--port", "3001", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--config", "/etc/clp-config.yml" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+490
to
+515
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider making RUST_LOG level configurable. The API server service configuration looks well-structured and follows the established patterns. However, Consider making this configurable like other services: environment:
CLP_LOGS_DIR: "/var/log/api_server"
CLP_DB_PASS: "${CLP_DB_PASS:?Please set a value.}"
CLP_DB_USER: "${CLP_DB_USER:?Please set a value.}"
- RUST_LOG: "TRACE"
+ RUST_LOG: "${CLP_API_SERVER_LOGGING_LEVEL:-INFO}"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,4 @@ COPY --link --chown=${UID} ./build/spider/spider-build/src/spider/spider_worker | |
| COPY --link --chown=${UID} ./build/nodejs-22/bin/node bin/node-22 | ||
| COPY --link --chown=${UID} ./build/python-libs/ lib/python3/site-packages/ | ||
| COPY --link --chown=${UID} ./build/webui/ var/www/webui/ | ||
| COPY --link --chown=${UID} ./build/rust/release/api_server bin/ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (i know i'm the original author of this source file.. sorry for missing that previously) now that this has become a long list, shall we alphabetize the |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @LinZhihao-723 for awareness