forge
Clone
https://git.tahinli.com/Tahinli/forge.git
0 watching0 forksRustAGPL-3.07.1 MiB490f099Tahinli7 hours ago322 commits
| 1 | //! The runner's own log, shipped to the forge. A tracing layer formats every INFO (or more severe) |
| 2 | //! event into a bounded in-memory ring. [`ship`] posts the lines the forge has not seen yet, so the |
| 3 | //! runner's page on the forge shows what it was doing, for example why a job waited in the queue. |
| 4 | //! Job logs are not part of this. They have their own path, see [`crate::logs`]. |
| 5 | |
| 6 | use VecDeque; |
| 7 | use ; |
| 8 | use ; |
| 9 | use ; |
| 10 | |
| 11 | use ; |
| 12 | use StatusCode; |
| 13 | use CancellationToken; |
| 14 | use ; |
| 15 | use ; |
| 16 | use Layer; |
| 17 | use Context; |
| 18 | |
| 19 | use crate; |
| 20 | |
| 21 | /// Most lines the ring holds. The oldest are dropped first. |
| 22 | pub const CAPACITY: usize = 2000; |
| 23 | /// Longest text kept for one line, in bytes. Longer text is cut on a character boundary. |
| 24 | pub const MAX_TEXT: usize = 4096; |
| 25 | /// Most lines in one batch. |
| 26 | pub const BATCH: usize = 500; |
| 27 | /// Time between two shipping attempts. |
| 28 | const EVERY: Duration = from_secs; |
| 29 | /// Event targets that are noise. Shipping uses HTTP, so these would feed back into the ring. |
| 30 | const SKIP_TARGETS: = ; |
| 31 | |
| 32 | static RING: = new; |
| 33 | |
| 34 | /// The ring shared by the layer and the shipper. |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | /// The layer that fills the ring. Add it to the subscriber with `.with(selflog::layer())`. |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | /// A bounded buffer of log lines. Each line gets the next sequence number, counting from 0 for |
| 45 | /// the process. Lines are shipped by sequence number, so a line keeps its number after older |
| 46 | /// ones are dropped. |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | /// The tracing layer that puts INFO (and more severe) events into the ring. |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | /// Collects an event's message and fields into one line, in the same shape the fmt layer uses: |
| 130 | /// the message, then `key=value` for each field. |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | pub |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | /// Cuts `text` to at most [`MAX_TEXT`] bytes, on a character boundary. |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | /// Posts the lines the forge has not seen yet, every two seconds, under the boot id of this |
| 194 | /// process. Failures are logged at debug level and retried on the next tick. When `stop` is |
| 195 | /// cancelled, the lines still held are sent before returning, so the caller may bound this with a |
| 196 | /// timeout. An older forge without the endpoint answers 404, and then shipping stops for good. |
| 197 | pub async |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 |