From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <g.goller@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 7E95093638
 for <pbs-devel@lists.proxmox.com>; Mon,  5 Feb 2024 14:59:28 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 55AC8185AA
 for <pbs-devel@lists.proxmox.com>; Mon,  5 Feb 2024 14:58:58 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pbs-devel@lists.proxmox.com>; Mon,  5 Feb 2024 14:58:57 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5D5FC44243
 for <pbs-devel@lists.proxmox.com>; Mon,  5 Feb 2024 14:58:57 +0100 (CET)
Mime-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
Date: Mon, 05 Feb 2024 14:58:56 +0100
Message-Id: <CYX7634MW3YS.2EH7YHBK3T8G@proxmox.com>
From: "Gabriel Goller" <g.goller@proxmox.com>
To: "Proxmox Backup Server development discussion"
 <pbs-devel@lists.proxmox.com>
X-Mailer: aerc 0.16.0-149-g2d8b81f619fc
References: <20240205115830.523721-2-s.lendl@proxmox.com>
 <20240205115830.523721-3-s.lendl@proxmox.com>
In-Reply-To: <20240205115830.523721-3-s.lendl@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.116 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
Subject: Re: [pbs-devel] [PATCH proxmox-backup 1/8] api: garbage collect job
 status
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 05 Feb 2024 13:59:28 -0000

On Mon Feb 5, 2024 at 12:58 PM CET, Stefan Lendl wrote:
> Adds an api endpoint on the datastore that reports the gc job status
> such as:
>  - Schedule
>  - State (of last run)
>  - Duration (of last run)
>  - Last Run
>  - Next Run (if scheduled)
>  - Pending Chunks (of last run)
>  - Removed Chunks (of last run)
>
> Adds a dedicated endpoint admin/gc that reports gc job status for all
> datastores including the onces without a gc-schedule.
>
> Originally-by: Gabriel Goller <g.goller@proxmox.com>
> Signed-off-by: Stefan Lendl <s.lendl@proxmox.com>
> ---
>  pbs-api-types/src/datastore.rs |  40 ++++++++++
>  src/api2/admin/datastore.rs    | 129 ++++++++++++++++++++++++++++++++-
>  src/api2/admin/gc.rs           |  57 +++++++++++++++
>  src/api2/admin/mod.rs          |   2 +
>  src/api2/admin/prune.rs        |   3 +
>  5 files changed, 228 insertions(+), 3 deletions(-)
>  mode change 100644 =3D> 100755 src/api2/admin/datastore.rs
>  create mode 100644 src/api2/admin/gc.rs
>
> diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore=
.rs
> index cce9888b..ba3879c9 100644
> --- a/pbs-api-types/src/datastore.rs
> +++ b/pbs-api-types/src/datastore.rs
> @@ -1270,6 +1270,46 @@ pub struct GarbageCollectionStatus {
>      pub still_bad: usize,
>  }
> =20
> +#[api(
> +    properties: {
> +        "last-run-upid": {
> +            optional: true,
> +            type: UPID,
> +        },
> +    },
> +)]
> +#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
> +#[serde(rename_all =3D "kebab-case")]
> +/// Garbage Collection general info
> +pub struct GarbageCollectionJobStatus {
> +    /// Datastore
> +    pub store: String,
> +    /// upid of the last run gc job
> +    #[serde(skip_serializing_if =3D "Option::is_none")]
> +    pub last_run_upid: Option<String>,
> +    /// Number of removed chunks
> +    #[serde(skip_serializing_if =3D "Option::is_none")]
> +    pub removed_chunks: Option<usize>,
> +    /// Number of pending chunks
> +    #[serde(skip_serializing_if =3D "Option::is_none")]
> +    pub pending_chunks: Option<usize>,
> +    /// Schedule of the gc job
> +    #[serde(skip_serializing_if =3D "Option::is_none")]
> +    pub schedule: Option<String>,
> +    /// Time of the next gc run
> +    #[serde(skip_serializing_if =3D "Option::is_none")]
> +    pub next_run: Option<i64>,
> +    /// Endtime of the last gc run
> +    #[serde(skip_serializing_if =3D "Option::is_none")]
> +    pub last_run_endtime: Option<i64>,
> +    /// State of the last gc run
> +    #[serde(skip_serializing_if =3D "Option::is_none")]
> +    pub last_run_state: Option<String>,
> +    /// Duration of last gc run
> +    #[serde(skip_serializing_if =3D "Option::is_none")]
> +    pub duration: Option<i64>,
> +}
> +
>  #[api(
>      properties: {
>          "gc-status": {
> diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
> old mode 100644
> new mode 100755
> index a95031e7..c46d7506
> --- a/src/api2/admin/datastore.rs
> +++ b/src/api2/admin/datastore.rs
> @@ -10,6 +10,7 @@ use anyhow::{bail, format_err, Error};
>  use futures::*;
>  use hyper::http::request::Parts;
>  use hyper::{header, Body, Response, StatusCode};
> +use proxmox_time::CalendarEvent;

Please order this import with the other `proxmox_*` imports :)

> [..]

This here is not needed:

> diff --git a/src/api2/admin/prune.rs b/src/api2/admin/prune.rs
> index a5ebf297..4eca0807 100644
> --- a/src/api2/admin/prune.rs
> +++ b/src/api2/admin/prune.rs
> @@ -1,6 +1,7 @@
>  //! Datastore Prune Job Management
> =20
>  use anyhow::{format_err, Error};
> +
>  use serde_json::Value;
> =20
>  use proxmox_router::{
> @@ -21,6 +22,8 @@ use crate::server::{
>      jobstate::{compute_schedule_status, Job, JobState},
>  };
> =20
> +
> +
>  #[api(
>      input: {
>          properties: {