Skip to content

Commit 5436acf

Browse files
authored
feat(ci): integrate with cargo-dylint (#14713)
Signed-off-by: Bugen Zhao <[email protected]>
1 parent 5625492 commit 5436acf

File tree

19 files changed

+105
-22
lines changed

19 files changed

+105
-22
lines changed

Cargo.lock

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

ci/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
4848
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
4949
RUN cargo binstall -y --no-symlinks cargo-llvm-cov cargo-nextest cargo-hakari cargo-sort cargo-cache cargo-audit \
5050
51+
5152
5253
5354
&& cargo cache -a \

ci/build-ci-image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cat ../rust-toolchain
1010
# shellcheck disable=SC2155
1111

1212
# REMEMBER TO ALSO UPDATE ci/docker-compose.yml
13-
export BUILD_ENV_VERSION=v20240104_1
13+
export BUILD_ENV_VERSION=v20240122_1
1414

1515
export BUILD_TAG="public.ecr.aws/x5u3w5h6/rw-build-env:${BUILD_ENV_VERSION}"
1616

ci/docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ services:
7171
retries: 5
7272

7373
source-test-env:
74-
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240104_1
74+
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240122_1
7575
depends_on:
7676
- mysql
7777
- db
@@ -81,7 +81,7 @@ services:
8181
- ..:/risingwave
8282

8383
sink-test-env:
84-
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240104_1
84+
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240122_1
8585
depends_on:
8686
- mysql
8787
- db
@@ -93,12 +93,12 @@ services:
9393
- ..:/risingwave
9494

9595
rw-build-env:
96-
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240104_1
96+
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240122_1
9797
volumes:
9898
- ..:/risingwave
9999

100100
ci-flamegraph-env:
101-
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240104_1
101+
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240122_1
102102
# NOTE(kwannoel): This is used in order to permit
103103
# syscalls for `nperf` (perf_event_open),
104104
# so it can do CPU profiling.
@@ -109,7 +109,7 @@ services:
109109
- ..:/risingwave
110110

111111
regress-test-env:
112-
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240104_1
112+
image: public.ecr.aws/x5u3w5h6/rw-build-env:v20240122_1
113113
depends_on:
114114
db:
115115
condition: service_healthy

ci/scripts/check-dylint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# Exits as soon as any line fails.
4+
set -euo pipefail
5+
6+
source ci/scripts/common.sh
7+
unset RUSTC_WRAPPER # disable sccache, see https://github.com/mozilla/sccache/issues/861
8+
9+
echo "--- Run dylint check (dev, all features)"
10+
# Instead of `-D warnings`, we only deny warnings from our own lints. This is because...
11+
# - Warnings from `check` or `clippy` are already checked in `check.sh`.
12+
# - The toolchain used for linting could be slightly different from the one used to
13+
# compile RisingWave. Warnings from `rustc` itself may produce false positives.
14+
DYLINT_RUSTFLAGS="-A warnings -D rw_warnings" cargo dylint --all -- --all-targets --all-features --locked

ci/scripts/common.sh

100644100755
File mode changed.

ci/scripts/docker-hdfs.sh

100644100755
File mode changed.

ci/scripts/e2e-elasticsearch-sink-test.sh

100644100755
File mode changed.

ci/scripts/e2e-sink-test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ else
109109
fi
110110

111111
echo "--- testing elasticsearch sink"
112-
chmod +x ./ci/scripts/e2e-elasticsearch-sink-test.sh
113112
./ci/scripts/e2e-elasticsearch-sink-test.sh
114113
if [ $? -eq 0 ]; then
115114
echo "elasticsearch sink check passed"

ci/scripts/pr.env.sh

100644100755
File mode changed.

ci/workflows/pull-request.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,31 @@ steps:
370370
timeout_in_minutes: 25
371371
retry: *auto-retry
372372

373+
- label: "check dylint"
374+
command: "ci/scripts/check-dylint.sh"
375+
if: |
376+
!(build.pull_request.labels includes "ci/skip-ci") && build.env("CI_STEPS") == null
377+
|| build.pull_request.labels includes "ci/run-check"
378+
|| build.env("CI_STEPS") =~ /(^|,)check(,|$$)/
379+
plugins:
380+
- gencer/cache#v2.4.10:
381+
id: cache
382+
key: "v1-cache-{{ id }}-{{ runner.os }}-{{ checksum 'Cargo.lock' }}"
383+
restore-keys:
384+
- "v1-cache-{{ id }}-{{ runner.os }}-"
385+
- "v1-cache-{{ id }}-"
386+
backend: s3
387+
s3:
388+
bucket: ci-cache-bucket
389+
args: "--no-progress"
390+
paths:
391+
- ".cargo/advisory-db"
392+
- docker-compose#v4.9.0:
393+
run: rw-build-env
394+
config: ci/docker-compose.yml
395+
timeout_in_minutes: 25
396+
retry: *auto-retry
397+
373398
- label: "unit test (deterministic simulation)"
374399
command: "ci/scripts/deterministic-unit-test.sh"
375400
if: |

lints/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ name = "format_error"
1212
path = "ui/format_error.rs"
1313

1414
# See `README.md` before bumping the version.
15+
# Remember to update the version in `ci/Dockerfile` as well.
1516
[dependencies]
1617
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "6fd0258e45105161b7e759a22e7350958e5cb0b1" }
1718
dylint_linting = "2.6.0"

lints/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ See [cargo dylint](https://github.com/trailofbits/dylint) for more information.
77
## Install `cargo-dylint`
88

99
```bash
10-
cargo install dylint
10+
cargo install cargo-dylint dylint-link
1111
```
1212

1313
## Run lints

lints/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,39 @@ dylint_linting::dylint_library!();
3232
#[allow(clippy::no_mangle_with_rust_abi)]
3333
#[no_mangle]
3434
pub fn register_lints(_sess: &rustc_session::Session, lint_store: &mut rustc_lint::LintStore) {
35+
// -- Begin lint registration --
36+
37+
// Preparation steps.
3538
lint_store.register_early_pass(|| {
3639
Box::<utils::format_args_collector::FormatArgsCollector>::default()
3740
});
3841

42+
// Actual lints.
3943
lint_store.register_lints(&[format_error::FORMAT_ERROR]);
4044
lint_store.register_late_pass(|_| Box::<format_error::FormatError>::default());
45+
46+
// -- End lint registration --
47+
48+
// Register lints into groups.
49+
// Note: use `rw_` instead of `rw::` to avoid "error[E0602]: unknown lint tool: `rw`".
50+
register_group(lint_store, "rw_all", |_| true);
51+
register_group(lint_store, "rw_warnings", |l| {
52+
l.default_level >= rustc_lint::Level::Warn
53+
});
54+
}
55+
56+
fn register_group(
57+
lint_store: &mut rustc_lint::LintStore,
58+
name: &'static str,
59+
filter_predicate: impl Fn(&rustc_lint::Lint) -> bool,
60+
) {
61+
let lints = lint_store
62+
.get_lints()
63+
.iter()
64+
.filter(|l| l.name.starts_with("rw::"))
65+
.filter(|l| filter_predicate(l))
66+
.map(|l| rustc_lint::LintId::of(l))
67+
.collect();
68+
69+
lint_store.register_group(true, name, None, lints);
4170
}

src/frontend/src/handler/create_sql_function.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use risingwave_sqlparser::ast::{
2424
CreateFunctionBody, FunctionDefinition, ObjectName, OperateFunctionArg,
2525
};
2626
use risingwave_sqlparser::parser::{Parser, ParserError};
27+
use thiserror_ext::AsReport;
2728

2829
use super::*;
2930
use crate::binder::UdfContext;
@@ -176,9 +177,10 @@ pub async fn handle_create_sql_function(
176177

177178
if let Ok(expr) = UdfContext::extract_udf_expression(ast) {
178179
if let Err(e) = binder.bind_expr(expr) {
179-
return Err(ErrorCode::InvalidInputSyntax(
180-
format!("failed to conduct semantic check, please see if you are calling non-existence functions.\nDetailed error: {e}")
181-
)
180+
return Err(ErrorCode::InvalidInputSyntax(format!(
181+
"failed to conduct semantic check, please see if you are calling non-existence functions: {}",
182+
e.as_report()
183+
))
182184
.into());
183185
}
184186
} else {

src/meta/src/hummock/manager/checkpoint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use risingwave_hummock_sdk::version::HummockVersion;
2525
use risingwave_hummock_sdk::HummockVersionId;
2626
use risingwave_pb::hummock::hummock_version_checkpoint::{PbStaleObjects, StaleObjects};
2727
use risingwave_pb::hummock::{PbHummockVersionArchive, PbHummockVersionCheckpoint};
28+
use thiserror_ext::AsReport;
2829

2930
use crate::hummock::error::Result;
3031
use crate::hummock::manager::{read_lock, write_lock};
@@ -178,7 +179,8 @@ impl HummockManager {
178179
if let Some(archive) = archive {
179180
if let Err(e) = self.write_version_archive(&archive).await {
180181
tracing::warn!(
181-
"failed to write version archive {}, {e}",
182+
error = %e.as_report(),
183+
"failed to write version archive {}",
182184
archive.version.as_ref().unwrap().id
183185
);
184186
}

src/storage/src/monitor/traced_store.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use risingwave_hummock_trace::{
2323
init_collector, should_use_trace, ConcurrentId, MayTraceSpan, OperationResult, StorageType,
2424
TraceResult, TraceSpan, TracedBytes, TracedSealCurrentEpochOptions, LOCAL_ID,
2525
};
26+
use thiserror_ext::AsReport;
2627

2728
use super::identity;
2829
use crate::error::{StorageError, StorageResult};
@@ -357,7 +358,7 @@ impl<S: StateStoreIterItemStream> TracedStateStoreIter<S> {
357358
while let Some((key, value)) = inner
358359
.try_next()
359360
.await
360-
.inspect_err(|e| tracing::error!("Failed in next: {:?}", e))?
361+
.inspect_err(|e| tracing::error!(error = %e.as_report(), "Failed in next"))?
361362
{
362363
self.span.may_send_iter_next();
363364
self.span

src/tests/sqlsmith/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ risingwave_frontend = { workspace = true }
2828
risingwave_pb = { workspace = true }
2929
risingwave_sqlparser = { workspace = true }
3030
similar = "2.4.0"
31+
thiserror-ext = { workspace = true }
3132
tokio = { version = "0.2", package = "madsim-tokio" }
3233
tokio-postgres = "0.7"
3334
tracing = "0.1"

src/tests/sqlsmith/tests/frontend/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use risingwave_sqlparser::ast::Statement;
2828
use risingwave_sqlsmith::{
2929
is_permissible_error, mview_sql_gen, parse_create_table_statements, parse_sql, sql_gen, Table,
3030
};
31+
use thiserror_ext::AsReport;
3132
use tokio::runtime::Runtime;
3233

3334
type Result<T> = std::result::Result<T, Failed>;
@@ -48,7 +49,7 @@ async fn handle(session: Arc<SessionImpl>, stmt: Statement, sql: Arc<str>) -> Re
4849
let result = handler::handle(session.clone(), stmt, sql, vec![])
4950
.await
5051
.map(|_| ())
51-
.map_err(|e| format!("Error Reason:\n{}", e).into());
52+
.map_err(|e| format!("Error Reason:\n{}", e.as_report()).into());
5253
validate_result(result)
5354
}
5455

@@ -183,20 +184,26 @@ fn run_batch_query(
183184
let mut binder = Binder::new(&session);
184185
let bound = binder
185186
.bind(stmt)
186-
.map_err(|e| Failed::from(format!("Failed to bind:\nReason:\n{}", e)))?;
187+
.map_err(|e| Failed::from(format!("Failed to bind:\nReason:\n{}", e.as_report())))?;
187188
let mut planner = Planner::new(context);
188-
let mut logical_plan = planner
189-
.plan(bound)
190-
.map_err(|e| Failed::from(format!("Failed to generate logical plan:\nReason:\n{}", e)))?;
191-
let batch_plan = logical_plan
192-
.gen_batch_plan()
193-
.map_err(|e| Failed::from(format!("Failed to generate batch plan:\nReason:\n{}", e)))?;
189+
let mut logical_plan = planner.plan(bound).map_err(|e| {
190+
Failed::from(format!(
191+
"Failed to generate logical plan:\nReason:\n{}",
192+
e.as_report()
193+
))
194+
})?;
195+
let batch_plan = logical_plan.gen_batch_plan().map_err(|e| {
196+
Failed::from(format!(
197+
"Failed to generate batch plan:\nReason:\n{}",
198+
e.as_report()
199+
))
200+
})?;
194201
logical_plan
195202
.gen_batch_distributed_plan(batch_plan)
196203
.map_err(|e| {
197204
Failed::from(format!(
198205
"Failed to generate batch distributed plan:\nReason:\n{}",
199-
e
206+
e.as_report()
200207
))
201208
})?;
202209
Ok(())

0 commit comments

Comments
 (0)