Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create gitlab pipeline #534

Merged
merged 45 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
91128a6
add badge to readme
alvicsam Oct 19, 2021
9e251a8
first version of pipeline
alvicsam Oct 19, 2021
93fc653
Update .gitlab-ci.yml
alvicsam Oct 19, 2021
5262318
add pre-cache script
alvicsam Oct 19, 2021
a24b9bb
fmt and clippy stable
alvicsam Oct 19, 2021
7e3fe6d
add check and test
alvicsam Oct 21, 2021
e6c8358
remove output text file from bench
alvicsam Oct 21, 2021
5b35d10
Update scripts/ci/pre_cache.sh
alvicsam Oct 22, 2021
becbdf0
Update .gitlab-ci.yml
alvicsam Oct 22, 2021
68b72ca
small fix
alvicsam Oct 22, 2021
20589ea
fix test and schedule
alvicsam Nov 9, 2021
c6c443b
CI: verbose is a surplus
TriplEight Nov 4, 2021
b2a0c9f
CI: separately check rustdoc linx
TriplEight Nov 4, 2021
8cd5e48
fix refs
alvicsam Nov 9, 2021
0aaee60
add bench to gh-pages
alvicsam Nov 9, 2021
a9175ec
fix refs
alvicsam Nov 9, 2021
0408012
fix benchmarks
alvicsam Nov 10, 2021
9588b80
added vault to ci
alvicsam Nov 10, 2021
abe5dc7
fix vars
alvicsam Nov 10, 2021
95af7a8
comment bench
alvicsam Nov 10, 2021
80ce0af
fix benches name
alvicsam Nov 12, 2021
0cf9290
added script to push benchmark results to VM
alvicsam Nov 15, 2021
da23d5e
make script executable
alvicsam Nov 15, 2021
99ddccd
change bench psuh executor
alvicsam Nov 15, 2021
f284330
changed benchmark task to run on a dedicated node pool
alvicsam Nov 16, 2021
e3809cd
change prometheus metric name for benchmarks
alvicsam Nov 24, 2021
c44422d
send 2 metrics with benchmark results
alvicsam Nov 25, 2021
9f944f1
disable non-schedule jobs from schedule run
alvicsam Nov 25, 2021
6cf75c9
empty commit for benchmark test
alvicsam Nov 25, 2021
bede6bb
change metric name
alvicsam Nov 25, 2021
a5ce28e
empty commit for benchmark test
alvicsam Nov 25, 2021
cf0ae9f
empty commit for benchmark test
alvicsam Nov 26, 2021
39adb0f
add cirunner label to vm metric
alvicsam Nov 26, 2021
a6d6258
split vm metric to 2 metrics
alvicsam Nov 26, 2021
5b7f149
change runner description to runner tag in ci scripts
alvicsam Nov 26, 2021
18bfe81
add pass runner tags from benchmark to publish job
alvicsam Nov 29, 2021
864b89b
change runner tag to runner description
alvicsam Nov 29, 2021
ccd8f7d
add debug message
alvicsam Nov 29, 2021
51d4ca9
empty commit for test
alvicsam Nov 29, 2021
7f76577
empty commit for test
alvicsam Nov 29, 2021
4e214fb
Update .scripts/ci/push_bench_results.sh
alvicsam Nov 30, 2021
b0163ba
add defaults, remove dups, change ci image for publish-bench
alvicsam Nov 30, 2021
4ffeeac
remove pre_cache.sh
alvicsam Nov 30, 2021
9b4b815
move interruptible to defaults
alvicsam Dec 2, 2021
bd12ab4
add issue to fixme comment
alvicsam Dec 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
default:
alvicsam marked this conversation as resolved.
Show resolved Hide resolved
interruptible: true
retry:
max: 2
when:
- runner_system_failure
- unknown_failure
- api_failure

stages:
- lint
- test
- benchmark
- publish

variables: &default-vars
GIT_STRATEGY: fetch
GIT_DEPTH: 100
CARGO_INCREMENTAL: 0
CARGO_TARGET_DIR: "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
CI_IMAGE: "paritytech/ci-linux:production"
VAULT_SERVER_URL: "https://vault.parity-mgmt-vault.parity.io"
VAULT_AUTH_PATH: "gitlab-parity-io-jwt"
VAULT_AUTH_ROLE: "cicd_gitlab_parity_${CI_PROJECT_NAME}"

.vault-secrets: &vault-secrets
secrets:
GITHUB_TOKEN:
vault: cicd/gitlab/parity/GITHUB_TOKEN@kv
file: false
GITHUB_USER:
vault: cicd/gitlab/parity/GITHUB_USER@kv
file: false

.common-refs: &common-refs
rules:
- if: $CI_PIPELINE_SOURCE == "web"
- if: $CI_COMMIT_REF_NAME == "main"
- if: $CI_COMMIT_REF_NAME == "master"
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs

# run nightly by schedule
.schedule-refs: &schedule-refs
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"

.rust-info-script: &rust-info-script
- rustup show
- cargo --version
- rustup +nightly show
- cargo +nightly --version
- bash --version
- sccache -s

.docker-env: &docker-env
image: "${CI_IMAGE}"
before_script:
- *rust-info-script
- sccache -s
tags:
- linux-docker

.kubernetes-env: &kubernetes-env
image: "${CI_IMAGE}"
tags:
- kubernetes-parity-build

.collect-artifacts: &collect-artifacts
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
when: on_success
expire_in: 28 days
paths:
- ./artifacts/
reports:
dotenv: runner.env
#### stage: lint

fmt:
stage: lint
<<: *docker-env
<<: *common-refs
script:
# FIXME: remove after stable fmt added to ci-linux
- rustup component add rustfmt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't the rustfmt component part of the base image? Seems like setting up the toolchain components should be in a single place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, we run cargo fmt from the nightly release in other repos. I'll add comment here to fix it later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I guess the question still stands though: wherever you install the nightly toolchain could be a good place to add the rustfmt component as well? And then run cargo +nightly fmt here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dvdplm We have nightly fmt installed.
I guess you mean that you're OK with cargo +nightly fmt running here, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer cargo fmt from stable, but cargo +nightly fmt works too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a big deal, we can add it to the CI image for stable, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added clippy and fmt to the image however need to wait while issue in substrate is fixed

- cargo fmt --all -- --check

clippy:
stage: lint
<<: *docker-env
<<: *common-refs
script:
# FIXME: remove after stable clippy added to ci-linux
- rustup component add clippy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dvdplm We have nightly clippy installed.
I guess you mean that you're OK with cargo +nightly clippy --all-targets running here, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, I prefer CI to use stable but yes, I'm ok running nightly clippy too. Curious though, why is clippy not included in the base image?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean paritytech/base-ci-linux? It was never requested before to run a stable clippy or fmt.

- cargo clippy --all-targets

check-rustdoc-links:
stage: lint
<<: *docker-env
<<: *common-refs
script:
- RUSTDOCFLAGS="--deny broken_intra_doc_links" cargo doc --workspace --no-deps --document-private-items

#### stage: test

check-code:
TriplEight marked this conversation as resolved.
Show resolved Hide resolved
stage: test
<<: *docker-env
<<: *common-refs
script:
- cargo install cargo-hack
- cargo hack check --workspace --each-feature
alvicsam marked this conversation as resolved.
Show resolved Hide resolved

test:
alvicsam marked this conversation as resolved.
Show resolved Hide resolved
stage: test
<<: *docker-env
<<: *common-refs
script:
- cargo test

benchmarks:
alvicsam marked this conversation as resolved.
Show resolved Hide resolved
stage: benchmark
<<: *docker-env
<<: *collect-artifacts
<<: *schedule-refs
script:
- cargo bench -p jsonrpsee-benchmarks -- --output-format bencher | tee output.txt
- mkdir artifacts
- cp output.txt artifacts/
- echo ${CI_RUNNER_DESCRIPTION}
- echo "RUNNER_NAME=${CI_RUNNER_DESCRIPTION}" > runner.env
tags:
- linux-docker-benches

publish-bench:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to use paritytech/ci-linux here? It's better off with a lighter paritytech/tools

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better off with a lighter paritytech/tools

Agree, fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then it maybe makes sense to remove that default image from k8s anchor.

Copy link
Contributor Author

@alvicsam alvicsam Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep k8s anchor as it is so it is equal through all our .gitlab-ci.yml files in different repos

stage: publish
variables:
CI_IMAGE: "paritytech/tools:latest"
<<: *kubernetes-env
<<: *schedule-refs
needs:
- job: benchmarks
artifacts: true
script:
- echo $RUNNER_NAME
- .scripts/ci/push_bench_results.sh artifacts/output.txt

28 changes: 28 additions & 0 deletions .scripts/ci/push_bench_results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# The script takes output.txt, removes every line that doesn't have "test"
# in it and pushes benchmark result to Victoria Metrics
# Benchmark name should have underscores in the name instead of spaces (e.g. async/http_concurrent_round_trip/8)

RESULT_FILE=$1
CURRENT_DIR=$(pwd)

if [ -z "$RESULT_FILE" ]
then
RESULT_FILE="output.txt"
fi

cat $RESULT_FILE | grep test > $CURRENT_DIR/output_redacted.txt

INPUT="output_redacted.txt"

while IFS= read -r line
do
BENCH_NAME=$(echo $line | cut -f 2 -d ' ')
BENCH_RESULT=$(echo $line | cut -f 5 -d ' ')
# send metric with common results
curl -d 'parity_benchmark_common_result_ns{project="'${CI_PROJECT_NAME}'",benchmark="'$BENCH_NAME'"} '$BENCH_RESULT'' \
-X POST 'http://vm-longterm.parity-build.parity.io/api/v1/import/prometheus'
# send metric with detailed results
curl -d 'parity_benchmark_specific_result_ns{project="'${CI_PROJECT_NAME}'",benchmark="'$BENCH_NAME'",commit="'${CI_COMMIT_SHORT_SHA}'",cirunner="'${RUNNER_NAME}'"} '$BENCH_RESULT'' \
-X POST 'http://vm-longterm.parity-build.parity.io/api/v1/import/prometheus'
done < "$INPUT"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![GitLab Status](https://gitlab.parity.io/parity/jsonrpsee/badges/master/pipeline.svg)](https://gitlab.parity.io/parity/jsonrpsee/pipelines)

# jsonrpsee

JSON-RPC library designed for async/await in Rust.
Expand Down
6 changes: 3 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ trait RequestBencher {
let rt = TokioRuntime::new().unwrap();
let (url, _server) = rt.block_on(helpers::http_server(rt.handle().clone()));
let client = Arc::new(HttpClientBuilder::default().max_concurrent_requests(1024 * 1024).build(&url).unwrap());
run_round_trip_with_batch(&rt, crit, client, "http batch requests", Self::REQUEST_TYPE);
run_round_trip_with_batch(&rt, crit, client, "http_batch_requests", Self::REQUEST_TYPE);
}

fn websocket_requests(crit: &mut Criterion) {
Expand All @@ -113,7 +113,7 @@ trait RequestBencher {
let (url, _server) = rt.block_on(helpers::ws_server(rt.handle().clone()));
let client =
Arc::new(rt.block_on(WsClientBuilder::default().max_concurrent_requests(1024 * 1024).build(&url)).unwrap());
run_round_trip_with_batch(&rt, crit, client, "ws batch requests", Self::REQUEST_TYPE);
run_round_trip_with_batch(&rt, crit, client, "ws_batch_requests", Self::REQUEST_TYPE);
}

fn subscriptions(crit: &mut Criterion) {
Expand Down Expand Up @@ -188,7 +188,7 @@ fn run_sub_round_trip(rt: &TokioRuntime, crit: &mut Criterion, client: Arc<impl
});
}

/// Benchmark http batch requests over batch sizes of 2, 5, 10, 50 and 100 RPCs in each batch.
/// Benchmark http_batch_requests over batch sizes of 2, 5, 10, 50 and 100 RPCs in each batch.
fn run_round_trip_with_batch(
rt: &TokioRuntime,
crit: &mut Criterion,
Expand Down