Skip to content

[Workspace] feat: update workspace server to support data connection type#8200

Merged
SuZhou-Joe merged 3 commits intoopensearch-project:mainfrom
raintygao:connection-server
Sep 14, 2024
Merged

[Workspace] feat: update workspace server to support data connection type#8200
SuZhou-Joe merged 3 commits intoopensearch-project:mainfrom
raintygao:connection-server

Conversation

@raintygao
Copy link
Copy Markdown
Contributor

@raintygao raintygao commented Sep 14, 2024

Description

Update workspace server to support data connection type

This is a PR picked from #8013, as we want to separate frontend and server changes and merge server changes first for testing, so we extract server changes from #8013 and create this PR.

Testing the changes

Create workspace

post http://localhost:6601/api/workspaces

{
    "attributes": {
        "name": "workspace-name1",
        "color": "#54B399",
        "features": [
            "use-case-observability"
        ]
    },
    "settings": {
        "dataSources": [],
        "dataConnections": [
            "12345" // data connection object id
        ],
        "permissions": {
            "library_write": {
                "users": [
                    "%me%"
                ]
            },
            "write": {
                "users": [
                    "%me%"
                ]
            }
        }
    }
}

Result

{
    "success": true,
    "result": {
        "id": "_IlxNR"
    }
}

Update workspace

put http://localhost:6601/api/_IlxNR

{
    "attributes": {
        "name": "workspace-name1",
        "color": "#54B399",
        "features": [
            "use-case-observability"
        ]
    },
    "settings": {
        "dataSources": [],
        "dataConnections": [
            "12346" // new data connection object ids that you want to associate
        ],
        "permissions": {
            "library_write": {
                "users": [
                    "%me%"
                ]
            },
            "write": {
                "users": [
                    "%me%"
                ]
            }
        }
    }
}

Result

{
    "success": true,
    "result": true
}

Verify

get data-connection objects with workspace field
http://localhost:6601/api/saved_objects/_find?fields=id&fields=title&fields=workspaces&per_page=10000&type=data-connection&workspaces=*

Result
image

Changelog

  • feat: update workspace server to support data connection type

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
Copy Markdown

codecov bot commented Sep 14, 2024

Codecov Report

Attention: Patch coverage is 97.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 64.05%. Comparing base (21f4218) to head (35996f2).
Report is 42 commits behind head on main.

Files with missing lines Patch % Lines
...ed_objects_wrapper_for_check_workspace_conflict.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8200   +/-   ##
=======================================
  Coverage   64.04%   64.05%           
=======================================
  Files        3740     3741    +1     
  Lines       88608    88635   +27     
  Branches    13799    13803    +4     
=======================================
+ Hits        56746    56772   +26     
- Misses      31264    31265    +1     
  Partials      598      598           
Flag Coverage Δ
Linux_1 30.06% <97.50%> (+0.02%) ⬆️
Linux_2 58.83% <ø> (ø)
Linux_3 40.37% <ø> (+<0.01%) ⬆️
Linux_4 31.46% <ø> (-0.01%) ⬇️
Windows_1 30.08% <97.50%> (+0.02%) ⬆️
Windows_2 58.78% <ø> (ø)
Windows_3 40.37% <ø> (+<0.01%) ⬆️
Windows_4 31.46% <ø> (ø)

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.

Signed-off-by: tygao <tygao@amazon.com>
@raintygao raintygao changed the title feat: update workspace server to support data connection type [Workspace] feat: update workspace server to support data connection type Sep 14, 2024
"requiredPlugins": ["opensearchDashboardsUtils"],
"optionalPlugins": [],
"extraPublicDirs": ["common/data_sources", "common/util"]
"extraPublicDirs": ["common","common/data_sources", "common/util"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like a new pattern to me, so it will bypass the lint check?

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.

Copy link
Copy Markdown
Member

@SuZhou-Joe SuZhou-Joe left a comment

Choose a reason for hiding this comment

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

LGTM, so the permission on the data connections will be raised in another PR?

@raintygao
Copy link
Copy Markdown
Contributor Author

LGTM, so the permission on the data connections will be raised in another PR?

Yes, this will be addressed and included in later PRs.

Comment on lines +285 to 309
if (newDataConnections) {
const originalSelectedDataConnectionIds = originalSelectedDataSourcesAndConnections
.filter((item) => item.type === DATA_CONNECTION_SAVED_OBJECT_TYPE)
.map((ds) => ds.id);
const dataConnectionsToBeRemoved = originalSelectedDataConnectionIds.filter(
(ds) => !newDataConnections.find((item) => item === ds)
);
const dataConnectionsToBeAdded = newDataConnections.filter(
(ds) => !originalSelectedDataConnectionIds.find((item) => item === ds)
);
if (dataConnectionsToBeRemoved.length > 0) {
for (const dataConnectionId of dataConnectionsToBeRemoved) {
promises.push(
client.deleteFromWorkspaces(DATA_CONNECTION_SAVED_OBJECT_TYPE, dataConnectionId, [id])
);
}
}
if (dataConnectionsToBeAdded.length > 0) {
for (const dataConnectionId of dataConnectionsToBeAdded) {
promises.push(
client.addToWorkspaces(DATA_CONNECTION_SAVED_OBJECT_TYPE, dataConnectionId, [id])
);
}
}
}
Copy link
Copy Markdown
Member

@SuZhou-Joe SuZhou-Joe Sep 14, 2024

Choose a reason for hiding this comment

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

Nit: seems like the logic to handle the data connection are the same as data source, would it be possible to make it into a function like addOperationsToPromisesList(type: string)?

So the code here will be like

const promises = [];
const addOperationsToPromisesList = (type: string) => { xxx }

// Add data sources operations into promise
addOperationsToPromisesList(DATA_SOURCE_SAVED_OBJECT_TYPE);

// Add data connections operations into promise
addOperationsToPromisesList(DATA_CONNECTION_SAVED_OBJECT_TYPE);

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.

Sounds good, will optimize this part in #8013.

settings: {
dataSources?: string[];
permissions?: SavedObjectPermissions;
dataConnections?: string[];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not reuse dataSources? It doesn't seem necessary to add an extra parameter dataConnections. Because for workspace, they are all data sources, I personally don't want it to be implemented in a way that every time adding new type of data source, it requires to change the API interface.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what's passed in here is just saved object ids, we could handle different type of data source internally.

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.

Yes, if we reuse dataSources field, we need to update this field from [‘id1’,‘id2’] to [{type:‘data-source’,id:‘id1’},{type:‘data-connection’,id:‘id2’], which would make a breaking change to existing API.

@SuZhou-Joe SuZhou-Joe merged commit f338aff into opensearch-project:main Sep 14, 2024
opensearch-trigger-bot bot pushed a commit that referenced this pull request Sep 16, 2024
…type (#8200)

* feat: update worksapce server to support data connection type

Signed-off-by: tygao <tygao@amazon.com>

* Changeset file for PR #8200 created/updated

* test: add tests for wrapper

Signed-off-by: tygao <tygao@amazon.com>

---------

Signed-off-by: tygao <tygao@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit f338aff)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ashwin-pc pushed a commit that referenced this pull request Sep 16, 2024
…type (#8200) (#8203)

* feat: update worksapce server to support data connection type



* Changeset file for PR #8200 created/updated

* test: add tests for wrapper



---------



(cherry picked from commit f338aff)

Signed-off-by: tygao <tygao@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
yubonluo pushed a commit to yubonluo/OpenSearch-Dashboards that referenced this pull request Sep 25, 2024
…type (opensearch-project#8200) (opensearch-project#8203)

* feat: update worksapce server to support data connection type



* Changeset file for PR opensearch-project#8200 created/updated

* test: add tests for wrapper



---------



(cherry picked from commit f338aff)

Signed-off-by: tygao <tygao@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
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.

5 participants