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

OLAP Connectors: Test the connection before exiting the "Add Data" modal #6892

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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,273 changes: 1,273 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions runtime/drivers/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var spec = drivers.Spec{
Type: drivers.StringPropertyType,
Required: false,
DisplayName: "Connection string",
Placeholder: "clickhouse://localhost:9000?username=default&password=",
Placeholder: "clickhouse://localhost:9000?username=default&password=password",
Secret: true,
NoPrompt: true,
},
{
Expand Down Expand Up @@ -81,13 +82,6 @@ var spec = drivers.Spec{
DisplayName: "SSL",
Description: "Use SSL to connect to the ClickHouse server",
},
{
Key: "database",
Type: drivers.StringPropertyType,
Required: false,
DisplayName: "Database",
Description: "Specify the database within the ClickHouse server",
},
},
ImplementsOLAP: true,
}
Expand Down
1 change: 1 addition & 0 deletions runtime/drivers/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var spec = drivers.Spec{
DocsURL: "https://github.com/go-sql-driver/mysql?tab=readme-ov-file#dsn-data-source-name",
Placeholder: "username:password@tcp(example.com:3306)/my-db",
Hint: "Can be configured here or by setting the 'connector.mysql.dsn' environment variable (using '.env' or '--env')",
Secret: true,
},
{
Key: "name",
Expand Down
1 change: 1 addition & 0 deletions runtime/drivers/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var spec = drivers.Spec{
DocsURL: "https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING",
Placeholder: "postgresql://postgres:postgres@localhost:5432/postgres",
Hint: "Can be configured here or by setting the 'connector.postgres.database_url' environment variable (using '.env' or '--env')",
Secret: true,
},
{
Key: "name",
Expand Down
2 changes: 2 additions & 0 deletions runtime/drivers/salesforce/salesforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ var spec = drivers.Spec{
DisplayName: "Salesforce Password",
Required: false,
Hint: "Either set this or pass --env connector.salesforce.password=... to rill start",
Secret: true,
},
{
Key: "key",
Type: drivers.StringPropertyType,
DisplayName: "JWT Key for Authentication",
Required: false,
Hint: "Either set this or pass --env connector.salesforce.key=... to rill start",
Secret: true,
},
{
Key: "endpoint",
Expand Down
1 change: 1 addition & 0 deletions runtime/drivers/snowflake/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var spec = drivers.Spec{
DocsURL: "https://pkg.go.dev/github.com/snowflakedb/gosnowflake#hdr-Connection_String",
Placeholder: "my_user_name:my_password@ac123456/my_database/my_schema?warehouse=my_warehouse&role=my_user_role",
Hint: "Can be configured here or by setting the 'connector.snowflake.dsn' environment variable (using '.env' or '--env')",
Secret: true,
},
{
Key: "name",
Expand Down
2 changes: 1 addition & 1 deletion web-common/src/components/forms/SubmissionError.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</script>

<div>
<AlertTriangle size="16px" />
<AlertTriangle size="16px" className="shrink-0" />
<p class="ml-2">
{message}
</p>
Expand Down
4 changes: 3 additions & 1 deletion web-common/src/components/icons/AlertTriangle.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script>
<script lang="ts">
export let size = "1em";
export let color = "currentColor";
export let className = "";
</script>

<svg
height={size}
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
class={className}
>
<path
fill-rule="evenodd"
Expand Down
3 changes: 2 additions & 1 deletion web-common/src/features/connectors/ConnectorEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
<!-- For now, only show OLAP connectors -->
{#if implementsOlap}
{#if connector.name}
<li aria-label={connector.name} class="connector-entry">
<li class="connector-entry">
<button
class="connector-entry-header"
aria-label={connector.name}
on:click={() => {
store.toggleItem(connectorName);
}}
Expand Down
21 changes: 20 additions & 1 deletion web-common/src/features/connectors/code-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function updateDotEnvWithSecrets(
queryClient: QueryClient,
connector: V1ConnectorDriver,
formValues: Record<string, unknown>,
formType: "source" | "connector",
): Promise<string> {
const instanceId = get(runtime).instanceId;

Expand All @@ -86,7 +87,11 @@ export async function updateDotEnvWithSecrets(
}

// Get the secret keys
const secretKeys = connector.configProperties
const properties =
formType === "source"
? connector.sourceProperties
: connector.configProperties;
const secretKeys = properties
?.filter((property) => property.secret)
.map((property) => property.key);

Expand Down Expand Up @@ -144,6 +149,20 @@ export function replaceOrAddEnvVariable(
return newBlob;
}

export function deleteEnvVariable(
existingEnvBlob: string,
key: string,
): string {
const lines = existingEnvBlob.split("\n");
const updatedLines = lines.filter((line) => !line.startsWith(`${key}=`));
const newBlob = updatedLines
.filter((line, index) => !(line === "" && index === 0))
.join("\n")
.trim();

return newBlob;
}

export function makeDotEnvConnectorKey(connectorName: string, key: string) {
// Note: The connector name, not driver, is used. This enables configuring multiple connectors that use the same driver.
return `connector.${connectorName}.${key}`;
Expand Down
66 changes: 66 additions & 0 deletions web-common/src/features/connectors/olap/test-connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { get } from "svelte/store";
import { queryClient } from "../../../lib/svelte-query/globalQueryClient";
import { waitUntil } from "../../../lib/waitUtils";
import {
connectorServiceOLAPListTables,
getConnectorServiceOLAPListTablesQueryKey,
} from "../../../runtime-client";
import { fileArtifacts } from "../../entity-management/file-artifacts";
import { humanReadableErrorMessage } from "../../sources/modal/errors";

interface TestConnectorResult {
success: boolean;
error?: string;
}

export async function testOLAPConnector(
Copy link
Collaborator

Choose a reason for hiding this comment

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

A method called testOLAPConnector seems to be also checking if the file has updated as well.

Perhaps we should split them out, update and confirming of reconcile can be in a method. We could also get rid of the hard wait for 1000s. We could check for version change in ProjectParser instead?

instanceId: string,
newConnectorFilePath: string,
newConnectorName: string,
): Promise<TestConnectorResult> {
// Wait a sec – give the runtime time to start reconciling the file
await new Promise((resolve) => setTimeout(resolve, 1000));

// Wait for the file to reconcile
const fileArtifact = fileArtifacts.getFileArtifact(newConnectorFilePath);
await waitUntil(() => !get(fileArtifact.reconciling), 500);

// Check for errors
const hasErrorsStore = fileArtifact.getHasErrors(queryClient, instanceId);
const hasErrors = get(hasErrorsStore);
if (hasErrors) {
// Get the first error message
const firstError = get(
fileArtifact.getAllErrors(queryClient, instanceId),
)[0].message;

return {
success: false,
error: firstError,
};
}

// Test the connection by calling `GetTables`
const queryKey = getConnectorServiceOLAPListTablesQueryKey({
instanceId,
connector: newConnectorName,
});
const queryFn = () =>
connectorServiceOLAPListTables({
instanceId,
connector: newConnectorName,
});
try {
await queryClient.fetchQuery({ queryKey, queryFn });
return { success: true };
} catch (e) {
return {
success: false,
error: humanReadableErrorMessage(
newConnectorName,
e?.response?.data?.code,
e?.response?.data?.message,
),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
</DropdownMenu.Trigger>
<DropdownMenu.Content align="start" class="w-[240px]">
<DropdownMenu.Item
aria-label="Add Source"
aria-label="Add Data"
class="flex gap-x-2"
on:click={handleAddData}
>
Expand Down
Loading
Loading