|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +//! HTTP API for ereport producers. |
| 6 | +
|
| 7 | +use dropshot::HttpError; |
| 8 | +use dropshot::HttpResponseOk; |
| 9 | +use dropshot::Path; |
| 10 | +use dropshot::Query; |
| 11 | +use dropshot::RequestContext; |
| 12 | +use dropshot::ResultsPage; |
| 13 | +pub use ereport_types::Ena; |
| 14 | +pub use ereport_types::Ereport; |
| 15 | +pub use ereport_types::EreporterGenerationUuid; |
| 16 | +pub use ereport_types::Reporter; |
| 17 | +use openapi_manager_types::{ |
| 18 | + SupportedVersion, SupportedVersions, api_versions, |
| 19 | +}; |
| 20 | +use schemars::JsonSchema; |
| 21 | +use serde::Deserialize; |
| 22 | +use serde::Serialize; |
| 23 | +use std::num::NonZeroU32; |
| 24 | +use uuid::Uuid; |
| 25 | + |
| 26 | +api_versions!([ |
| 27 | + // WHEN CHANGING THE API (part 1 of 2): |
| 28 | + // |
| 29 | + // +- Pick a new semver and define it in the list below. The list MUST |
| 30 | + // | remain sorted, which generally means that your version should go at |
| 31 | + // | the very top. |
| 32 | + // | |
| 33 | + // | Duplicate this line, uncomment the *second* copy, update that copy for |
| 34 | + // | your new API version, and leave the first copy commented out as an |
| 35 | + // | example for the next person. |
| 36 | + // v |
| 37 | + // (next_int, IDENT), |
| 38 | + (1, INITIAL), |
| 39 | +]); |
| 40 | + |
| 41 | +// WHEN CHANGING THE API (part 2 of 2): |
| 42 | +// |
| 43 | +// The call to `api_versions!` above defines constants of type |
| 44 | +// `semver::Version` that you can use in your Dropshot API definition to specify |
| 45 | +// the version when a particular endpoint was added or removed. For example, if |
| 46 | +// you used: |
| 47 | +// |
| 48 | +// (2, ADD_FOOBAR) |
| 49 | +// |
| 50 | +// Then you could use `VERSION_ADD_FOOBAR` as the version in which endpoints |
| 51 | +// were added or removed. |
| 52 | + |
| 53 | +/// API for ereport producers. |
| 54 | +#[dropshot::api_description] |
| 55 | +pub trait EreportApi { |
| 56 | + type Context; |
| 57 | + |
| 58 | + /// Collect a tranche of ereports from this reporter. |
| 59 | + #[endpoint { |
| 60 | + method = POST, |
| 61 | + path = "/ereports/{reporter_id}", |
| 62 | + }] |
| 63 | + async fn ereports_collect( |
| 64 | + rqctx: RequestContext<Self::Context>, |
| 65 | + path: Path<ReporterPath>, |
| 66 | + query: Query<EreportQuery>, |
| 67 | + ) -> Result<HttpResponseOk<Ereports>, HttpError>; |
| 68 | +} |
| 69 | + |
| 70 | +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] |
| 71 | +pub struct ReporterPath { |
| 72 | + /// The UUID of the reporter from which to collect ereports. |
| 73 | + pub reporter_id: Uuid, |
| 74 | +} |
| 75 | + |
| 76 | +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] |
| 77 | +pub struct EreportQuery { |
| 78 | + /// The generation (restart nonce) of the reporter at which all other query |
| 79 | + /// parameters are valid. |
| 80 | + /// |
| 81 | + /// If this value does not match the reporter's current generation, the |
| 82 | + /// reporter's response will include the current generation, and will start |
| 83 | + /// at the earliest known ENA, rather than the provided `last_seen` ENA.` |
| 84 | + pub generation: EreporterGenerationUuid, |
| 85 | + |
| 86 | + /// If present, the reporter should not include ENAs earlier than this one |
| 87 | + /// in its response, provided that the query's requested generation matches |
| 88 | + /// the current generation. |
| 89 | + pub start_at: Option<Ena>, |
| 90 | + |
| 91 | + /// The ENA of the last ereport committed to persistent storage from the |
| 92 | + /// requested reporter generation. |
| 93 | + /// |
| 94 | + /// If the generation parameter matches the reporter's current generation, |
| 95 | + /// it is permitted to discard any ereports with ENAs up to and including |
| 96 | + /// this value. If the generation has changed from the provided generation, |
| 97 | + /// the reporter will not discard data. |
| 98 | + pub committed: Option<Ena>, |
| 99 | + |
| 100 | + /// Maximum number of ereports to return in this tranche. |
| 101 | + pub limit: NonZeroU32, |
| 102 | +} |
| 103 | + |
| 104 | +/// A tranche of ereports received from a reporter. |
| 105 | +#[derive(Debug, Serialize, Deserialize, JsonSchema)] |
| 106 | +pub struct Ereports { |
| 107 | + /// The reporter's current generation ID. |
| 108 | + /// |
| 109 | + /// If this is not equal to the current known generation, then the reporter |
| 110 | + /// has restarted. |
| 111 | + pub generation: EreporterGenerationUuid, |
| 112 | + /// The ereports in this tranche, and the ENA of the next page of ereports |
| 113 | + /// (if one exists).) |
| 114 | + #[serde(flatten)] |
| 115 | + pub reports: ResultsPage<Ereport>, |
| 116 | +} |
0 commit comments