Skip to content

Commit 78ba9ed

Browse files
committed
Support customizable telemetry data retention policy
- Add clickhouse-admin types for represeting the telemetry retention policy and the disk usage of the database tables or oximeter timeseries specifically. - Add clickhouse-admin-server APIs for manipulating the policy and listing the database and oximeter-timeseries usage. - Add `omdb` subcommands for exercising the new APIs
1 parent 09c554d commit 78ba9ed

30 files changed

Lines changed: 2503 additions & 207 deletions

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clickhouse-admin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ clickhouse-admin-test-utils.workspace = true
4040
dropshot.workspace = true
4141
expectorate.workspace = true
4242
omicron-test-utils.workspace = true
43+
oximeter.workspace = true
4344
oximeter-test-utils.workspace = true
4445
openapi-lint.workspace = true
4546
openapiv3.workspace = true

clickhouse-admin/api/src/lib.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ api_versions!([
2727
// | example for the next person.
2828
// v
2929
// (next_int, IDENT), // NOTE: read the note at the start of this macro!
30+
(2, ADD_RETENTION_POLICY_AND_TABLE_USAGE),
3031
(1, INITIAL),
3132
]);
3233

@@ -200,6 +201,47 @@ pub trait ClickhouseAdminServerApi {
200201
async fn init_db(
201202
rqctx: RequestContext<Self::Context>,
202203
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
204+
205+
/// Set the retention policy for timeseries data.
206+
#[endpoint {
207+
method = PUT,
208+
path = "/retention-policy",
209+
versions = VERSION_ADD_RETENTION_POLICY_AND_TABLE_USAGE..,
210+
}]
211+
async fn set_retention_policy(
212+
rqctx: RequestContext<Self::Context>,
213+
policy: TypedBody<latest::retention::RetentionPolicy>,
214+
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
215+
216+
/// Get the retention policy for timeseries data from the database
217+
#[endpoint {
218+
method = GET,
219+
path = "/retention-policy",
220+
versions = VERSION_ADD_RETENTION_POLICY_AND_TABLE_USAGE..,
221+
}]
222+
async fn retention_policy(
223+
rqctx: RequestContext<Self::Context>,
224+
) -> Result<HttpResponseOk<latest::retention::RetentionPolicy>, HttpError>;
225+
226+
/// Return the resource usage of database tables.
227+
#[endpoint {
228+
method = GET,
229+
path = "/usage/database",
230+
versions = VERSION_ADD_RETENTION_POLICY_AND_TABLE_USAGE..,
231+
}]
232+
async fn database_usage(
233+
rqctx: RequestContext<Self::Context>,
234+
) -> Result<HttpResponseOk<latest::usage::DatabaseUsageResult>, HttpError>;
235+
236+
/// Return the resource usage of oximeter timeseries.
237+
#[endpoint {
238+
method = PUT,
239+
path = "/usage/oximeter-timeseries",
240+
versions = VERSION_ADD_RETENTION_POLICY_AND_TABLE_USAGE..,
241+
}]
242+
async fn oximeter_usage(
243+
rqctx: RequestContext<Self::Context>,
244+
) -> Result<HttpResponseOk<latest::usage::OximeterUsageResult>, HttpError>;
203245
}
204246

205247
/// API interface for our clickhouse-admin-single server
@@ -235,4 +277,45 @@ pub trait ClickhouseAdminSingleApi {
235277
path_params: Path<latest::server::MetricInfoPath>,
236278
query_params: Query<latest::server::TimeSeriesSettingsQuery>,
237279
) -> Result<HttpResponseOk<Vec<latest::server::SystemTimeSeries>>, HttpError>;
280+
281+
/// Set the retention policy for timeseries data.
282+
#[endpoint {
283+
method = PUT,
284+
path = "/retention-policy",
285+
versions = VERSION_ADD_RETENTION_POLICY_AND_TABLE_USAGE..,
286+
}]
287+
async fn set_retention_policy(
288+
rqctx: RequestContext<Self::Context>,
289+
policy: TypedBody<latest::retention::RetentionPolicy>,
290+
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
291+
292+
/// Get the retention policy for timeseries data from the database
293+
#[endpoint {
294+
method = GET,
295+
path = "/retention-policy",
296+
versions = VERSION_ADD_RETENTION_POLICY_AND_TABLE_USAGE..,
297+
}]
298+
async fn retention_policy(
299+
rqctx: RequestContext<Self::Context>,
300+
) -> Result<HttpResponseOk<latest::retention::RetentionPolicy>, HttpError>;
301+
302+
/// Return the resource usage of database tables.
303+
#[endpoint {
304+
method = GET,
305+
path = "/usage/database",
306+
versions = VERSION_ADD_RETENTION_POLICY_AND_TABLE_USAGE..,
307+
}]
308+
async fn database_usage(
309+
rqctx: RequestContext<Self::Context>,
310+
) -> Result<HttpResponseOk<latest::usage::DatabaseUsageResult>, HttpError>;
311+
312+
/// Return the resource usage of oximeter timeseries.
313+
#[endpoint {
314+
method = PUT,
315+
path = "/usage/oximeter-timeseries",
316+
versions = VERSION_ADD_RETENTION_POLICY_AND_TABLE_USAGE..,
317+
}]
318+
async fn oximeter_usage(
319+
rqctx: RequestContext<Self::Context>,
320+
) -> Result<HttpResponseOk<latest::usage::OximeterUsageResult>, HttpError>;
238321
}

0 commit comments

Comments
 (0)