Skip to content

Commit 159b927

Browse files
committed
editoast: log stdcm requests
Signed-off-by: hamz2a <atrari.hamza@gmail.com>
1 parent 990c8fa commit 159b927

File tree

11 files changed

+188
-22
lines changed

11 files changed

+188
-22
lines changed

editoast/editoast_models/src/tables.rs

+17
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,21 @@ diesel::table! {
596596
}
597597
}
598598

599+
diesel::table! {
600+
use diesel::sql_types::*;
601+
use postgis_diesel::sql_types::*;
602+
603+
stdcm_logs (id) {
604+
id -> Int8,
605+
#[max_length = 32]
606+
trace_id -> Varchar,
607+
request -> Jsonb,
608+
response -> Jsonb,
609+
created -> Timestamptz,
610+
user_id -> Nullable<Int8>,
611+
}
612+
}
613+
599614
diesel::table! {
600615
use diesel::sql_types::*;
601616
use postgis_diesel::sql_types::*;
@@ -798,6 +813,7 @@ diesel::joinable!(search_project -> project (id));
798813
diesel::joinable!(search_scenario -> scenario (id));
799814
diesel::joinable!(search_signal -> infra_object_signal (id));
800815
diesel::joinable!(search_study -> study (id));
816+
diesel::joinable!(stdcm_logs -> authn_user (user_id));
801817
diesel::joinable!(stdcm_search_environment -> electrical_profile_set (electrical_profile_set_id));
802818
diesel::joinable!(stdcm_search_environment -> infra (infra_id));
803819
diesel::joinable!(stdcm_search_environment -> temporary_speed_limit_group (temporary_speed_limit_group_id));
@@ -851,6 +867,7 @@ diesel::allow_tables_to_appear_in_same_query!(
851867
search_signal,
852868
search_study,
853869
search_track,
870+
stdcm_logs,
854871
stdcm_search_environment,
855872
study,
856873
temporary_speed_limit,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE stdcm_logs;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TABLE stdcm_logs (
2+
id int8 PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
3+
trace_id VARCHAR(32) UNIQUE NOT NULL,
4+
request jsonb NOT NULL,
5+
response jsonb NOT NULL,
6+
created timestamptz NOT NULL DEFAULT NOW(),
7+
user_id bigint REFERENCES authn_user ON DELETE CASCADE
8+
);

editoast/openapi.yaml

+64
Original file line numberDiff line numberDiff line change
@@ -8622,6 +8622,45 @@ components:
86228622
type: integer
86238623
format: int64
86248624
nullable: true
8625+
Response:
8626+
oneOf:
8627+
- type: object
8628+
required:
8629+
- simulation
8630+
- path
8631+
- departure_time
8632+
- status
8633+
properties:
8634+
departure_time:
8635+
type: string
8636+
format: date-time
8637+
path:
8638+
$ref: '#/components/schemas/PathfindingResultSuccess'
8639+
simulation:
8640+
$ref: '#/components/schemas/SimulationResponse'
8641+
status:
8642+
type: string
8643+
enum:
8644+
- success
8645+
- type: object
8646+
required:
8647+
- status
8648+
properties:
8649+
status:
8650+
type: string
8651+
enum:
8652+
- path_not_found
8653+
- type: object
8654+
required:
8655+
- error
8656+
- status
8657+
properties:
8658+
error:
8659+
$ref: '#/components/schemas/SimulationResponse'
8660+
status:
8661+
type: string
8662+
enum:
8663+
- preprocessing_simulation_error
86258664
RjsPowerRestrictionRange:
86268665
type: object
86278666
description: A range along the train path where a power restriction is applied.
@@ -10228,6 +10267,31 @@ components:
1022810267
type: array
1022910268
items:
1023010269
$ref: '#/components/schemas/RangeAllowance'
10270+
StdcmLog:
10271+
type: object
10272+
required:
10273+
- id
10274+
- trace_id
10275+
- request
10276+
- response
10277+
- created
10278+
properties:
10279+
created:
10280+
type: string
10281+
format: date-time
10282+
id:
10283+
type: integer
10284+
format: int64
10285+
request:
10286+
$ref: '#/components/schemas/Request'
10287+
response:
10288+
$ref: '#/components/schemas/Response'
10289+
trace_id:
10290+
type: string
10291+
user_id:
10292+
type: integer
10293+
format: int64
10294+
nullable: true
1023110295
StdcmSearchEnvironment:
1023210296
type: object
1023310297
required:

editoast/src/core/conflict_detection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct ConflictDetectionRequest {
2929
pub work_schedules: Option<WorkSchedulesRequest>,
3030
}
3131

32-
#[derive(Debug, Clone, Serialize)]
32+
#[derive(Debug, Clone, Serialize, Deserialize)]
3333
pub struct TrainRequirements {
3434
pub start_time: DateTime<Utc>,
3535
pub spacing_requirements: Vec<SpacingRequirement>,

editoast/src/core/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ editoast_common::schemas! {
3636
simulation::schemas(),
3737
pathfinding::schemas(),
3838
conflict_detection::schemas(),
39+
stdcm::schemas(),
3940
}
4041

4142
#[derive(Debug, Clone)]

editoast/src/core/simulation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ editoast_common::schemas! {
3434
SimulationResponse,
3535
}
3636

37-
#[derive(Debug, Serialize, Derivative)]
37+
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
3838
#[derivative(Hash)]
3939
pub struct PhysicsConsist {
4040
pub effort_curves: EffortCurves,

editoast/src/core/stdcm.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ use super::simulation::SimulationResponse;
1919
use crate::core::AsCoreRequest;
2020
use crate::core::Json;
2121

22-
#[derive(Debug, Serialize)]
22+
editoast_common::schemas! {
23+
Response,
24+
}
25+
26+
#[derive(Debug, Clone, Serialize, Deserialize)]
2327
pub struct Request {
2428
/// Infrastructure id
2529
pub infra: i64,
@@ -61,7 +65,7 @@ pub struct Request {
6165
pub temporary_speed_limits: Vec<TemporarySpeedLimit>,
6266
}
6367

64-
#[derive(Debug, Serialize)]
68+
#[derive(Debug, Clone, Serialize, Deserialize)]
6569
pub struct PathItem {
6670
/// The track offsets of the path item
6771
pub locations: Vec<TrackOffset>,
@@ -72,7 +76,7 @@ pub struct PathItem {
7276
}
7377

7478
/// Contains the data of a step timing, when it is specified
75-
#[derive(Debug, Serialize)]
79+
#[derive(Debug, Clone, Serialize, Deserialize)]
7680
pub struct StepTimingData {
7781
/// Time the train should arrive at this point
7882
pub arrival_time: DateTime<Utc>,
@@ -83,7 +87,7 @@ pub struct StepTimingData {
8387
}
8488

8589
/// Lighter description of a work schedule, with only the relevant information for core
86-
#[derive(Debug, Serialize)]
90+
#[derive(Debug, Clone, Serialize, Deserialize)]
8791
pub struct WorkSchedule {
8892
/// Start time as a time delta from the stdcm start time in ms
8993
pub start_time: u64,
@@ -94,7 +98,7 @@ pub struct WorkSchedule {
9498
}
9599

96100
/// Lighter description of a work schedule with only the relevant information for core
97-
#[derive(Debug, Serialize)]
101+
#[derive(Debug, Clone, Serialize, Deserialize)]
98102
pub struct TemporarySpeedLimit {
99103
/// Speed limitation in m/s
100104
pub speed_limit: f64,
@@ -114,7 +118,7 @@ pub struct UndirectedTrackRange {
114118
pub end: u64,
115119
}
116120

117-
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
121+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, ToSchema)]
118122
#[serde(tag = "status", rename_all = "snake_case")]
119123
// We accepted the difference of memory size taken by variants
120124
// Since there is only on success and others are error cases

editoast/src/models/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod fixtures;
66
pub mod infra;
77
pub mod infra_objects;
88
pub mod layers;
9+
pub mod stdcm_log;
910
// We allow unused until models is moved to a separate crate
1011
pub mod auth;
1112
pub mod pagination;
@@ -41,6 +42,7 @@ editoast_common::schemas! {
4142
infra::schemas(),
4243
projects::schemas(),
4344
rolling_stock_model::schemas(),
45+
stdcm_log::schemas(),
4446
}
4547

4648
#[cfg(test)]

editoast/src/models/stdcm_log.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use chrono::DateTime;
2+
use chrono::Utc;
3+
use editoast_derive::Model;
4+
use serde::Deserialize;
5+
use serde::Serialize;
6+
use utoipa::ToSchema;
7+
8+
use crate::core::stdcm::Request;
9+
use crate::core::stdcm::Response;
10+
11+
editoast_common::schemas! {
12+
StdcmLog,
13+
}
14+
15+
#[derive(Clone, Debug, Serialize, Deserialize, Model, ToSchema)]
16+
#[model(table = editoast_models::tables::stdcm_logs)]
17+
#[model(gen(ops = c))]
18+
pub struct StdcmLog {
19+
pub id: i64,
20+
pub trace_id: String,
21+
#[model(json)]
22+
pub request: Request,
23+
#[model(json)]
24+
pub response: Response,
25+
pub created: DateTime<Utc>,
26+
pub user_id: Option<i64>,
27+
}

0 commit comments

Comments
 (0)