-
Notifications
You must be signed in to change notification settings - Fork 3
feat(eval): add eval id to metrics #995
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
Open
karthikrab
wants to merge
3
commits into
master
Choose a base branch
from
feature/eval_token
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...gateway/tensorzero-internal/src/clickhouse/migration_manager/migrations/migration_0036.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| use crate::clickhouse::migration_manager::migration_trait::Migration; | ||
| use crate::clickhouse::ClickHouseConnectionInfo; | ||
| use crate::error::{Error, ErrorDetails}; | ||
| use async_trait::async_trait; | ||
|
|
||
| use super::{check_column_exists, check_table_exists}; | ||
|
|
||
| /// This migration adds evaluation_id column to the ModelInferenceDetails and GatewayAnalytics tables | ||
| /// to track inferences associated with specific evaluations. | ||
| pub struct Migration0036<'a> { | ||
| pub clickhouse: &'a ClickHouseConnectionInfo, | ||
| } | ||
|
|
||
| const MIGRATION_ID: &str = "0036"; | ||
|
|
||
| #[async_trait] | ||
| impl Migration for Migration0036<'_> { | ||
| async fn can_apply(&self) -> Result<(), Error> { | ||
| // Check if ModelInferenceDetails table exists | ||
| let model_inference_details_exists = | ||
| check_table_exists(self.clickhouse, "ModelInferenceDetails", MIGRATION_ID).await?; | ||
|
|
||
| if !model_inference_details_exists { | ||
| return Err(Error::new(ErrorDetails::ClickHouseMigration { | ||
| id: MIGRATION_ID.to_string(), | ||
| message: "ModelInferenceDetails table does not exist".to_string(), | ||
| })); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| async fn should_apply(&self) -> Result<bool, Error> { | ||
| // Check if evaluation_id column already exists in ModelInferenceDetails | ||
| let evaluation_id_exists_mid = check_column_exists( | ||
| self.clickhouse, | ||
| "ModelInferenceDetails", | ||
| "evaluation_id", | ||
| MIGRATION_ID, | ||
| ) | ||
| .await?; | ||
|
|
||
| // Check if evaluation_id column already exists in GatewayAnalytics | ||
| let gateway_analytics_exists = | ||
| check_table_exists(self.clickhouse, "GatewayAnalytics", MIGRATION_ID).await?; | ||
|
|
||
| let evaluation_id_exists_ga = if gateway_analytics_exists { | ||
| check_column_exists( | ||
| self.clickhouse, | ||
| "GatewayAnalytics", | ||
| "evaluation_id", | ||
| MIGRATION_ID, | ||
| ) | ||
| .await? | ||
| } else { | ||
| true // If table doesn't exist, consider it as "already done" for this column | ||
| }; | ||
|
|
||
| // Apply if any column is missing | ||
| Ok(!evaluation_id_exists_mid || !evaluation_id_exists_ga) | ||
| } | ||
|
|
||
| async fn apply(&self, _clean_start: bool) -> Result<(), Error> { | ||
| // Add evaluation_id column to ModelInferenceDetails | ||
| let query = r#" | ||
| ALTER TABLE ModelInferenceDetails | ||
| ADD COLUMN IF NOT EXISTS evaluation_id Nullable(UUID) | ||
| "#; | ||
| self.clickhouse | ||
| .run_query_synchronous(query.to_string(), None) | ||
| .await?; | ||
|
|
||
| // Add index for evaluation_id in ModelInferenceDetails | ||
| let index_query = r#" | ||
| ALTER TABLE ModelInferenceDetails | ||
| ADD INDEX IF NOT EXISTS idx_evaluation_id evaluation_id TYPE bloom_filter(0.01) GRANULARITY 4 | ||
| "#; | ||
| self.clickhouse | ||
| .run_query_synchronous(index_query.to_string(), None) | ||
| .await?; | ||
|
|
||
| // Check if GatewayAnalytics table exists before adding column | ||
| let gateway_analytics_exists = | ||
| check_table_exists(self.clickhouse, "GatewayAnalytics", MIGRATION_ID).await?; | ||
|
|
||
| if gateway_analytics_exists { | ||
| // Add evaluation_id column to GatewayAnalytics | ||
| let ga_query = r#" | ||
| ALTER TABLE GatewayAnalytics | ||
| ADD COLUMN IF NOT EXISTS evaluation_id Nullable(UUID) | ||
| "#; | ||
| self.clickhouse | ||
| .run_query_synchronous(ga_query.to_string(), None) | ||
| .await?; | ||
|
|
||
| // Add index for evaluation_id in GatewayAnalytics | ||
| let ga_index_query = r#" | ||
| ALTER TABLE GatewayAnalytics | ||
| ADD INDEX IF NOT EXISTS idx_evaluation_id evaluation_id TYPE bloom_filter(0.01) GRANULARITY 4 | ||
| "#; | ||
| self.clickhouse | ||
| .run_query_synchronous(ga_index_query.to_string(), None) | ||
| .await?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn rollback_instructions(&self) -> String { | ||
| r#" | ||
| ALTER TABLE ModelInferenceDetails DROP INDEX IF EXISTS idx_evaluation_id; | ||
| ALTER TABLE ModelInferenceDetails DROP COLUMN IF EXISTS evaluation_id; | ||
| ALTER TABLE GatewayAnalytics DROP INDEX IF EXISTS idx_evaluation_id; | ||
| ALTER TABLE GatewayAnalytics DROP COLUMN IF EXISTS evaluation_id; | ||
| "# | ||
| .to_string() | ||
| } | ||
|
|
||
| async fn has_succeeded(&self) -> Result<bool, Error> { | ||
| let should_apply = self.should_apply().await?; | ||
| Ok(!should_apply) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function contains a lot of repetitive code for extracting different metadata fields from the headers. This can be refactored to be more concise and maintainable by using
and_thento chain the operations, which is more idiomatic in Rust and reduces nesting. This will make the function shorter and easier to read.