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

Migrate to Official Clickhouse Client #2236

Merged
merged 8 commits into from
Mar 20, 2024
Merged

Migrate to Official Clickhouse Client #2236

merged 8 commits into from
Mar 20, 2024

Conversation

lukesonnet
Copy link
Collaborator

@lukesonnet lukesonnet commented Mar 15, 2024

Features and Changes

Move to official clickhouse client.

Closes #2194

May resolve #2130 error which seems to be emitted from the clickhouse client we were using before.

Testing

Ran test, experiment metric and fact metric queries, and traffic query for ClickHouse. All works as expected.

Screenshots

Statistics show up:
Screenshot 2024-03-15 at 11 14 47 AM

Timeout setting:
Screenshot 2024-03-15 at 12 22 59 PM

Timeout works:
Screenshot 2024-03-15 at 12 21 20 PM

Copy link

github-actions bot commented Mar 15, 2024

Your preview environment pr-2236-bttf has been deployed.

Preview environment endpoints are available at:

database: this.params.database,
application: "GrowthBook",
clickhouse_settings: {
max_execution_time: Math.min(this.params.maxExecutionTime ?? 240, 1800),
Copy link
Member

Choose a reason for hiding this comment

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

4 minutes feels like a really short default value. I feel like this will break people's existing data sources and require them to go in and edit the connection settings. I'd rather have the default be 30 minutes and then let them opt-in to making it shorter if they want to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, you're right. Not sure what I was thinking. Set it to 30 minutes, increased max to 60 minutes.

packages/back-end/types/query.d.ts Show resolved Hide resolved
const client = createClient({
host: `${this.params.url}${
this.params.port ? `:${this.params.port}` : ""
}`,
Copy link
Member

Choose a reason for hiding this comment

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

The old Clickhouse client supported specifying a port in the URL while also passing in a port setting. For example, this would work fine before, but would break today:

{
  url: "http://localhost:1234",
  port: "1234"
}

There was also some weird behavior in the old client if you passed in different ports in both places, but I don't think we need to support that edge case.

Copy link
Member

Choose a reason for hiding this comment

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

An easy solution to this is to use the URL class.

function getHost(url: string | undefined, port: number) {
  if (!url) return undefined;
  const host = new URL(url);
  if (!host.port && port) host.port = port + "";
  return host.origin;
}
// ...

const client = createClient({
  host: getHost(this.params.url, this.params.port),

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One issue with this is that URL(url) will throw an error if url isn't a proper URL. Should I just catch this case and do my pasting approach or should we consider some better validation when the form is saved (I don't think we do any right now).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for example, do something like this to catch some edge cases

export function getHost(url: string | undefined, port: number): string | undefined {  
  if (!url) return undefined;  
  try {
    const host = new URL(url);  
    if (!host.port && port) host.port = port + "";  
    return host.origin;  
  } catch (e) {
    return `${url}:${port}`;
  }
}  

Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to just let it throw. I'm pretty sure if they have an invalid URL today it will be broken, so this shouldn't introduce any regressions.

@lukesonnet
Copy link
Collaborator Author

new stats look good
Screenshot 2024-03-19 at 9 35 07 AM

default now showing in form
Screenshot 2024-03-19 at 9 34 04 AM

@lukesonnet lukesonnet merged commit 9936e4b into main Mar 20, 2024
3 checks passed
@lukesonnet lukesonnet deleted the ls/clickhouse-client branch March 20, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants