Skip to content

Commit

Permalink
feat(core): add webserver in telemetry (#1896)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored Apr 19, 2024
1 parent 103caa0 commit 00674c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
17 changes: 14 additions & 3 deletions crates/tabby/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ pub async fn main(config: &Config, args: &ServeArgs) {
warn!("'--webserver' is enabled by default since 0.11, and will be removed in the next major release. Please remove this flag from your command.");
}

#[allow(unused_assignments)]
let mut webserver = None;

#[cfg(feature = "ee")]
{
webserver = Some(!args.no_webserver)
}

#[cfg(feature = "ee")]
let ws = if !args.no_webserver {
Some(tabby_webserver::public::WebserverHandle::new(create_event_logger()).await)
Expand All @@ -150,7 +158,7 @@ pub async fn main(config: &Config, args: &ServeArgs) {
}

let code = Arc::new(create_code_search(repository_access));
let mut api = api_router(args, config, logger.clone(), code.clone()).await;
let mut api = api_router(args, config, logger.clone(), code.clone(), webserver).await;
let mut ui = Router::new()
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
.fallback(|| async { axum::response::Redirect::temporary("/swagger-ui") });
Expand All @@ -164,7 +172,7 @@ pub async fn main(config: &Config, args: &ServeArgs) {
ui = new_ui;
};

start_heartbeat(args);
start_heartbeat(args, webserver);
run_app(api, Some(ui), args.host, args.port).await
}

Expand All @@ -183,6 +191,7 @@ async fn api_router(
config: &Config,
logger: Arc<dyn EventLogger>,
code: Arc<dyn CodeSearch>,
webserver: Option<bool>,
) -> Router {
let completion_state = if let Some(model) = &args.model {
Some(Arc::new(
Expand Down Expand Up @@ -219,6 +228,7 @@ async fn api_router(
args.model.as_deref(),
args.chat_model.as_deref(),
&args.device,
webserver,
));

routers.push({
Expand Down Expand Up @@ -313,11 +323,12 @@ async fn api_router(
root
}

fn start_heartbeat(args: &ServeArgs) {
fn start_heartbeat(args: &ServeArgs, webserver: Option<bool>) {
let state = health::HealthState::new(
args.model.as_deref(),
args.chat_model.as_deref(),
&args.device,
webserver,
);
tokio::spawn(async move {
loop {
Expand Down
9 changes: 8 additions & 1 deletion crates/tabby/src/services/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ pub struct HealthState {
cpu_count: usize,
cuda_devices: Vec<String>,
version: Version,
webserver: Option<bool>,
}

impl HealthState {
pub fn new(model: Option<&str>, chat_model: Option<&str>, device: &Device) -> Self {
pub fn new(
model: Option<&str>,
chat_model: Option<&str>,
device: &Device,
webserver: Option<bool>,
) -> Self {
let (cpu_info, cpu_count) = read_cpu_info();

let cuda_devices = match read_cuda_devices() {
Expand All @@ -40,6 +46,7 @@ impl HealthState {
cpu_count,
cuda_devices,
version: Version::new(),
webserver,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion website/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Tabby collects usage stats by default. This data will only be used by the Tabby

### What data is collected?
We collect non-sensitive data that helps us understand how Tabby is used. For now we collects `serve` command you used to start the server.
As of the date 10/07/2023, the following information has been collected:
As of the date 04/18/2024, the following information has been collected:

```rust
struct HealthState {
Expand All @@ -105,6 +105,7 @@ struct HealthState {
cpu_count: usize,
cuda_devices: Vec<String>,
version: Version,
webserver: Option<bool>,
}
```

Expand Down

0 comments on commit 00674c8

Please sign in to comment.