From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pdm-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 749B71FF15E
	for <inbox@lore.proxmox.com>; Tue, 11 Feb 2025 15:50:30 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 274E42F97C;
	Tue, 11 Feb 2025 15:50:28 +0100 (CET)
Message-ID: <04e144d9-5e77-418d-8067-5c49298d815b@proxmox.com>
Date: Tue, 11 Feb 2025 15:50:24 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
From: Lukas Wagner <l.wagner@proxmox.com>
To: Proxmox Datacenter Manager development discussion
 <pdm-devel@lists.proxmox.com>, Wolfgang Bumiller <w.bumiller@proxmox.com>
References: <20250204095554.39501-1-w.bumiller@proxmox.com>
 <20250204095554.39501-2-w.bumiller@proxmox.com>
Content-Language: de-AT, en-US
In-Reply-To: <20250204095554.39501-2-w.bumiller@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.010 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
Subject: Re: [pdm-devel] [PATCH datacenter-manager 1/7] server: generic
 multi-client wrapper
X-BeenThere: pdm-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Datacenter Manager development discussion
 <pdm-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/>
List-Post: <mailto:pdm-devel@lists.proxmox.com>
List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Datacenter Manager development discussion
 <pdm-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pdm-devel-bounces@lists.proxmox.com
Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com>



On  2025-02-04 10:55, Wolfgang Bumiller wrote:
> +
> +// doing this via a generic method is currently tedious as it requires an extra helper trait to
> +// declare the flow of the lifetime in the `self.request` vs `self.streaming_request` function from
> +// its input to its generic output future... and then you run into borrow-checker limitations...
> +macro_rules! try_request {
> +    ($self:expr, $method:expr, $path_and_query:expr, $params:expr, $how:ident) => {
> +        let params = $params.map(serde_json::to_value);
> +        Box::pin(async move {
> +            let params = params
> +                .transpose()
> +                .map_err(|err| proxmox_client::Error::Anyhow(err.into()))?;
> +
> +            let mut last_err = None;
> +            let mut timed_out = false;
> +            // The iterator in use here will automatically mark a client as faulty if we move on to
> +            // the `next()` one.
> +            for client in $self.try_clients() {
> +                if let Some(err) = last_err.take() {
> +                    log::error!("API client error, trying another remote - {err:?}");
> +                }
> +                if timed_out {
> +                    timed_out = false;
> +                    log::error!("API client timed out, trying another remote");
> +                }
> +
> +                let request = client.$how($method.clone(), $path_and_query, params.as_ref());
> +                match tokio::time::timeout($self.timeout, request).await {
> +                    Ok(Err(proxmox_client::Error::Client(err))) => {
> +                        last_err = Some(err);
> +                    }
> +                    Ok(result) => return result,
> +                    Err(_) => {
> +                        timed_out = true;
> +                    }
> +                }
> +            }

maybe add another 

if let Some(err) = last_err {
    log::error!("... {err} ...");
}

so that the actual `err` from the last client you tried is also logged?
Also if the *last* client to try times out I guess we would like to log that as well?

> +
> +            Err(proxmox_client::Error::Other(
> +                "failed to perform API request",
> +            ))
> +        })
> +    };
> +}

-- 
- Lukas



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel