-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Create saved object for prometheus data-connection #10968
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Joshua Li <[email protected]>
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ps48
left a comment
There was a problem hiding this 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' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| 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' }; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| 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 }); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Lines 451 to 474 in f129a7e
| 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); | |
| }); |
| <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" |
There was a problem hiding this comment.
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]>
Signed-off-by: Joshua Li <[email protected]>
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
Testing the changes
Changelog
Check List
yarn test:jestyarn test:jest_integration