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

disable all clickhouse queries for non-full builds #213

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature flag check for 'FullBuild' is a duplicate of existing checks in the codebase. Consider reusing the existing pattern or refactoring to avoid duplication.

  • Feature flag check in insert_events (events.rs)
  • Feature flag check in insert_span (spans.rs)
  • Feature flag check in insert_labels (labels.rs)
  • Feature flag check in utils (utils.rs)
  • Feature flag check in consumer (consumer.rs)

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