Skip to content

Commit 243ed56

Browse files
authored
chore: move log models under buck2 types (#1878)
Signed-off-by: lvy010 <17338770572@163.com>
1 parent 5ef6cbb commit 243ed56

7 files changed

Lines changed: 87 additions & 90 deletions

File tree

api-model/src/buck2/types.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,75 @@ impl ProjectRelativePath {
3939
opt.map(|s| Self(s.to_owned()))
4040
}
4141
}
42+
43+
/// Supported read modes for log APIs.
44+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, PartialEq, Eq, Default)]
45+
#[serde(rename_all = "lowercase")]
46+
pub enum LogReadMode {
47+
#[default]
48+
Full,
49+
Segment,
50+
}
51+
52+
/// Log stream event emitted by Orion worker/build processing.
53+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
54+
pub struct LogEvent {
55+
pub task_id: String,
56+
pub repo_name: String,
57+
pub build_id: String,
58+
pub line: String,
59+
pub is_end: bool,
60+
}
61+
62+
/// Log segment read result.
63+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
64+
pub struct LogSegment {
65+
pub build_id: String,
66+
pub offset: u64,
67+
pub len: usize,
68+
pub data: String,
69+
pub next_offset: u64,
70+
pub file_size: u64,
71+
/// Whether we reached end of file
72+
pub eof: bool,
73+
}
74+
75+
/// Query parameters for target log APIs.
76+
#[derive(Debug, Clone, Deserialize, ToSchema)]
77+
pub struct TargetLogQuery {
78+
#[serde(default)]
79+
pub r#type: LogReadMode,
80+
pub offset: Option<usize>,
81+
pub limit: Option<usize>,
82+
}
83+
84+
/// Query parameters for task history log APIs.
85+
#[derive(Debug, Clone, Deserialize, ToSchema)]
86+
pub struct TaskHistoryQuery {
87+
pub task_id: String,
88+
pub build_id: String,
89+
pub repo: String,
90+
pub start: Option<usize>,
91+
pub end: Option<usize>,
92+
}
93+
94+
/// Log lines response for history reads.
95+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
96+
pub struct LogLinesResponse {
97+
pub data: Vec<String>,
98+
pub len: usize,
99+
}
100+
101+
/// Log lines response for target reads.
102+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
103+
pub struct TargetLogLinesResponse {
104+
pub data: Vec<String>,
105+
pub len: usize,
106+
pub build_id: String,
107+
}
108+
109+
/// Error response for log-related APIs.
110+
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
111+
pub struct LogErrorResponse {
112+
pub message: String,
113+
}

api-model/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pub mod buck2;
22
pub mod common;
33
pub mod git;
4-
pub mod orion;

api-model/src/orion/log.rs

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

api-model/src/orion/mod.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

orion-server/src/api.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
};
55

66
use anyhow::Result;
7-
use api_model::orion::log::{
7+
use api_model::buck2::types::{
88
LogErrorResponse, LogEvent, LogLinesResponse, LogReadMode, TargetLogLinesResponse,
99
TargetLogQuery, TaskHistoryQuery,
1010
};
@@ -263,10 +263,10 @@ pub async fn task_output_handler(
263263
("end" = Option<usize>, Query, description = "End line number"),
264264
),
265265
responses(
266-
(status = 200, description = "History Log", body = api_model::orion::log::LogLinesResponse),
267-
(status = 400, description = "Invalid parameters", body = api_model::orion::log::LogErrorResponse),
268-
(status = 404, description = "Log file not found", body = api_model::orion::log::LogErrorResponse),
269-
(status = 500, description = "Failed to operate log file", body = api_model::orion::log::LogErrorResponse),
266+
(status = 200, description = "History Log", body = api_model::buck2::types::LogLinesResponse),
267+
(status = 400, description = "Invalid parameters", body = api_model::buck2::types::LogErrorResponse),
268+
(status = 404, description = "Log file not found", body = api_model::buck2::types::LogErrorResponse),
269+
(status = 500, description = "Failed to operate log file", body = api_model::buck2::types::LogErrorResponse),
270270
)
271271
)]
272272
pub async fn task_history_output_handler(
@@ -323,10 +323,10 @@ pub async fn task_history_output_handler(
323323
(
324324
status = 200,
325325
description = "Target log content",
326-
body = api_model::orion::log::TargetLogLinesResponse
326+
body = api_model::buck2::types::TargetLogLinesResponse
327327
),
328-
(status = 404, description = "Target or log not found", body = api_model::orion::log::LogErrorResponse),
329-
(status = 500, description = "Failed to read log", body = api_model::orion::log::LogErrorResponse)
328+
(status = 404, description = "Target or log not found", body = api_model::buck2::types::LogErrorResponse),
329+
(status = 500, description = "Failed to read log", body = api_model::buck2::types::LogErrorResponse)
330330
)
331331
)]
332332
pub async fn target_logs_handler(

orion-server/src/log/log_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{path::Path, sync::Arc};
22

3-
use api_model::orion::log::LogEvent;
3+
use api_model::buck2::types::LogEvent;
44
use futures::{Stream, StreamExt};
55
use tokio_stream::wrappers::BroadcastStream;
66

orion-server/src/server.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ use crate::{
4444
components(
4545
schemas(
4646
crate::scheduler::BuildRequest,
47-
api_model::orion::log::LogSegment,
48-
api_model::orion::log::LogLinesResponse,
49-
api_model::orion::log::TargetLogLinesResponse,
50-
api_model::orion::log::LogErrorResponse,
47+
api_model::buck2::types::LogLinesResponse,
48+
api_model::buck2::types::TargetLogLinesResponse,
49+
api_model::buck2::types::LogErrorResponse,
5150
api::TaskStatusEnum,
5251
api::BuildDTO,
5352
api::TargetDTO,
54-
api_model::orion::log::TargetLogQuery,
55-
api_model::orion::log::LogReadMode,
56-
api_model::orion::log::TaskHistoryQuery,
53+
api_model::buck2::types::TargetLogQuery,
54+
api_model::buck2::types::LogReadMode,
55+
api_model::buck2::types::TaskHistoryQuery,
5756
api::TaskInfoDTO,
5857
api::OrionClientInfo,
5958
api::OrionClientStatus,

0 commit comments

Comments
 (0)