-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
482f454
commit 6db82e6
Showing
14 changed files
with
192 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,47 @@ | ||
# Generating Clickhouse Stats | ||
This Helm repository contains queries to produce output that the LangSmith UI does not currently support directly (e.g. obtaining trace counts for multiple workspaces by date in a single query). | ||
|
||
This command takes a clickhouse connection string that contains an embedded name and password (which can be passed in from a call to a secrets manager) and executes a query from an input file. In the example below, we are using the `ch_get_trace_counts_daily.sql` input file in the `support_queries` directory. | ||
|
||
### Prerequisites | ||
|
||
Ensure you have the following tools/items ready. | ||
|
||
1. kubectl | ||
|
||
- https://kubernetes.io/docs/tasks/tools/ | ||
|
||
2. Clickhouse database credentials | ||
|
||
- Host | ||
- Port | ||
- Username | ||
- If using the bundled version, this is `default` | ||
- Password | ||
- If using the bundled version, this is `password` | ||
- Database name | ||
- If using the bundled version, this is `default` | ||
|
||
3. Connectivity to the Clickhouse database from the machine you will be running the `get_clickhouse_stats` script on. | ||
|
||
- If you are using the bundled version, you may need to port forward the clickhouse service to your local machine. | ||
- Run `kubectl port-forward svc/langsmith-clickhouse 8123:8123` to port forward the clickhouse service to your local machine. | ||
|
||
### Running the clickhouse stats generation script | ||
|
||
## Running the query script | ||
|
||
Run the following command to run the desired query: | ||
|
||
```bash | ||
sh run_support_query_ch.sh <clickhouse_url> --input path/to/query.sql | ||
``` | ||
|
||
For example, if you are using the bundled version with port-forwarding, the command might look like: | ||
|
||
```bash | ||
sh run_support_query_ch.sh "clickhouse://default:password@localhost:8123/default" --input support_queries/clickhouse/ch_get_trace_counts_daily.sql | ||
``` | ||
|
||
which will output the count of daily traces by workspace ID and organization ID. To extract this to a file add the flag `--output path/to/file.csv` | ||
|
This file contains 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 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
7 changes: 7 additions & 0 deletions
7
...langsmith/scripts/support_queries/clickhouse/ch_get_historic_trace_counts_by_ws_daily.sql
This file contains 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,7 @@ | ||
select toStartOfInterval(inserted_at, interval 1 day) as ts, | ||
tenant_id as workspace_id, | ||
count(distinct id) as trace_count | ||
from default.runs_history | ||
where is_root = 1 | ||
group by ts, tenant_id | ||
order by ts, tenant_id |
7 changes: 7 additions & 0 deletions
7
charts/langsmith/scripts/support_queries/clickhouse/ch_get_trace_counts_by_ws_daily.sql
This file contains 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,7 @@ | ||
select toStartOfInterval(inserted_at, interval 1 day) as ts, | ||
tenant_id as workspace_id, | ||
count(distinct id) as trace_count | ||
from default.runs | ||
where is_root = 1 | ||
group by ts, tenant_id | ||
order by ts, tenant_id |
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
charts/langsmith/scripts/support_queries/postgres/pg_get_users_by_org.sql
This file contains 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,17 @@ | ||
-- This query retreives a list of users by organization. | ||
-- There will be one row per unique user-organization combination | ||
|
||
select distinct | ||
u.email as user_email, | ||
u.full_name as user_name, | ||
o.display_name as organization_name, | ||
o.id as organization_id | ||
from users u | ||
|
||
join identities i | ||
on u.id = i.user_id | ||
|
||
join organizations o | ||
on i.organization_id = o.id | ||
and not o.is_personal | ||
and i.tenant_id is null |
21 changes: 21 additions & 0 deletions
21
charts/langsmith/scripts/support_queries/postgres/pg_get_users_by_ws_and_org.sql
This file contains 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,21 @@ | ||
-- This query retreives a list of users by workspace and organization. | ||
-- There will be one row per unique user-workspace combination | ||
|
||
select | ||
u.email as user_email, | ||
u.full_name as user_name, | ||
o.display_name as organization_name, | ||
o.id as organization_id, | ||
t.display_name as workspace_name, | ||
t.id as workspace_id | ||
from users u | ||
|
||
join identities i | ||
on u.id = i.user_id | ||
|
||
join tenants t | ||
on i.tenant_id = t.id | ||
|
||
join organizations o | ||
on t.organization_id = o.id | ||
and NOT o.is_personal |
23 changes: 23 additions & 0 deletions
23
charts/langsmith/scripts/support_queries/postgres/pg_get_users_with_stats.sql
This file contains 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,23 @@ | ||
-- This query retreives a list of users and the count of organizations and workspaces they are a member of | ||
-- There will be one row per unique user | ||
|
||
select | ||
u.email as user_email, | ||
u.full_name as user_name, | ||
count(distinct o.id) as org_count, | ||
count(distinct t.id) as workspace_count | ||
from users u | ||
|
||
join identities i | ||
on u.id = i.user_id | ||
|
||
join tenants t | ||
on i.tenant_id = t.id | ||
|
||
join organizations o | ||
on t.organization_id = o.id | ||
and NOT o.is_personal | ||
|
||
group by | ||
user_email, | ||
user_name |
24 changes: 24 additions & 0 deletions
24
charts/langsmith/scripts/support_queries/postgres/pg_get_workspace_dataset_counts.sql
This file contains 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,24 @@ | ||
-- This query returns a workspace ID | ||
|
||
select | ||
organizations.id as org_id, | ||
organizations.display_name as org_name, | ||
tenant_id as workspace_id, | ||
tenants.display_name as workspace_name, | ||
count(distinct dataset.id) as dataset_count | ||
from dataset | ||
|
||
join tenants | ||
on dataset.tenant_id = tenants.id | ||
|
||
join organizations | ||
on tenants.organization_id = organizations.id | ||
|
||
group by | ||
org_id, | ||
org_name, | ||
workspace_id, | ||
workspace_name | ||
|
||
order BY | ||
prompt_count desc |
28 changes: 28 additions & 0 deletions
28
charts/langsmith/scripts/support_queries/postgres/pg_get_workspace_prompt_counts.sql
This file contains 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,28 @@ | ||
-- This query returns a workspace ID | ||
|
||
select | ||
organizations.id as org_id, | ||
organizations.display_name as org_name, | ||
tenant_id as workspace_id, | ||
tenants.display_name as workspace_name, | ||
count(distinct hub_repos.id) as prompt_count, | ||
count(distinct hub_commits.id) as revision_count | ||
from hub_repos | ||
|
||
join tenants | ||
on hub_repos.tenant_id = tenants.id | ||
|
||
join organizations | ||
on tenants.organization_id = organizations.id | ||
|
||
join hub_commits | ||
on hub_repos.id = hub_commits.repo_id | ||
|
||
group by | ||
org_id, | ||
org_name, | ||
workspace_id, | ||
workspace_name | ||
|
||
order BY | ||
prompt_count desc |
14 changes: 14 additions & 0 deletions
14
charts/langsmith/scripts/support_queries/postgres/pg_get_ws_by_org.sql
This file contains 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,14 @@ | ||
-- This query pulls a list of workspaces by organization | ||
-- Personal orgs if they exist are excluded | ||
|
||
select distinct | ||
ws.organization_id as organization_id, | ||
o.display_name as organization_name, | ||
ws.id as workspace_id, | ||
ws.display_name as workspace_name | ||
from tenants ws | ||
|
||
join organizations o | ||
on ws.organization_id = o.id | ||
|
||
where not o.is_personal |