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

chore: specify format rules #149

Merged
merged 11 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ jobs:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy
- name: Install taplo-cli from crates.io
uses: baptiste0928/cargo-install@v2
with:
crate: taplo-cli
version: "0.6"
- name: Check format
if: matrix.rust == 'nightly'
run: cargo fmt --all -- --check
- name: Check Cargo.toml format
if: matrix.rust == 'nightly'
run: taplo fmt --check
- name: Lints
if: matrix.rust == 'nightly'
run: cargo clippy --all-targets --all-features -- --deny warnings
- name: Build
run: cargo build --workspace --all-targets
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"minitrace",
"minitrace-macro",
Expand Down
6 changes: 3 additions & 3 deletions minitrace-datadog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "minitrace-datadog"
version = "0.4.1"
authors = ["The TiKV Project Authors"]
license = "Apache-2.0"
edition = "2018"
edition = "2021"
description = "Datadog reporter for minitrace-rust"
homepage = "https://github.com/tikv/minitrace-rust"
repository = "https://github.com/tikv/minitrace-rust"
Expand All @@ -12,10 +12,10 @@ readme = "README.md"
keywords = ["tracing", "span", "datadog", "jaeger", "opentracing"]

[dependencies]
minitrace = { path = "../minitrace" }
minitrace = { version = "0.4.1", path = "../minitrace" }
reqwest = { version = "0.11", features = ["blocking"] }
rmp-serde = "1"
serde = { version = "1", features = ["derive"] }
reqwest = { version = "0.11", features = ["blocking"] }

[dev-dependencies]
futures = "0.3"
4 changes: 2 additions & 2 deletions minitrace-jaeger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "minitrace-jaeger"
version = "0.4.1"
authors = ["The TiKV Project Authors"]
license = "Apache-2.0"
edition = "2018"
edition = "2021"
description = "Jaeger reporter for minitrace-rust"
homepage = "https://github.com/tikv/minitrace-rust"
repository = "https://github.com/tikv/minitrace-rust"
Expand All @@ -12,7 +12,7 @@ readme = "README.md"
keywords = ["tracing", "span", "datadog", "jaeger", "opentracing"]

[dependencies]
minitrace = { path = "../minitrace" }
minitrace = { version = "0.4.1", path = "../minitrace" }
thrift_codec = "0.2"
tokio = { version = "1", features = ["net"] }

Expand Down
10 changes: 7 additions & 3 deletions minitrace-jaeger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ use minitrace::prelude::*;
use thrift_codec::message::Message;
use thrift_codec::CompactEncode;

use crate::thrift::{
Batch, EmitBatchNotification, Process, Span as JaegerSpan, SpanRef, SpanRefKind, Tag,
};
use crate::thrift::Batch;
use crate::thrift::EmitBatchNotification;
use crate::thrift::Process;
use crate::thrift::Span as JaegerSpan;
use crate::thrift::SpanRef;
use crate::thrift::SpanRefKind;
use crate::thrift::Tag;

pub fn encode(
service_name: String,
Expand Down
4 changes: 3 additions & 1 deletion minitrace-jaeger/src/thrift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
//!
//! [jaeger.thrift]: https://github.com/uber/jaeger-idl/blob/master/thrift/jaeger.thrift

use thrift_codec::data::{Field, List, Struct};
use thrift_codec::data::Field;
use thrift_codec::data::List;
use thrift_codec::data::Struct;
use thrift_codec::message::Message;

#[derive(Debug, Clone)]
Expand Down
12 changes: 6 additions & 6 deletions minitrace-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "minitrace-macro"
version = "0.4.1"
authors = ["The TiKV Project Authors"]
license = "Apache-2.0"
edition = "2018"
edition = "2021"
description = "Attribute procedural macro for minitrace-rust"
homepage = "https://github.com/tikv/minitrace-rust"
repository = "https://github.com/tikv/minitrace-rust"
Expand All @@ -16,12 +16,12 @@ proc-macro = true

[dependencies]
# The macro `quote_spanned!` is added to syn in 1.0.84
syn = { version = "1.0.84", features = ["full", "parsing", "extra-traits", "proc-macro", "visit-mut"] }
quote = "1"
proc-macro2 = "1"
proc-macro-error = "1"
proc-macro2 = "1"
quote = "1"
syn = { version = "1.0.84", features = ["full", "parsing", "extra-traits", "proc-macro", "visit-mut"] }

[dev-dependencies]
trybuild = "1"
minitrace = "0.4.0"
minitrace = { version = "0.4.1", path = "../minitrace" }
tokio = { version = "1", features = ["full"] }
trybuild = "1"
11 changes: 8 additions & 3 deletions minitrace-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ extern crate proc_macro;
#[macro_use]
extern crate proc_macro_error;

use proc_macro2::Span;
use proc_macro2::TokenStream;
use proc_macro2::{Span, TokenTree};
use quote::{format_ident, quote_spanned};
use proc_macro2::TokenTree;
use quote::format_ident;
use quote::quote_spanned;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{punctuated::Punctuated, visit_mut::VisitMut, Ident, *};
use syn::visit_mut::VisitMut;
use syn::Ident;
use syn::*;

struct Args {
event: String,
Expand Down
30 changes: 15 additions & 15 deletions minitrace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "minitrace"
version = "0.4.1"
authors = ["The TiKV Project Authors"]
license = "Apache-2.0"
edition = "2018"
edition = "2021"
description = "A high-performance timeline tracing library for Rust"
homepage = "https://github.com/tikv/minitrace-rust"
repository = "https://github.com/tikv/minitrace-rust"
Expand All @@ -12,11 +12,11 @@ readme = "../README.md"
keywords = ["tracing", "span", "datadog", "jaeger", "opentracing"]

[dependencies]
futures = "0.3"
minitrace-macro = { version = "0.4.1", path = "../minitrace-macro" }
minstant = "0.1"
minitrace-macro = { path = "../minitrace-macro" }
pin-project = "1.0"
parking_lot = "0.12"
futures = "0.3"
pin-project = "1.0"
# TODO: Remove once_cell once #![feature(once_cell)] is stabilized
once_cell = "1"

Expand All @@ -25,22 +25,22 @@ once_cell = "1"
async-trait = "0.1.52"
criterion = { version = "0.4", features = ["html_reports"] }
crossbeam = "0.8"
minitrace-jaeger = { path = "../minitrace-jaeger" }
minitrace-datadog = { path = "../minitrace-datadog" }
tokio = { version = "1", features = ["rt", "time", "macros"] }
rustracing = "0.6"
env_logger = "0.10"
futures = "0.3"
futures-timer = "3"
log = "0.4"
minitrace-datadog = { version = "0.4.1", path = "../minitrace-datadog" }
minitrace-jaeger = { version = "0.4.1", path = "../minitrace-jaeger" }
mockall = "0.11"
opentelemetry = { version = "0.18", default-features = false, features = ["trace"] }
opentelemetry-jaeger = "0.17"
tracing-opentelemetry = "0.18"
rand = "0.8"
rustracing = "0.6"
tokio = { version = "1", features = ["rt", "time", "macros"] }
tracing = "0.1"
tracing-core = "0.1"
tracing-opentelemetry = "0.18"
tracing-subscriber = "0.3"
rand = "0.8"
futures = "0.3"
futures-timer = "3"
mockall = "0.11"
log = "0.4"
env_logger = "0.10"

[[bench]]
name = "trace"
Expand Down
4 changes: 3 additions & 1 deletion minitrace/benches/compare.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.

use criterion::{criterion_group, criterion_main, Criterion};
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;

fn init_opentelemetry() {
use tracing_subscriber::prelude::*;
Expand Down
5 changes: 4 additions & 1 deletion minitrace/benches/object_pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0.

use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::BatchSize;
use criterion::Criterion;
use minitrace::util::object_pool::Pool;

fn bench_alloc_vec(c: &mut Criterion) {
Expand Down
4 changes: 3 additions & 1 deletion minitrace/benches/spsc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0.

use criterion::{criterion_group, criterion_main, Criterion};
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;

fn crossbeam(nmsg: usize) {
let (tx, rx) = crossbeam::channel::bounded(10240);
Expand Down
5 changes: 4 additions & 1 deletion minitrace/benches/trace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::black_box;
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
use minitrace::local::LocalCollector;
use minitrace::prelude::*;

Expand Down
4 changes: 3 additions & 1 deletion minitrace/src/collector/command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0.

use crate::collector::{CollectArgs, SpanRecord, SpanSet};
use crate::collector::CollectArgs;
use crate::collector::SpanRecord;
use crate::collector::SpanSet;
use crate::util::CollectToken;

pub enum CollectCommand {
Expand Down
67 changes: 40 additions & 27 deletions minitrace/src/collector/global_collector.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.

use crate::collector::command::{
CollectCommand, CommitCollect, DropCollect, StartCollect, SubmitSpans,
};
use crate::collector::{CollectArgs, SpanRecord, SpanSet};
use crate::local::raw_span::RawSpan;
use crate::local::span_id::SpanId;
use crate::local::LocalSpans;
use crate::util::spsc::{self, Receiver, Sender};
use crate::util::CollectToken;

use std::collections::HashMap;
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::time::Duration;

use minstant::Anchor;
use once_cell::sync::Lazy;
use parking_lot::Mutex;

use crate::collector::command::CollectCommand;
use crate::collector::command::CommitCollect;
use crate::collector::command::DropCollect;
use crate::collector::command::StartCollect;
use crate::collector::command::SubmitSpans;
use crate::collector::CollectArgs;
use crate::collector::SpanRecord;
use crate::collector::SpanSet;
use crate::local::raw_span::RawSpan;
use crate::local::span_id::SpanId;
use crate::local::LocalSpans;
use crate::util::spsc::Receiver;
use crate::util::spsc::Sender;
use crate::util::spsc::{self};
use crate::util::CollectToken;

const COLLECT_LOOP_INTERVAL: Duration = Duration::from_millis(10);

static NEXT_COLLECT_ID: AtomicU32 = AtomicU32::new(0);
Expand Down Expand Up @@ -128,10 +135,14 @@ impl GlobalCollector {
fn start() -> Self {
std::thread::Builder::new()
.name("minitrace".to_string())
.spawn(move || loop {
let begin_instant = std::time::Instant::now();
GLOBAL_COLLECTOR.lock().handle_commands();
std::thread::sleep(COLLECT_LOOP_INTERVAL.saturating_sub(begin_instant.elapsed()));
.spawn(move || {
loop {
let begin_instant = std::time::Instant::now();
GLOBAL_COLLECTOR.lock().handle_commands();
std::thread::sleep(
COLLECT_LOOP_INTERVAL.saturating_sub(begin_instant.elapsed()),
);
}
})
.unwrap();

Expand Down Expand Up @@ -161,18 +172,20 @@ impl GlobalCollector {
let commit_collects = &mut self.commit_collects;
let submit_spans = &mut self.submit_spans;

self.rxs.retain_mut(|rx| loop {
match rx.try_recv() {
Ok(Some(CollectCommand::StartCollect(cmd))) => start_collects.push(cmd),
Ok(Some(CollectCommand::DropCollect(cmd))) => drop_collects.push(cmd),
Ok(Some(CollectCommand::CommitCollect(cmd))) => commit_collects.push(cmd),
Ok(Some(CollectCommand::SubmitSpans(cmd))) => submit_spans.push(cmd),
Ok(None) => {
return true;
}
Err(_) => {
// Channel disconnected. It must be because the sender thread has stopped.
return false;
self.rxs.retain_mut(|rx| {
loop {
match rx.try_recv() {
Ok(Some(CollectCommand::StartCollect(cmd))) => start_collects.push(cmd),
Ok(Some(CollectCommand::DropCollect(cmd))) => drop_collects.push(cmd),
Ok(Some(CollectCommand::CommitCollect(cmd))) => commit_collects.push(cmd),
Ok(Some(CollectCommand::SubmitSpans(cmd))) => submit_spans.push(cmd),
Ok(None) => {
return true;
}
Err(_) => {
// Channel disconnected. It must be because the sender thread has stopped.
return false;
}
}
}
});
Expand Down
Loading