Skip to content

Commit

Permalink
add /v1/system/health endpoint that always returns ok if it can
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Oct 4, 2023
1 parent 6bc5e60 commit a5e5cbe
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 2 deletions.
18 changes: 18 additions & 0 deletions nexus/src/external_api/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ type NexusApiDescription = ApiDescription<Arc<ServerContext>>;
/// Returns a description of the external nexus API
pub(crate) fn external_api() -> NexusApiDescription {
fn register_endpoints(api: &mut NexusApiDescription) -> Result<(), String> {
api.register(system_health)?;

api.register(system_policy_view)?;
api.register(system_policy_update)?;

Expand Down Expand Up @@ -364,6 +366,22 @@ pub(crate) fn external_api() -> NexusApiDescription {
// clients. Client generators use operationId to name API methods, so changing
// a function name is a breaking change from a client perspective.

/// Fetch system status
///
/// Always responds with Ok if it responds at all.
#[endpoint {
method = GET,
path = "/v1/system/health",
tags = ["system"],
}]
async fn system_health(
_rqctx: RequestContext<Arc<ServerContext>>,
) -> Result<HttpResponseOk<views::SystemHealth>, HttpError> {
Ok(HttpResponseOk(views::SystemHealth {
api: views::SystemHealthStatus::Ok,
}))
}

/// Fetch the top-level IAM policy
#[endpoint {
method = GET,
Expand Down
6 changes: 6 additions & 0 deletions nexus/src/external_api/tag-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
"url": "http://docs.oxide.computer/api/vpcs"
}
},
"system": {
"description": "General system endpoints",
"external_docs": {
"url": "http://docs.oxide.computer/api/system"
}
},
"system/hardware": {
"description": "These operations pertain to hardware inventory and management. Racks are the unit of expansion of an Oxide deployment. Racks are in turn composed of sleds, switches, power supplies, and a cabled backplane.",
"external_docs": {
Expand Down
13 changes: 12 additions & 1 deletion nexus/tests/integration_tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use dropshot::HttpErrorResponseBody;
use http::method::Method;
use http::StatusCode;
use nexus_types::external_api::{params, views::Project};
use nexus_types::external_api::params;
use nexus_types::external_api::views::{self, Project};
use omicron_common::api::external::IdentityMetadataCreateParams;
use omicron_common::api::external::IdentityMetadataUpdateParams;
use omicron_common::api::external::Name;
Expand Down Expand Up @@ -546,3 +547,13 @@ async fn test_projects_list(cptestctx: &ControlPlaneTestContext) {
.collect::<Vec<Uuid>>()
);
}

#[nexus_test]
async fn test_system_health(cptestctx: &ControlPlaneTestContext) {
let client = &cptestctx.external_client;

let health = NexusRequest::object_get(client, "/v1/system/health")
.execute_and_parse_unwrap::<views::SystemHealth>()
.await;
assert_eq!(health.api, views::SystemHealthStatus::Ok);
}
1 change: 0 additions & 1 deletion nexus/tests/integration_tests/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,5 @@ lazy_static! {
AllowedMethod::GetNonexistent
],
},

];
}
4 changes: 4 additions & 0 deletions nexus/tests/output/nexus_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ snapshot_delete DELETE /v1/snapshots/{snapshot}
snapshot_list GET /v1/snapshots
snapshot_view GET /v1/snapshots/{snapshot}

API operations found with tag "system"
OPERATION ID METHOD URL PATH
system_health GET /v1/system/health

API operations found with tag "system/hardware"
OPERATION ID METHOD URL PATH
networking_switch_port_apply_settings POST /v1/system/hardware/switch-port/{port}/settings
Expand Down
1 change: 1 addition & 0 deletions nexus/tests/output/uncovered-authz-endpoints.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
API endpoints with no coverage in authz tests:
system_health (get "/v1/system/health")
device_auth_request (post "/device/auth")
device_auth_confirm (post "/device/confirm")
device_access_token (post "/device/token")
Expand Down
15 changes: 15 additions & 0 deletions nexus/types/src/external_api/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,18 @@ pub struct UpdateDeployment {
pub version: SemverVersion,
pub status: UpdateStatus,
}

// SYSTEM HEALTH

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum SystemHealthStatus {
Ok,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct SystemHealth {
/// Whether the external API is reachable. Will always be Ok if the endpoint
/// returns anything at all.
pub api: SystemHealthStatus,
}
57 changes: 57 additions & 0 deletions openapi/nexus.json
Original file line number Diff line number Diff line change
Expand Up @@ -4036,6 +4036,34 @@
}
}
},
"/v1/system/health": {
"get": {
"tags": [
"system"
],
"summary": "Fetch system status",
"description": "Always responds with Ok if it responds at all.",
"operationId": "system_health",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SystemHealth"
}
}
}
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/v1/system/identity-providers": {
"get": {
"tags": [
Expand Down Expand Up @@ -14031,6 +14059,28 @@
"vlan_id"
]
},
"SystemHealth": {
"type": "object",
"properties": {
"api": {
"description": "Whether the external API is reachable. Will always be Ok if the endpoint returns anything at all.",
"allOf": [
{
"$ref": "#/components/schemas/SystemHealthStatus"
}
]
}
},
"required": [
"api"
]
},
"SystemHealthStatus": {
"type": "string",
"enum": [
"ok"
]
},
"User": {
"description": "View of a User",
"type": "object",
Expand Down Expand Up @@ -15247,6 +15297,13 @@
"url": "http://docs.oxide.computer/api/snapshots"
}
},
{
"name": "system",
"description": "General system endpoints",
"externalDocs": {
"url": "http://docs.oxide.computer/api/system"
}
},
{
"name": "system/hardware",
"description": "These operations pertain to hardware inventory and management. Racks are the unit of expansion of an Oxide deployment. Racks are in turn composed of sleds, switches, power supplies, and a cabled backplane.",
Expand Down

0 comments on commit a5e5cbe

Please sign in to comment.