Skip to content

[FEATURE] Add test datasource connection button - #99

Open
adrianSepiol wants to merge 6 commits into
perses:mainfrom
adrianSepiol:add-test-connection-button
Open

[FEATURE] Add test datasource connection button#99
adrianSepiol wants to merge 6 commits into
perses:mainfrom
adrianSepiol:add-test-connection-button

Conversation

@adrianSepiol

@adrianSepiol adrianSepiol commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

…Button for testing datasource connections

Related pull requests (in order):

  1. [BUGFIX] set correct ContentLength for request body perses#4007
  2. This one
  3. [FEATURE] integrate test datasource connection button into DatasourceDrawer perses#4008
  4. [BREAKINGCHANGE] Replace local buildProxyUrl with shared implementation from @perses-dev/client perses#4302
  5. [FEATURE] add test connection button to prometheus plugin plugins#620

Related issue:
perses/perses#1542

Description

Adds a Test Connection button to the datasource editor that validates connectivity before saving. The button is wired through the editor component chain (DatasourceEditorForm → PluginEditor → PluginSpecEditor) where the connection logic is bound to the plugin's healthCheckPath and the current project/dashboard context. As part of this, buildProxyUrl is also migrated to @perses-dev/client, replacing the local implementation in perses/ui/app that will be removed in a companion PR.

Screenshots

In perses/plugins#620

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.
  • E2E tests are stable and unlikely to be flaky.
    See e2e docs for more details. Common issues include:
    • Is the data inconsistent? You need to mock API requests.
    • Does the time change? You need to use consistent time values or mock time utilities.
    • Does it have loading states? You need to wait for loading to complete.

@adrianSepiol
adrianSepiol marked this pull request as ready for review April 7, 2026 09:30
@adrianSepiol
adrianSepiol requested a review from a team as a code owner April 7, 2026 09:30
@adrianSepiol
adrianSepiol marked this pull request as draft July 27, 2026 12:51
@adrianSepiol
adrianSepiol force-pushed the add-test-connection-button branch 3 times, most recently from 3df35e7 to 6e06d51 Compare July 27, 2026 14:19
@adrianSepiol
adrianSepiol marked this pull request as ready for review July 27, 2026 14:23
@adrianSepiol
adrianSepiol force-pushed the add-test-connection-button branch from 6e06d51 to bcda582 Compare July 27, 2026 14:31
@adrianSepiol adrianSepiol changed the title [ENHANCEMENT] Add UnsavedDatasourceStore and DatasourceTestConnection… [FEATURE] Add test datasource connection button Jul 27, 2026
const existing = draft.proxy.spec.allowedEndpoints ?? [];
const alreadyAllowed = existing.some((e) => e.endpointPattern === healthCheckPath && e.method === 'GET');
if (!alreadyAllowed) {
draft.proxy.spec.allowedEndpoints = [...existing, { endpointPattern: healthCheckPath, method: 'GET' }];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is inserted as a regex, would it fail it the dots or other reserved characters are not escaped?

}, [testConnection, successSnackbar, exceptionSnackbar]);

return (
<Button onClick={handleClick} color="info" variant="outlined" {...buttonProps}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We probably should have a testing... state and block the button while is testing, otherwise rapid clicks can cause multiple snackbars.

Comment thread client/src/model/datasource-api.ts Outdated
const pluginSpec = spec.plugin.spec;

if (hasDirectUrl(pluginSpec)) {
await fetch(`${pluginSpec.directUrl}${normalizedPath}`, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we sanitize this url?, it seems it might contain double slash // if directUrl ends with slash

Comment thread plugin-system/src/model/plugin-base.ts Outdated
value: Spec;
onChange: (next: Spec) => void;
isReadonly?: boolean;
testConnection?: () => Promise<void>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to apply for all plugins, is there a more concrete interface for the datasources editors?

@adrianSepiol
adrianSepiol force-pushed the add-test-connection-button branch from 45bba07 to 3dc45bf Compare July 28, 2026 16:17
@adrianSepiol
adrianSepiol requested a review from jgbernalp August 11, 2026 08:11
Comment thread client/src/model/datasource-api.ts Outdated
);
}

function hasHTTPProxy(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems this function is duplicated in the plugin-system. Should we export it here and re use it?

const escapedPattern = escapeRegExp(healthCheckPath);
const augmentedPluginSpec = hasHTTPProxy(value)
? produce(value, (draft) => {
const existing = draft.proxy.spec.allowedEndpoints ?? [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can draft.proxy.spec be undefined? it seems the guard is only checking the proxy.kind

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added additional checks to guard

testConnection,
...others
}: DatasourceSpecEditorProps): ReactElement | null {
const healthCheckPath = plugin.healthCheckPath;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we normalize the healthCheckPath before same as is being done when creating the connection function: https://github.com/perses/shared/pull/99/changes#diff-213ce5cb395fb15fbbfba8fc2d90021672b0bc625e22d683f35faf7341cec040R79

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, we normalize it there because we concatenate it with first part of url, here we just pass it to test function (the one that normalizes)

Comment thread client/src/model/datasource-api.ts Outdated
const pluginSpec = spec.plugin.spec;

if (hasDirectUrl(pluginSpec)) {
await fetch(`${pluginSpec.directUrl.replace(/\/$/, '')}${normalizedPath}`, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should check that the normalized path is not empty, otherwise we will be hitting the current UI which might lead to a successful connection check with an empty url

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed this code to URL, this way if this is not valid url we will get exception

it('does not pass testConnection when plugin has no healthCheckPath', async () => {
const testConnection = jest.fn();
renderComponent({
pluginSelection: { type: 'Variable', kind: 'ErnieVariable1' },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test is not testing the correct plugin, in this case is a Variable plugin

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added another datasource test plugin without healthcheck path

Signed-off-by: Adrian Sepiół <a.sepiol@sap.com>
…ht to prevent duplicate calls

Signed-off-by: Adrian Sepiół <a.sepiol@sap.com>
…h check path

Signed-off-by: Adrian Sepiół <a.sepiol@sap.com>
…ceSpecEditor component

Signed-off-by: Adrian Sepiół <a.sepiol@sap.com>
…serting into allowedEndpoints endpointPattern

Signed-off-by: Adrian Sepiół <a.sepiol@sap.com>
…on validation

Signed-off-by: Adrian Sepiół <a.sepiol@sap.com>
@adrianSepiol
adrianSepiol force-pushed the add-test-connection-button branch from 3dc45bf to 45c6b62 Compare August 12, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants