risedev/
preflight_check.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::env;
16use std::process::Command;
17
18use anyhow::Result;
19use console::style;
20use thiserror_ext::AsReport;
21
22fn preflight_check_proxy() -> Result<()> {
23    if env::var("http_proxy").is_ok()
24        || env::var("https_proxy").is_ok()
25        || env::var("HTTP_PROXY").is_ok()
26        || env::var("HTTPS_PROXY").is_ok()
27        || env::var("all_proxy").is_ok()
28        || env::var("ALL_PROXY").is_ok()
29    {
30        if let Ok(x) = env::var("no_proxy")
31            && x.contains("127.0.0.1")
32            && x.contains("::1")
33        {
34            println!(
35                "[{}] {} - You are using proxies for all RisingWave components. Please make sure that `no_proxy` is set for all worker nodes within the cluster.",
36                style("risedev-preflight-check").bold(),
37                style("INFO").green().bold()
38            );
39        } else {
40            println!(
41                "[{}] {} - `no_proxy` is not set correctly, which might cause failure in RiseDev and RisingWave. Consider {}.",
42                style("risedev-preflight-check").bold(),
43                style("WARN").yellow().bold(),
44                style("`export no_proxy=localhost,127.0.0.1,::1`")
45                    .blue()
46                    .bold()
47            );
48        }
49    }
50
51    Ok(())
52}
53
54fn preflight_check_ulimit() -> Result<()> {
55    let ulimit = Command::new("sh")
56        .args(["-c", "ulimit -n"])
57        .output()?
58        .stdout;
59    let ulimit = String::from_utf8(ulimit)?;
60    let ulimit: usize = ulimit.trim().parse()?;
61    if ulimit < 8192 {
62        println!(
63            "[{}] {} - ulimit for file handler is too low (currently {}). If you meet too many open files error, considering changing the ulimit.",
64            style("risedev-preflight-check").bold(),
65            style("WARN").yellow().bold(),
66            ulimit
67        );
68    }
69    Ok(())
70}
71
72pub fn preflight_check() -> Result<()> {
73    if let Err(e) = preflight_check_proxy() {
74        println!(
75            "[{}] {} - failed to run proxy preflight check: {}",
76            style("risedev-preflight-check").bold(),
77            style("WARN").yellow().bold(),
78            e.as_report()
79        );
80    }
81
82    if let Err(e) = preflight_check_ulimit() {
83        println!(
84            "[{}] {} - failed to run ulimit preflight check: {}",
85            style("risedev-preflight-check").bold(),
86            style("WARN").yellow().bold(),
87            e.as_report()
88        );
89    }
90
91    Ok(())
92}