Skip to content

Commit

Permalink
Merge pull request #214 from lmnr-ai/dev
Browse files Browse the repository at this point in the history
disable all clickhouse queries for non-full builds (#213)
  • Loading branch information
dinmukhamedm authored Nov 15, 2024
2 parents d9e7d65 + 7b14a7a commit f3a0450
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app-server/src/ch/evaluation_scores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use clickhouse::Row;
use serde::{Deserialize, Serialize, Serializer};
use uuid::Uuid;

use crate::evaluations::utils::EvaluationDatapointResult;
use crate::{
evaluations::utils::EvaluationDatapointResult,
features::{is_feature_enabled, Feature},
};

use super::utils::chrono_to_nanoseconds;

Expand Down Expand Up @@ -75,6 +78,10 @@ pub async fn insert_evaluation_scores(
return Ok(());
}

if !is_feature_enabled(Feature::FullBuild) {
return Ok(());
}

let ch_insert = clickhouse.insert("evaluation_scores");
match ch_insert {
Ok(mut ch_insert) => {
Expand Down
8 changes: 7 additions & 1 deletion app-server/src/ch/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use serde::Serialize;
use serde_repr::Serialize_repr;
use uuid::Uuid;

use crate::db::{self, event_templates::EventTemplate};
use crate::{
db::{self, event_templates::EventTemplate},
features::{is_feature_enabled, Feature},
};

use super::{
modifiers::GroupByInterval,
Expand Down Expand Up @@ -87,6 +90,9 @@ impl CHEvent {
}

pub async fn insert_events(clickhouse: clickhouse::Client, events: Vec<CHEvent>) -> Result<()> {
if !is_feature_enabled(Feature::FullBuild) {
return Ok(());
}
if events.is_empty() {
return Ok(());
}
Expand Down
12 changes: 11 additions & 1 deletion app-server/src/ch/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use clickhouse::Row;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::db::labels::LabelSource;
use crate::{
db::labels::LabelSource,
features::{is_feature_enabled, Feature},
};

use super::utils::chrono_to_nanoseconds;

Expand Down Expand Up @@ -73,6 +76,10 @@ pub async fn insert_label(
value: f64,
span_id: Uuid,
) -> Result<()> {
if !is_feature_enabled(Feature::FullBuild) {
return Ok(());
}

let label = CHLabel::new(
project_id,
class_id,
Expand Down Expand Up @@ -113,6 +120,9 @@ pub async fn delete_label(
span_id: Uuid,
id: Uuid,
) -> Result<()> {
if !is_feature_enabled(Feature::FullBuild) {
return Ok(());
}
// Note, this does not immediately physically delete the data.
// https://clickhouse.com/docs/en/sql-reference/statements/delete
client
Expand Down
4 changes: 4 additions & 0 deletions app-server/src/ch/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use uuid::Uuid;

use crate::{
db::spans::{Span, SpanType},
features::{is_feature_enabled, Feature},
traces::spans::SpanUsage,
};

Expand Down Expand Up @@ -94,6 +95,9 @@ impl CHSpan {
}

pub async fn insert_span(clickhouse: clickhouse::Client, span: &CHSpan) -> Result<()> {
if !is_feature_enabled(Feature::FullBuild) {
return Ok(());
}
let ch_insert = clickhouse.insert("spans");
match ch_insert {
Ok(mut ch_insert) => {
Expand Down
6 changes: 5 additions & 1 deletion app-server/src/routes/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use serde::Deserialize;
use uuid::Uuid;

use crate::{
ch::{self, utils::get_bounds, Aggregation},
ch::{self, utils::get_bounds, Aggregation, MetricTimeValue},
db::{
self,
events::EventWithTemplateName,
modifiers::{AbsoluteDateInterval, DateRange, Filter, RelativeDateInterval},
DB,
},
features::{is_feature_enabled, Feature},
routes::{PaginatedGetQueryParams, PaginatedResponse, DEFAULT_PAGE_SIZE},
};

Expand Down Expand Up @@ -174,6 +175,9 @@ pub async fn get_events_metrics(
} else {
defaulted_range
};
if !is_feature_enabled(Feature::FullBuild) {
return Ok(HttpResponse::Ok().json(Vec::<MetricTimeValue<i64>>::new()));
}

match range {
DateRange::Relative(interval) => {
Expand Down
6 changes: 6 additions & 0 deletions app-server/src/routes/traces.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::{GetMetricsQueryParams, ResponseResult};
use super::{PaginatedGetQueryParams, PaginatedResponse, DEFAULT_PAGE_SIZE};
use crate::ch::utils::get_bounds;
use crate::ch::MetricTimeValue;
use crate::features::{is_feature_enabled, Feature};
use crate::{
ch::{self, modifiers::GroupByInterval, Aggregation},
db::{
Expand Down Expand Up @@ -184,6 +186,10 @@ pub async fn get_traces_metrics(
past_hours: "all".to_string(),
}));

if !is_feature_enabled(Feature::FullBuild) {
return Ok(HttpResponse::Ok().json(Vec::<MetricTimeValue<f64>>::new()));
}

match defaulted_range {
DateRange::Relative(interval) => {
if interval.past_hours == "all" {
Expand Down
5 changes: 5 additions & 0 deletions frontend/lib/clickhouse/evaluation-scores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ClickHouseClient } from "@clickhouse/client";
import { AggregationFunction, TimeRange, addTimeRangeToQuery, aggregationFunctionToCh } from "./utils";
import { EvaluationTimeProgression } from "../evaluation/types";
import { BucketRow } from "../types";
import { Feature } from "../features/features";
import { isFeatureEnabled } from "../features/features";

const DEFAULT_BUCKET_COUNT = 10;
const DEFAULT_LOWER_BOUND = 0;
Expand All @@ -13,6 +15,9 @@ export const getEvaluationTimeProgression = async (
timeRange: TimeRange,
aggregationFunction: AggregationFunction,
): Promise<EvaluationTimeProgression[]> => {
if (!isFeatureEnabled(Feature.FULL_BUILD)) {
return [];
}
const query = `WITH base AS (
SELECT
evaluation_id,
Expand Down

0 comments on commit f3a0450

Please sign in to comment.