Skip to content

Commit aa3dc39

Browse files
committed
init
1 parent 06d5848 commit aa3dc39

File tree

11 files changed

+202
-4
lines changed

11 files changed

+202
-4
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ members = [
114114
"src/bendsave",
115115
"src/bendpy",
116116
"src/meta/app-storage",
117+
"src/common/telemetry",
117118
]
118119

119120
# Workspace dependencies
@@ -172,6 +173,7 @@ databend-common-settings = { path = "src/query/settings" }
172173
databend-common-sql = { path = "src/query/sql" }
173174
databend-common-sqlsmith = { path = "src/tests/sqlsmith" }
174175
databend-common-storage = { path = "src/common/storage" }
176+
databend-common-telemetry = { path = "src/common/telemetry" }
175177
databend-common-storages-delta = { path = "src/query/storages/delta" }
176178
databend-common-storages-factory = { path = "src/query/storages/factory" }
177179
databend-common-storages-fuse = { path = "src/query/storages/fuse" }

src/common/telemetry/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "databend-common-telemetry"
3+
version = { workspace = true }
4+
authors = { workspace = true }
5+
license = { workspace = true }
6+
publish = { workspace = true }
7+
edition = { workspace = true }
8+
9+
[dependencies]
10+
num_cpus = { workspace = true }
11+
reqwest = { workspace = true, features = ["json", "rustls-tls"] }
12+
serde_json = { workspace = true }
13+
tokio = { workspace = true }

src/common/telemetry/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2021 Datafuse 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+
15+
pub mod simple;
16+
17+
pub use simple::report_node_telemetry;

src/common/telemetry/src/simple.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2021 Datafuse 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+
15+
use std::time::Duration;
16+
17+
// No license check needed here - done by caller
18+
19+
// Fixed telemetry endpoint - not configurable by users
20+
const TELEMETRY_ENDPOINT: &str = "https://telemetry.databend.com/v1/report";
21+
22+
pub async fn report_node_telemetry(payload: serde_json::Value) {
23+
let client = match reqwest::Client::builder()
24+
.timeout(Duration::from_secs(3))
25+
.connect_timeout(Duration::from_secs(2))
26+
.build()
27+
{
28+
Ok(client) => client,
29+
Err(_) => return,
30+
};
31+
32+
let version = payload
33+
.get("version")
34+
.and_then(|v| v.as_str())
35+
.unwrap_or("unknown");
36+
37+
let _ = tokio::time::timeout(
38+
Duration::from_secs(3),
39+
client
40+
.post(TELEMETRY_ENDPOINT)
41+
.header("Content-Type", "application/json")
42+
.header("User-Agent", format!("Databend/{}", version))
43+
.json(&payload)
44+
.send(),
45+
)
46+
.await;
47+
}

src/query/config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ databend-common-exception = { workspace = true }
2323
databend-common-grpc = { workspace = true }
2424
databend-common-meta-app = { workspace = true }
2525
databend-common-storage = { workspace = true }
26+
databend-common-telemetry = { workspace = true }
2627
databend-common-tracing = { workspace = true }
2728
log = { workspace = true }
2829
serde = { workspace = true }

src/query/config/src/config.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use databend_common_tracing::FileConfig as InnerFileLogConfig;
4848
use databend_common_tracing::HistoryConfig as InnerHistoryConfig;
4949
use databend_common_tracing::HistoryTableConfig as InnerHistoryTableConfig;
5050
use databend_common_tracing::OTLPConfig as InnerOTLPLogConfig;
51+
// TelemetryConfig moved here to avoid circular dependency
5152
use databend_common_tracing::OTLPEndpointConfig as InnerOTLPEndpointConfig;
5253
use databend_common_tracing::OTLPProtocol;
5354
use databend_common_tracing::ProfileLogConfig as InnerProfileLogConfig;
@@ -63,6 +64,39 @@ use serfig::collectors::from_env;
6364
use serfig::collectors::from_file;
6465
use serfig::collectors::from_self;
6566

67+
/// Telemetry configuration for node information reporting
68+
///
69+
/// Note: The `enabled` flag only works with Enterprise Edition license.
70+
/// Without EE license, telemetry is always enabled.
71+
/// With EE license, users can set `enabled=false` to disable telemetry reporting.
72+
/// The endpoint is fixed and not configurable by users.
73+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Args)]
74+
#[serde(default)]
75+
pub struct TelemetryConfig {
76+
/// Enable/disable telemetry reporting (only works with EE license)
77+
#[clap(long = "telemetry-enabled", value_name = "BOOL")]
78+
#[serde(default = "default_telemetry_enabled")]
79+
pub enabled: bool,
80+
}
81+
82+
fn default_telemetry_enabled() -> bool {
83+
true
84+
}
85+
86+
impl Default for TelemetryConfig {
87+
fn default() -> Self {
88+
Self {
89+
enabled: default_telemetry_enabled(),
90+
}
91+
}
92+
}
93+
94+
impl TelemetryConfig {
95+
pub fn is_enabled(&self) -> bool {
96+
self.enabled
97+
}
98+
}
99+
66100
use super::inner;
67101
use super::inner::CatalogConfig as InnerCatalogConfig;
68102
use super::inner::CatalogHiveConfig as InnerCatalogHiveConfig;
@@ -128,6 +162,10 @@ pub struct Config {
128162
#[clap(flatten)]
129163
pub spill: SpillConfig,
130164

165+
// telemetry Config
166+
#[clap(flatten)]
167+
pub telemetry: TelemetryConfig,
168+
131169
/// external catalog config.
132170
///
133171
/// - Later, catalog information SHOULD be kept in KV Service
@@ -3582,6 +3620,7 @@ mod cache_config_converters {
35823620
.collect(),
35833621
cache: inner.cache.into(),
35843622
spill: inner.spill.into(),
3623+
telemetry: inner.telemetry,
35853624
}
35863625
}
35873626
}
@@ -3599,6 +3638,7 @@ mod cache_config_converters {
35993638
catalog,
36003639
cache,
36013640
spill,
3641+
telemetry,
36023642
catalogs: input_catalogs,
36033643
..
36043644
} = self;
@@ -3628,6 +3668,7 @@ mod cache_config_converters {
36283668
catalogs,
36293669
cache: cache.try_into()?,
36303670
spill,
3671+
telemetry,
36313672
})
36323673
}
36333674
}

src/query/config/src/inner.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use databend_common_tracing::Config as LogConfig;
3737

3838
use super::config::Config;
3939
use super::config::ResourcesManagementConfig;
40+
use super::config::TelemetryConfig;
4041
use crate::BuiltInConfig;
4142

4243
/// Inner config for query.
@@ -67,6 +68,9 @@ pub struct InnerConfig {
6768

6869
// Spill Config
6970
pub spill: SpillConfig,
71+
72+
// Telemetry Config
73+
pub telemetry: TelemetryConfig,
7074
}
7175

7276
impl InnerConfig {

src/query/config/src/mask.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl Config {
5151
catalog: self.catalog,
5252
cache: self.cache,
5353
spill: self.spill.mask_display(),
54+
telemetry: self.telemetry,
5455
catalogs: self.catalogs,
5556
}
5657
}

src/query/service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ databend-common-hashtable = { workspace = true }
6363
databend-common-http = { workspace = true }
6464
databend-common-io = { workspace = true }
6565
databend-common-license = { workspace = true }
66+
databend-common-telemetry = { workspace = true }
6667
databend-common-management = { workspace = true }
6768
databend-common-meta-api = { workspace = true }
6869
databend-common-meta-app = { workspace = true }

0 commit comments

Comments
 (0)