Skip to content

Conversation

@joshuali925
Copy link
Member

Description

Prometheus will be stored as data-connection saved objects. Only connection id and MDS datasource id is saved.

        {
          "data-connection": {
            "connectionId": "my_prometheus",
            "type": "Prometheus"
          },
          "type": "data-connection",
          "references": [
            {
              "id": "02ced1b0-c95f-11f0-a5f2-dfc60f85a7e3",
              "type": "data-source",
              "name": "dataSource"
            }
          ],
          "updated_at": "2025-11-24T18:06:37.234Z"
        }

Underlying they are still in SQL, but OSD will use saved objects API to get Prometheus metadata. Users should only use OSD to create/delete prometheus connections if they use UI.

Additionally, this PR supports "No Auth" option when creating prometheus connections.

Issues Resolved

Screenshot

image

Testing the changes

Changelog

  • feat: Create saved object for prometheus data-connection

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

❌ Patch coverage is 58.82353% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.77%. Comparing base (1929553) to head (6cbecce).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...anagement/server/routes/data_connections_router.ts 61.76% 7 Missing and 6 partials ⚠️
...figuration/configure_direct_query_data_sources.tsx 57.14% 2 Missing and 4 partials ⚠️
.../data_source_management/public/components/utils.ts 50.00% 6 Missing ⚠️
...ation/prometheus/review_prometheus_data_source.tsx 0.00% 0 Missing and 2 partials ⚠️
...on/prometheus/configure_prometheus_data_source.tsx 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10968      +/-   ##
==========================================
- Coverage   60.79%   60.77%   -0.03%     
==========================================
  Files        4531     4532       +1     
  Lines      122238   122389     +151     
  Branches    20492    20542      +50     
==========================================
+ Hits        74310    74376      +66     
- Misses      42688    42760      +72     
- Partials     5240     5253      +13     
Flag Coverage Δ
Linux_1 26.55% <0.00%> (-0.01%) ⬇️
Linux_2 38.92% <ø> (ø)
Linux_3 39.51% <58.82%> (?)
Linux_4 33.73% <0.00%> (-0.01%) ⬇️
Windows_1 26.56% <0.00%> (-0.01%) ⬇️
Windows_2 38.90% <ø> (ø)
Windows_3 39.50% <58.82%> (+<0.01%) ⬆️
Windows_4 33.73% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@ps48 ps48 left a comment

Choose a reason for hiding this comment

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

Have some minor comments.
One Question: How permissions are enforced on saved object operations with Datasource backend roles associated to the prometheus PPL datasource?

record.connectionType !== DataSourceConnectionType.OpenSearchConnection
record.connectionType !== DataSourceConnectionType.OpenSearchConnection &&
// Prometheus data-connections are shown on top level
record.type !== 'Prometheus'
Copy link
Member

Choose a reason for hiding this comment

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

Can we use DataConnectionType.Prometheus enum?

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, thanks

export enum DataConnectionType {
CloudWatch = 'AWS CloudWatch',
SecurityLake = 'AWS Security Lake',
Prometheus = 'Prometheus',
Copy link
Member

Choose a reason for hiding this comment

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

Do we need Amazon Prometheus here?

Copy link
Member Author

Choose a reason for hiding this comment

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

let's leave it till later, this PR only modifies the existing prometheus type

Comment on lines +358 to +361
if (statusCode !== 404) {
console.error('Issue in deleting data connection from backend:', error);
const errorBody = error.body ||
error.response || { message: error.message || 'Unknown error occurred' };
Copy link
Member

Choose a reason for hiding this comment

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

why is only 404 handled here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It means SQL side data source is gone, and user is deleting the orphaned data-connection saved object. We should continue

If SQL is not working (5xx) i feel we should directly show error to user and not touch saved objects

Comment on lines 204 to 230
const dataConnectionsresponse = await client('ppl.createDataSource', {
body: {
name: request.body.name,
connector: request.body.connector,
allowedRoles: request.body.allowedRoles,
properties: request.body.properties,
},
});

// Create data-connection saved object for Prometheus datasources
if (request.body.connector === 'prometheus') {
await context.core.savedObjects.client.create(
'data-connection',
{
connectionId: request.body.name,
type: DataConnectionType.Prometheus,
meta: JSON.stringify({ properties: request.body.properties }),
},
{
references: dataSourceMDSId
? [{ id: dataSourceMDSId, type: 'data-source', name: 'dataSource' }]
: [],
}
);
}

return response.ok({ body: dataConnectionsresponse });
Copy link
Member

Choose a reason for hiding this comment

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

May be we can check if ppl datasource was created successfully and only then creation the prometheus saved object?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe if creation in SQL plugin failed, it goes into catch and skips the saved object creation

Comment on lines +456 to +468
if (selectedDataSource.objectType === DATA_CONNECTION_SAVED_OBJECT_TYPE) {
const savedObject = await savedObjectsClient.get(
DATA_CONNECTION_SAVED_OBJECT_TYPE,
selectedDataSource.id
);
const dataSourceMDSId = savedObject.references.find((r) => r.type === 'data-source')?.id;
return http.delete(
`${DATACONNECTIONS_BASE}/${selectedDataSource.title}/dataSourceMDSId=${
dataSourceMDSId || ''
}`
);
}
return deleteDataSourceById(selectedDataSource.id, savedObjectsClient);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to handle scenarios where one deletion fails either saved object or SQL and mention it to the user explicitly?

Copy link
Member

Choose a reason for hiding this comment

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

Some CTA for users as toast to understand what's the inconsistent state.

Copy link
Member Author

Choose a reason for hiding this comment

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

That should be existing logic when calling this utils. The utils only deletes and throws error up

deleteMultipleDataSources(savedObjects.client, selectedDataSources)
.then(() => {
setSelectedDataSources([]);
// Fetch data sources
fetchDataSources();
setConfirmDeleteVisible(false);
// Check if default data source is deleted or not.
// if yes, then set the first existing datasource as default datasource.
setDefaultDataSource();
})
.catch(() => {
handleDisplayToastMessage({
message: i18n.translate(
'dataSourcesManagement.dataSourceListing.deleteDataSourceFailMsg',
{
defaultMessage:
'Error occurred while deleting selected records for Data sources. Please try it again',
}
),
});
})
.finally(() => {
setIsDeleting(false);
});

Comment on lines 167 to 177
<EuiCompressedSelect
id="selectDataSource"
options={[
...(!hideLocalCluster
? [{ value: LocalCluster.id, text: LocalCluster.label }]
: []),
...dataSources.map((ds) => ({ value: ds.id, text: ds.title || ds.id })),
]}
value={currentDataSourceId}
onChange={(e) => setDataSourceIdForRequest(e.target.value)}
data-test-subj="dataSourceSelect"
Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

Signed-off-by: Joshua Li <[email protected]>
@joshuali925 joshuali925 marked this pull request as draft November 25, 2025 23:41
@joshuali925 joshuali925 marked this pull request as ready for review November 26, 2025 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants