Skip to content

Commit

Permalink
[sled-diagnostics] Output for support bundles should be structured (#…
Browse files Browse the repository at this point in the history
…7228)

This introduces the `SledDiagnosticsQueryOutput` type so support bundles
can now have structured output in collected files. This makes it
potentially easier for an operator to write scripts that search for
particular commands based on various fields.

This is on top of:
- #7194
- #7193
  • Loading branch information
papertigers authored Jan 8, 2025
1 parent a77566a commit 78ca57a
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 94 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 103 additions & 15 deletions openapi/sled-agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,16 @@
"operationId": "support_dladm_info",
"responses": {
"200": {
"description": "",
"description": "successful operation",
"content": {
"*/*": {
"schema": {}
"application/json": {
"schema": {
"title": "Array_of_SledDiagnosticsQueryOutput",
"type": "array",
"items": {
"$ref": "#/components/schemas/SledDiagnosticsQueryOutput"
}
}
}
}
},
Expand All @@ -699,10 +705,16 @@
"operationId": "support_ipadm_info",
"responses": {
"200": {
"description": "",
"description": "successful operation",
"content": {
"*/*": {
"schema": {}
"application/json": {
"schema": {
"title": "Array_of_SledDiagnosticsQueryOutput",
"type": "array",
"items": {
"$ref": "#/components/schemas/SledDiagnosticsQueryOutput"
}
}
}
}
},
Expand All @@ -720,10 +732,16 @@
"operationId": "support_pargs_info",
"responses": {
"200": {
"description": "",
"description": "successful operation",
"content": {
"*/*": {
"schema": {}
"application/json": {
"schema": {
"title": "Array_of_SledDiagnosticsQueryOutput",
"type": "array",
"items": {
"$ref": "#/components/schemas/SledDiagnosticsQueryOutput"
}
}
}
}
},
Expand All @@ -741,10 +759,16 @@
"operationId": "support_pstack_info",
"responses": {
"200": {
"description": "",
"description": "successful operation",
"content": {
"*/*": {
"schema": {}
"application/json": {
"schema": {
"title": "Array_of_SledDiagnosticsQueryOutput",
"type": "array",
"items": {
"$ref": "#/components/schemas/SledDiagnosticsQueryOutput"
}
}
}
}
},
Expand All @@ -762,10 +786,12 @@
"operationId": "support_zoneadm_info",
"responses": {
"200": {
"description": "",
"description": "successful operation",
"content": {
"*/*": {
"schema": {}
"application/json": {
"schema": {
"$ref": "#/components/schemas/SledDiagnosticsQueryOutput"
}
}
}
},
Expand Down Expand Up @@ -5569,6 +5595,68 @@
"type": "string",
"pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
},
"SledDiagnosticsQueryOutput": {
"oneOf": [
{
"type": "object",
"properties": {
"success": {
"type": "object",
"properties": {
"command": {
"description": "The command and its arguments.",
"type": "string"
},
"exit_code": {
"nullable": true,
"description": "The exit code if one was present when the command exited.",
"type": "integer",
"format": "int32"
},
"exit_status": {
"description": "The exit status of the command. This will be the exit code (if any) and exit reason such as from a signal.",
"type": "string"
},
"stdio": {
"description": "Any stdout/stderr produced by the command.",
"type": "string"
}
},
"required": [
"command",
"exit_status",
"stdio"
]
}
},
"required": [
"success"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"failure": {
"type": "object",
"properties": {
"error": {
"description": "The reason the command failed to execute.",
"type": "string"
}
},
"required": [
"error"
]
}
},
"required": [
"failure"
],
"additionalProperties": false
}
]
},
"SledIdentifiers": {
"description": "Identifiers for a single sled.\n\nThis is intended primarily to be used in timeseries, to identify sled from which metric data originates.",
"type": "object",
Expand Down
1 change: 1 addition & 0 deletions sled-agent/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ schemars.workspace = true
serde.workspace = true
sled-agent-types.workspace = true
sled-hardware-types.workspace = true
sled-diagnostics.workspace = true
uuid.workspace = true
11 changes: 6 additions & 5 deletions sled-agent/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use sled_agent_types::{
ZoneBundleId, ZoneBundleMetadata,
},
};
use sled_diagnostics::SledDiagnosticsQueryOutput;
use uuid::Uuid;

#[dropshot::api_description]
Expand Down Expand Up @@ -630,39 +631,39 @@ pub trait SledAgentApi {
}]
async fn support_zoneadm_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError>;
) -> Result<HttpResponseOk<SledDiagnosticsQueryOutput>, HttpError>;

#[endpoint {
method = GET,
path = "/support/ipadm-info",
}]
async fn support_ipadm_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError>;
) -> Result<HttpResponseOk<Vec<SledDiagnosticsQueryOutput>>, HttpError>;

#[endpoint {
method = GET,
path = "/support/dladm-info",
}]
async fn support_dladm_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError>;
) -> Result<HttpResponseOk<Vec<SledDiagnosticsQueryOutput>>, HttpError>;

#[endpoint {
method = GET,
path = "/support/pargs-info",
}]
async fn support_pargs_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError>;
) -> Result<HttpResponseOk<Vec<SledDiagnosticsQueryOutput>>, HttpError>;

#[endpoint {
method = GET,
path = "/support/pstack-info",
}]
async fn support_pstack_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError>;
) -> Result<HttpResponseOk<Vec<SledDiagnosticsQueryOutput>>, HttpError>;
}

#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
Expand Down
88 changes: 41 additions & 47 deletions sled-agent/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ use sled_agent_types::zone_bundle::{
BundleUtilization, CleanupContext, CleanupCount, CleanupPeriod,
StorageLimit, ZoneBundleId, ZoneBundleMetadata,
};
use sled_diagnostics::SledDiagnosticsCommandHttpOutput;
use sled_diagnostics::{
SledDiagnosticsCommandHttpOutput, SledDiagnosticsQueryOutput,
};
use std::collections::BTreeMap;

type SledApiDescription = ApiDescription<SledAgent>;
Expand Down Expand Up @@ -964,73 +966,65 @@ impl SledAgentApi for SledAgentImpl {

async fn support_zoneadm_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError> {
) -> Result<HttpResponseOk<SledDiagnosticsQueryOutput>, HttpError> {
let sa = request_context.context();
let res = sa.support_zoneadm_info().await;
Ok(HttpResponseOk(FreeformBody(res.get_output().into())))
Ok(HttpResponseOk(res.get_output()))
}

async fn support_ipadm_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError> {
) -> Result<HttpResponseOk<Vec<SledDiagnosticsQueryOutput>>, HttpError>
{
let sa = request_context.context();
let output = sa
.support_ipadm_info()
.await
.into_iter()
.map(|cmd| cmd.get_output())
.collect::<Vec<_>>()
.as_slice()
.join("\n\n");

Ok(HttpResponseOk(FreeformBody(output.into())))
Ok(HttpResponseOk(
sa.support_ipadm_info()
.await
.into_iter()
.map(|cmd| cmd.get_output())
.collect::<Vec<_>>(),
))
}

async fn support_dladm_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError> {
) -> Result<HttpResponseOk<Vec<SledDiagnosticsQueryOutput>>, HttpError>
{
let sa = request_context.context();
let output = sa
.support_dladm_info()
.await
.into_iter()
.map(|cmd| cmd.get_output())
.collect::<Vec<_>>()
.as_slice()
.join("\n\n");

Ok(HttpResponseOk(FreeformBody(output.into())))
Ok(HttpResponseOk(
sa.support_dladm_info()
.await
.into_iter()
.map(|cmd| cmd.get_output())
.collect::<Vec<_>>(),
))
}

async fn support_pargs_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError> {
) -> Result<HttpResponseOk<Vec<SledDiagnosticsQueryOutput>>, HttpError>
{
let sa = request_context.context();
let output = sa
.support_pargs_info()
.await
.into_iter()
.map(|cmd| cmd.get_output())
.collect::<Vec<_>>()
.as_slice()
.join("\n\n");

Ok(HttpResponseOk(FreeformBody(output.into())))
Ok(HttpResponseOk(
sa.support_pargs_info()
.await
.into_iter()
.map(|cmd| cmd.get_output())
.collect::<Vec<_>>(),
))
}

async fn support_pstack_info(
request_context: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<FreeformBody>, HttpError> {
) -> Result<HttpResponseOk<Vec<SledDiagnosticsQueryOutput>>, HttpError>
{
let sa = request_context.context();
let output = sa
.support_pstack_info()
.await
.into_iter()
.map(|cmd| cmd.get_output())
.collect::<Vec<_>>()
.as_slice()
.join("\n\n");

Ok(HttpResponseOk(FreeformBody(output.into())))
Ok(HttpResponseOk(
sa.support_pstack_info()
.await
.into_iter()
.map(|cmd| cmd.get_output())
.collect::<Vec<_>>(),
))
}
}
Loading

0 comments on commit 78ca57a

Please sign in to comment.