monitor_client/api/read/
stack.rs

1use derive_empty_traits::EmptyTraits;
2use resolver_api::derive::Request;
3use serde::{Deserialize, Serialize};
4use typeshare::typeshare;
5
6use crate::entities::{
7  stack::{
8    Stack, StackActionState, StackListItem, StackQuery, StackService,
9  },
10  update::Log,
11  SearchCombinator, U64,
12};
13
14use super::MonitorReadRequest;
15
16//
17
18/// Get a specific stack. Response: [Stack].
19#[typeshare]
20#[derive(
21  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
22)]
23#[empty_traits(MonitorReadRequest)]
24#[response(GetStackResponse)]
25pub struct GetStack {
26  /// Id or name
27  #[serde(alias = "id", alias = "name")]
28  pub stack: String,
29}
30
31#[typeshare]
32pub type GetStackResponse = Stack;
33
34//
35
36/// Lists a specific stacks services (the containers). Response: [ListStackServicesResponse].
37#[typeshare]
38#[derive(
39  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
40)]
41#[empty_traits(MonitorReadRequest)]
42#[response(ListStackServicesResponse)]
43pub struct ListStackServices {
44  /// Id or name
45  #[serde(alias = "id", alias = "name")]
46  pub stack: String,
47}
48
49#[typeshare]
50pub type ListStackServicesResponse = Vec<StackService>;
51
52//
53
54/// Get a stack service's log. Response: [GetStackContainersResponse].
55#[typeshare]
56#[derive(
57  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
58)]
59#[empty_traits(MonitorReadRequest)]
60#[response(GetStackServiceLogResponse)]
61pub struct GetStackServiceLog {
62  /// Id or name
63  #[serde(alias = "id", alias = "name")]
64  pub stack: String,
65  /// The service to get the log for.
66  pub service: String,
67  /// The number of lines of the log tail to include.
68  /// Default: 100.
69  /// Max: 5000.
70  #[serde(default = "default_tail")]
71  pub tail: U64,
72}
73
74fn default_tail() -> u64 {
75  50
76}
77
78#[typeshare]
79pub type GetStackServiceLogResponse = Log;
80
81//
82
83/// Search the deployment log's tail using `grep`. All lines go to stdout.
84/// Response: [Log].
85///
86/// Note. This call will hit the underlying server directly for most up to date log.
87#[typeshare]
88#[derive(
89  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
90)]
91#[empty_traits(MonitorReadRequest)]
92#[response(SearchStackServiceLogResponse)]
93pub struct SearchStackServiceLog {
94  /// Id or name
95  #[serde(alias = "id", alias = "name")]
96  pub stack: String,
97  /// The service to get the log for.
98  pub service: String,
99  /// The terms to search for.
100  pub terms: Vec<String>,
101  /// When searching for multiple terms, can use `AND` or `OR` combinator.
102  ///
103  /// - `AND`: Only include lines with **all** terms present in that line.
104  /// - `OR`: Include lines that have one or more matches in the terms.
105  #[serde(default)]
106  pub combinator: SearchCombinator,
107  /// Invert the results, ie return all lines that DON'T match the terms / combinator.
108  #[serde(default)]
109  pub invert: bool,
110}
111
112#[typeshare]
113pub type SearchStackServiceLogResponse = Log;
114
115//
116
117/// Gets a list of existing values used as extra args across other stacks.
118/// Useful to offer suggestions. Response: [ListCommonStackExtraArgsResponse]
119#[typeshare]
120#[derive(
121  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
122)]
123#[empty_traits(MonitorReadRequest)]
124#[response(ListCommonStackExtraArgsResponse)]
125pub struct ListCommonStackExtraArgs {
126  /// optional structured query to filter stacks.
127  #[serde(default)]
128  pub query: StackQuery,
129}
130
131#[typeshare]
132pub type ListCommonStackExtraArgsResponse = Vec<String>;
133
134//
135
136/// List stacks matching optional query. Response: [ListStacksResponse].
137#[typeshare]
138#[derive(
139  Serialize, Deserialize, Debug, Clone, Default, Request, EmptyTraits,
140)]
141#[empty_traits(MonitorReadRequest)]
142#[response(ListStacksResponse)]
143pub struct ListStacks {
144  /// optional structured query to filter syncs.
145  #[serde(default)]
146  pub query: StackQuery,
147}
148
149#[typeshare]
150pub type ListStacksResponse = Vec<StackListItem>;
151
152//
153
154/// List stacks matching optional query. Response: [ListFullStacksResponse].
155#[typeshare]
156#[derive(
157  Serialize, Deserialize, Debug, Clone, Default, Request, EmptyTraits,
158)]
159#[empty_traits(MonitorReadRequest)]
160#[response(ListFullStacksResponse)]
161pub struct ListFullStacks {
162  /// optional structured query to filter stacks.
163  #[serde(default)]
164  pub query: StackQuery,
165}
166
167#[typeshare]
168pub type ListFullStacksResponse = Vec<Stack>;
169
170//
171
172/// Get current action state for the stack. Response: [StackActionState].
173#[typeshare]
174#[derive(
175  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
176)]
177#[empty_traits(MonitorReadRequest)]
178#[response(GetStackActionStateResponse)]
179pub struct GetStackActionState {
180  /// Id or name
181  #[serde(alias = "id", alias = "name")]
182  pub stack: String,
183}
184
185#[typeshare]
186pub type GetStackActionStateResponse = StackActionState;
187
188//
189
190/// Gets a summary of data relating to all syncs.
191/// Response: [GetStacksSummaryResponse].
192#[typeshare]
193#[derive(
194  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
195)]
196#[empty_traits(MonitorReadRequest)]
197#[response(GetStacksSummaryResponse)]
198pub struct GetStacksSummary {}
199
200/// Response for [GetStacksSummary]
201#[typeshare]
202#[derive(Serialize, Deserialize, Debug, Clone, Default)]
203pub struct GetStacksSummaryResponse {
204  /// The total number of stacks
205  pub total: u32,
206  /// The number of stacks with Running state.
207  pub running: u32,
208  /// The number of stacks with Paused state.
209  pub paused: u32,
210  /// The number of stacks with Stopped state.
211  pub stopped: u32,
212  /// The number of stacks with Restarting state.
213  pub restarting: u32,
214  /// The number of stacks with Dead state.
215  pub dead: u32,
216  /// The number of stacks with Created state.
217  pub created: u32,
218  /// The number of stacks with Removing state.
219  pub removing: u32,
220  /// The number of stacks with Unhealthy state.
221  pub unhealthy: u32,
222  /// The number of stacks with Down state.
223  pub down: u32,
224  /// The number of stacks with Unknown state.
225  pub unknown: u32,
226}
227
228//
229
230/// Get a target stack's configured webhooks. Response: [GetStackWebhooksEnabledResponse].
231#[typeshare]
232#[derive(
233  Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
234)]
235#[empty_traits(MonitorReadRequest)]
236#[response(GetStackWebhooksEnabledResponse)]
237pub struct GetStackWebhooksEnabled {
238  /// Id or name
239  #[serde(alias = "id", alias = "name")]
240  pub stack: String,
241}
242
243/// Response for [GetStackWebhooksEnabled]
244#[typeshare]
245#[derive(Serialize, Deserialize, Debug, Clone)]
246pub struct GetStackWebhooksEnabledResponse {
247  /// Whether the repo webhooks can even be managed.
248  /// The repo owner must be in `github_webhook_app.owners` list to be managed.
249  pub managed: bool,
250  /// Whether pushes to branch trigger refresh. Will always be false if managed is false.
251  pub refresh_enabled: bool,
252  /// Whether pushes to branch trigger stack execution. Will always be false if managed is false.
253  pub deploy_enabled: bool,
254}