Skip to content

Commit

Permalink
Merge branch 'main' into lock_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dantengsky authored Dec 20, 2023
2 parents 85c5d12 + c76b37e commit 0f2d619
Show file tree
Hide file tree
Showing 266 changed files with 4,263 additions and 4,573 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ Databend thrives on community contributions! Whether it's through ideas, code, o

Here are some resources to help you get started:

- [Building Databend From Source](https://docs.databend.com/doc/contributing/building-from-source)
- [The First Good Pull Request](https://docs.databend.com/doc/contributing/good-pr)
- [Building Databend From Source](https://docs.databend.com/doc/overview/community/contributor/building-from-source)
- [The First Good Pull Request](https://docs.databend.com/doc/overview/community/contributor/good-pr)


## 👥 Community
Expand Down
2 changes: 1 addition & 1 deletion src/common/arrow/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/base/tests/it/fixed_heap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/base/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/base/tests/it/pool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/base/tests/it/progress.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/base/tests/it/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/base/tests/it/stoppable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/cache/tests/it/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/cache/tests/it/cache/lru.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/cache/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/grpc/tests/it/dns_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/grpc/tests/it/grpc_token.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/grpc/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/hashtable/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/http/tests/it/health.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/http/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/io/tests/it/binary_read.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/io/tests/it/binary_write.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/io/tests/it/bincode_serialization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/io/tests/it/borsh_serialization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/io/tests/it/cursor_ext/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/io/tests/it/escape.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/io/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(cursor_remaining)]
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/metrics/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/common/storage/tests/it/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Datafuse Labs.
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions src/common/tracing/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use minitrace::prelude::*;
use serde_json::Map;

use crate::loggers::new_file_log_writer;
use crate::loggers::new_otlp_log_writer;
use crate::loggers::MinitraceLogger;
use crate::loggers::OpenTelemetryLogger;
use crate::Config;

const HEADER_TRACE_PARENT: &str = "traceparent";
Expand Down Expand Up @@ -176,7 +176,7 @@ pub fn init_logging(
let mut labels = labels.clone();
labels.insert("category".to_string(), "system".to_string());
labels.extend(cfg.otlp.labels.clone());
let logger = new_otlp_log_writer(&cfg.otlp.endpoint, labels);
let logger = OpenTelemetryLogger::new(log_name, &cfg.otlp.endpoint, labels);
let dispatch = fern::Dispatch::new()
.level(cfg.otlp.level.parse().unwrap_or(LevelFilter::Info))
.format(formatter("json"))
Expand Down Expand Up @@ -211,7 +211,7 @@ pub fn init_logging(
let mut labels = labels.clone();
labels.insert("category".to_string(), "query".to_string());
labels.extend(cfg.query.labels.clone());
let logger = new_otlp_log_writer(&cfg.query.otlp_endpoint, labels);
let logger = OpenTelemetryLogger::new(log_name, &cfg.query.otlp_endpoint, labels);
query_logger = query_logger.chain(Box::new(logger) as Box<dyn Log>);
}
}
Expand All @@ -229,7 +229,7 @@ pub fn init_logging(
let mut labels = labels.clone();
labels.insert("category".to_string(), "profile".to_string());
labels.extend(cfg.profile.labels.clone());
let logger = new_otlp_log_writer(&cfg.profile.otlp_endpoint, labels);
let logger = OpenTelemetryLogger::new(log_name, &cfg.profile.otlp_endpoint, labels);
profile_logger = profile_logger.chain(Box::new(logger) as Box<dyn Log>);
}
}
Expand Down
86 changes: 44 additions & 42 deletions src/common/tracing/src/loggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use std::time::Duration;
use std::time::SystemTime;

use opentelemetry::logs::AnyValue;
use opentelemetry::logs::Logger as _;
use opentelemetry::logs::Logger;
use opentelemetry::logs::LoggerProvider;
use opentelemetry::logs::Severity;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::logs::Logger;
use tracing_appender::non_blocking::NonBlocking;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_appender::rolling::RollingFileAppender;
Expand Down Expand Up @@ -96,39 +96,48 @@ impl log::Log for MinitraceLogger {
fn flush(&self) {}
}

pub(crate) struct OpenTelemetryOTLPLogWriter {
logger: Logger,
pub(crate) struct OpenTelemetryLogger {
logger: opentelemetry_sdk::logs::Logger,
// keep provider alive
provider: opentelemetry_sdk::logs::LoggerProvider,
}

pub(crate) fn new_otlp_log_writer(
endpoint: &str,
labels: BTreeMap<String, String>,
) -> OpenTelemetryOTLPLogWriter {
let kvs = labels
.into_iter()
.map(|(k, v)| opentelemetry::KeyValue::new(k, v))
.collect::<Vec<_>>();
let log_config = opentelemetry_sdk::logs::Config {
resource: Cow::Owned(opentelemetry::sdk::Resource::new(kvs)),
};
let export_config = opentelemetry_otlp::ExportConfig {
endpoint: endpoint.to_string(),
protocol: opentelemetry_otlp::Protocol::Grpc,
timeout: Duration::from_secs(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT),
};
let exporter = opentelemetry_otlp::new_exporter()
.tonic()
.with_export_config(export_config);
let logger = opentelemetry_otlp::new_pipeline()
.logging()
.with_exporter(exporter)
.with_log_config(log_config)
.install_batch(opentelemetry_sdk::runtime::Tokio)
.expect("install query log otlp pipeline");
OpenTelemetryOTLPLogWriter { logger }
impl OpenTelemetryLogger {
pub(crate) fn new(
name: impl ToString,
endpoint: &str,
labels: BTreeMap<String, String>,
) -> Self {
let kvs = labels
.into_iter()
.map(|(k, v)| opentelemetry::KeyValue::new(k, v))
.collect::<Vec<_>>();
let export_config = opentelemetry_otlp::ExportConfig {
endpoint: endpoint.to_string(),
protocol: opentelemetry_otlp::Protocol::Grpc,
timeout: Duration::from_secs(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT),
};
let exporter_builder: opentelemetry_otlp::LogExporterBuilder =
opentelemetry_otlp::new_exporter()
.tonic()
.with_export_config(export_config)
.into();
let exporter = exporter_builder
.build_log_exporter()
.expect("build log exporter");
let provider = opentelemetry_sdk::logs::LoggerProvider::builder()
.with_batch_exporter(exporter, opentelemetry_sdk::runtime::Tokio)
.with_config(
opentelemetry_sdk::logs::Config::default()
.with_resource(opentelemetry_sdk::Resource::new(kvs)),
)
.build();
let logger = provider.versioned_logger(name.to_string(), None, None, None);
Self { logger, provider }
}
}

impl log::Log for OpenTelemetryOTLPLogWriter {
impl log::Log for OpenTelemetryLogger {
fn enabled(&self, _metadata: &log::Metadata<'_>) -> bool {
// we handle level and target filter with fern
true
Expand All @@ -144,17 +153,10 @@ impl log::Log for OpenTelemetryOTLPLogWriter {
}

fn flush(&self) {
match self.logger.provider() {
Some(provider) => {
let result = provider.force_flush();
for r in result {
if let Err(e) = r {
eprintln!("flush log failed: {}", e);
}
}
}
None => {
eprintln!("flush log failed: logger provider is None");
let result = self.provider.force_flush();
for r in result {
if let Err(e) = r {
eprintln!("flush log failed: {}", e);
}
}
}
Expand Down
Loading

0 comments on commit 0f2d619

Please sign in to comment.