Skip to content
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
1 change: 1 addition & 0 deletions bifrost/lib/clients/jawnTypes/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@ Json: JsonObject;
session_total_requests?: components["schemas"]["Partial_NumberOperators_"];
session_created_at?: components["schemas"]["Partial_TimestampOperatorsTyped_"];
session_latest_request_created_at?: components["schemas"]["Partial_TimestampOperatorsTyped_"];
session_tag?: components["schemas"]["Partial_TextOperators_"];
};
/** @description From T, pick a set of properties whose keys are in the union K */
"Pick_FilterLeaf.feedback-or-request-or-response-or-properties-or-values-or-cache_hits-or-request_response_rmt-or-sessions_request_response_rmt_": {
Expand Down
48 changes: 48 additions & 0 deletions bifrost/lib/clients/jawnTypes/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ export interface paths {
"/v1/session/{sessionId}/feedback": {
post: operations["UpdateSessionFeedback"];
};
"/v1/session/{sessionId}/tag": {
get: operations["GetSessionTag"];
post: operations["UpdateSessionTag"];
};
"/v1/public/status/provider": {
get: operations["GetAllProviderStatus"];
};
Expand Down Expand Up @@ -1028,6 +1032,7 @@ export interface components {
session_total_requests?: components["schemas"]["Partial_NumberOperators_"];
session_created_at?: components["schemas"]["Partial_TimestampOperatorsTyped_"];
session_latest_request_created_at?: components["schemas"]["Partial_TimestampOperatorsTyped_"];
session_tag?: components["schemas"]["Partial_TextOperators_"];
};
/** @description Make all properties in T optional */
Partial_CacheHitsTableToOperators_: {
Expand Down Expand Up @@ -1885,6 +1890,12 @@ Json: JsonObject;
timeFilter?: components["schemas"]["TimeFilterMs"];
filter?: components["schemas"]["SessionFilterNode"];
};
"ResultSuccess_string-or-null_": {
data: string | null;
/** @enum {number|null} */
error: null;
};
"Result_string-or-null.string_": components["schemas"]["ResultSuccess_string-or-null_"] | components["schemas"]["ResultError_string_"];
MetricsData: {
/** Format: double */
totalRequests: number;
Expand Down Expand Up @@ -4381,6 +4392,43 @@ export interface operations {
};
};
};
GetSessionTag: {
parameters: {
path: {
sessionId: string;
};
};
responses: {
/** @description Ok */
200: {
content: {
"application/json": components["schemas"]["Result_string-or-null.string_"];
};
};
};
};
UpdateSessionTag: {
parameters: {
path: {
sessionId: string;
};
};
requestBody: {
content: {
"application/json": {
tag: string;
};
};
};
responses: {
/** @description Ok */
200: {
content: {
"application/json": components["schemas"]["Result_null.string_"];
};
};
};
};
GetAllProviderStatus: {
responses: {
/** @description Ok */
Expand Down
11 changes: 11 additions & 0 deletions clickhouse/migrations/schema_46_tags.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS default.tags (
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add organization id here as the highest order on the cardinality to help the queries be faster. Also to check auth faster in the SessionManager

organization_id UUID,
entity_type String,
entity_id String,
tag String,
created_at DateTime DEFAULT now(),
PRIMARY KEY (organization_id, entity_type)
) ENGINE = ReplacingMergeTree()
ORDER BY (organization_id, entity_type, entity_id, tag);

-- https://clickhouse.com/docs/guides/developer/deduplication
120 changes: 120 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,9 @@
},
"session_latest_request_created_at": {
"$ref": "#/components/schemas/Partial_TimestampOperatorsTyped_"
},
"session_tag": {
"$ref": "#/components/schemas/Partial_TextOperators_"
}
},
"type": "object",
Expand Down Expand Up @@ -5284,6 +5287,37 @@
"type": "object",
"additionalProperties": false
},
"ResultSuccess_string-or-null_": {
"properties": {
"data": {
"type": "string",
"nullable": true
},
"error": {
"type": "number",
"enum": [
null
],
"nullable": true
}
},
"required": [
"data",
"error"
],
"type": "object",
"additionalProperties": false
},
"Result_string-or-null.string_": {
"anyOf": [
{
"$ref": "#/components/schemas/ResultSuccess_string-or-null_"
},
{
"$ref": "#/components/schemas/ResultError_string_"
}
]
},
"MetricsData": {
"properties": {
"totalRequests": {
Expand Down Expand Up @@ -12800,6 +12834,92 @@
}
}
},
"/v1/session/{sessionId}/tag": {
"get": {
"operationId": "GetSessionTag",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Result_string-or-null.string_"
}
}
}
}
},
"tags": [
"Session"
],
"security": [
{
"api_key": []
}
],
"parameters": [
{
"in": "path",
"name": "sessionId",
"required": true,
"schema": {
"type": "string"
}
}
]
},
"post": {
"operationId": "UpdateSessionTag",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Result_null.string_"
}
}
}
}
},
"tags": [
"Session"
],
"security": [
{
"api_key": []
}
],
"parameters": [
{
"in": "path",
"name": "sessionId",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"properties": {
"tag": {
"type": "string"
}
},
"required": [
"tag"
],
"type": "object"
}
}
}
}
}
},
"/v1/public/status/provider": {
"get": {
"operationId": "GetAllProviderStatus",
Expand Down
4 changes: 4 additions & 0 deletions packages/common/sessions/tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum TagType {
REQUEST = "request",
SESSION = "session",
}
8 changes: 4 additions & 4 deletions packages/copy-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ copy_llm_mapper() {

# Function to copy the common/auth/server to jawn
copy_common() {
echo "Copying common/auth/server to jawn and web..."
echo "Copying common/ to jawn and web..."

# Define destinations
destinations=(
"../valhalla/jawn/src/packages/common/auth"
"../web/packages/common/auth"
"../valhalla/jawn/src/packages/common"
"../web/packages/common"
)

# Remove and recreate directories
Expand All @@ -79,7 +79,7 @@ copy_common() {

# Copy files to all destinations
for dest in "${destinations[@]}"; do
rsync -a --exclude="toImplement" common/auth/ "$dest"
rsync -a --exclude="toImplement" common/ "$dest"
echo "Copied to $dest"
done
}
Expand Down
36 changes: 36 additions & 0 deletions valhalla/jawn/src/controllers/public/sessionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,40 @@ export class SessionController extends Controller {
}
return result;
}

@Get("/{sessionId}/tag")
public async getSessionTag(
@Path() sessionId: string,
@Request() request: JawnAuthenticatedRequest
): Promise<Result<string | null, string>> {
const sessionManager = new SessionManager(request.authParams);

const result = await sessionManager.getSessionTag(sessionId);
if (result.error) {
this.setStatus(500);
} else {
this.setStatus(200);
}
return result;
}

@Post("/{sessionId}/tag")
public async updateSessionTag(
@Path() sessionId: string,
@Body() requestBody: { tag: string },
@Request() request: JawnAuthenticatedRequest
): Promise<Result<null, string>> {
const sessionManager = new SessionManager(request.authParams);

const result = await sessionManager.updateSessionTag(
sessionId,
requestBody.tag
);
if (result.error) {
this.setStatus(500);
} else {
this.setStatus(200);
}
return result;
}
}
10 changes: 10 additions & 0 deletions valhalla/jawn/src/lib/db/ClickhouseWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ export interface JawnHttpLogs {
properties: Record<string, string>;
}

export interface Tags {
organization_id: string;
entity_type: string;
entity_id: string;
tag: string;
created_at?: string;
updated_at?: string;
}

export interface ClickhouseDB {
Tables: {
properties_v3: PropertiesV3;
Expand All @@ -252,6 +261,7 @@ export interface ClickhouseDB {
rate_limit_log_v2: RateLimitLogV2;
cache_hits: CacheHits;
request_response_rmt: RequestResponseRMT;
tags: Tags;
jawn_http_logs: JawnHttpLogs;
};
}
Expand Down
1 change: 1 addition & 0 deletions valhalla/jawn/src/lib/shared/filters/filterDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ interface SessionsRequestResponseRMTToOperators {
session_total_requests: SingleKey<NumberOperators>;
session_created_at: SingleKey<TimestampOperatorsTyped>;
session_latest_request_created_at: SingleKey<TimestampOperatorsTyped>;
session_tag: SingleKey<TextOperators>;
}

export type FilterLeafRequestResponseLog =
Expand Down
Loading
Loading