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

[Workspace][Bug] Check if workspaces exists when creating saved objects #8739

Conversation

yubonluo
Copy link
Contributor

@yubonluo yubonluo commented Oct 29, 2024

Description

When calling create/bulkCreate save object with API, it needs to check if the passed workspaces exist.

Issues Resolved

Screenshot

No ui change

Testing the changes

Create a saved object

  • option 1
curl -X POST -H "osd-xsrf: true" -H "Content-Type: application/json" \
-d '{
  "attributes": {
    "title": "Revenue Dashboard",
    "description": "Revenue dashboard",
    "panelsJSON": "[{\"version\":\"2.9.0\",\"gridData\":{\"x\":0,\"y\":0,\"w\":24,\"h\":15,\"i\":\"5db1d75d-f680-4869-a0e8-0f2b8b05b99c\"},\"panelIndex\":\"5db1d75d-f680-4869-a0e8-0f2b8b05b99c\",\"embeddableConfig\":{},\"panelRefName\":\"panel_0\"}]",
    "optionsJSON": "{\"hidePanelTitles\":false,\"useMargins\":true}",
    "version": 1,
    "timeRestore": true,
    "kibanaSavedObjectMeta": {
      "searchSourceJSON": "{\"query\":{\"language\":\"kuery\",\"query\":\"\"},\"filter\":[]}"
    }
  },
  "references": [
    {
      "id": "37cc8650-b882-11e8-a6d9-e546fe2bba5f",
      "name": "panel_0",
      "type": "visualization"
    }
  ]
}' \
"http://localhost:5601/w/non-exist-workspace/api/saved_objects/dashboard" -u 'admin:myStrongPassword123!' --insecure

{"statusCode":400,"error":"Bad Request","message":"Exist invalid workspaces"}%
  • option 2
curl -X POST -H "osd-xsrf: true" -H "Content-Type: application/json" \
-d '{
  "attributes": {
    "title": "Revenue Dashboard",
    "description": "Revenue dashboard",
    "panelsJSON": "[{\"version\":\"2.9.0\",\"gridData\":{\"x\":0,\"y\":0,\"w\":24,\"h\":15,\"i\":\"5db1d75d-f680-4869-a0e8-0f2b8b05b99c\"},\"panelIndex\":\"5db1d75d-f680-4869-a0e8-0f2b8b05b99c\",\"embeddableConfig\":{},\"panelRefName\":\"panel_0\"}]",
    "optionsJSON": "{\"hidePanelTitles\":false,\"useMargins\":true}",
    "version": 1,
    "timeRestore": true,
    "kibanaSavedObjectMeta": {
      "searchSourceJSON": "{\"query\":{\"language\":\"kuery\",\"query\":\"\"},\"filter\":[]}"
    }
  },
"workspaces": ["non-exist-workspace1", "non-exist-workspace2"],
  "references": [
    {
      "id": "37cc8650-b882-11e8-a6d9-e546fe2bba5f",
      "name": "panel_0",
      "type": "visualization"
    }
  ]
}' \
"http://localhost:5601/api/saved_objects/dashboard" -u 'admin:myStrongPassword123!' --insecure
{"statusCode":400,"error":"Bad Request","message":"Exist invalid workspaces"}% 

bulk create saved objects

option 1

curl -X POST -H "osd-xsrf: true" -H "Content-Type: application/json" \
-d '[
  {
    "id": "67a9021c-c97e-4499-8150-9722ab44edd4",
    "type": "visualization",
    "attributes": {
      "title": "vega-visualization",
      "fieldFormatMap": "{\"hour_of_day\":{}}",
      "fields": "[{\"name\":\"@timestamp\",\"type\":\"date\",\"esTypes\":[\"date\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]"
    },
    "version": "1",
    "migrationVersion": {},
    "references": [
      {
        "id": "ef71d6c1-8e6b-418d-9f7c-e5d9bbde9cf7",
        "type": "data-source",
        "name": "dataSource"
      }
    ],
    "initialNamespaces": [
      "default"
    ]
  }
]' \
"http://localhost:5601/w/non-exist-workspace/api/saved_objects/_bulk_create" -u 'admin:myStrongPassword123!' --insecure

{"statusCode":400,"error":"Bad Request","message":"Exist invalid workspaces"}% 

option 2

curl -X POST -H "osd-xsrf: true" -H "Content-Type: application/json" \
-d '[
  {
    "id": "67a9021c-c97e-4499-8150-9722ab44edd4",
    "type": "visualization",
    "attributes": {
      "title": "vega-visualization",
      "fieldFormatMap": "{\"hour_of_day\":{}}",
      "fields": "[{\"name\":\"@timestamp\",\"type\":\"date\",\"esTypes\":[\"date\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]"
    },
    "version": "1",
    "migrationVersion": {},
    "references": [
      {
        "id": "ef71d6c1-8e6b-418d-9f7c-e5d9bbde9cf7",
        "type": "data-source",
        "name": "dataSource"
      }
    ],
    "initialNamespaces": [
      "default"
    ]
  }
]' \
"http://localhost:5601/api/saved_objects/_bulk_create?workspaces=non-exist-workspace" -u 'admin:myStrongPassword123!' --insecure
{"statusCode":400,"error":"Bad Request","message":"Exist invalid workspaces"}%  

Changelog

  • fix: [Workspace] [Bug] Check if workspaces exists when creating saved objects.

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

@yubonluo yubonluo changed the title [Workspace] [Bug] Check if workspaces exists when creating saved objects [Workspace][Bug] Check if workspaces exists when creating saved objects Oct 29, 2024
SuZhou-Joe
SuZhou-Joe previously approved these changes Oct 29, 2024
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.88%. Comparing base (080b0db) to head (1fd3501).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ver/saved_objects/workspace_id_consumer_wrapper.ts 90.90% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8739   +/-   ##
=======================================
  Coverage   60.88%   60.88%           
=======================================
  Files        3802     3802           
  Lines       91083    91087    +4     
  Branches    14382    14382           
=======================================
+ Hits        55456    55461    +5     
  Misses      32086    32086           
+ Partials     3541     3540    -1     
Flag Coverage Δ
Linux_1 29.03% <90.90%> (+<0.01%) ⬆️
Linux_2 56.38% <ø> (ø)
Linux_3 37.90% <ø> (ø)
Linux_4 29.00% <ø> (ø)
Windows_1 29.04% <90.90%> (+<0.01%) ⬆️
Windows_2 56.34% <ø> (ø)
Windows_3 37.90% <ø> (ø)
Windows_4 29.00% <ø> (ø)

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.

@ananzh
Copy link
Member

ananzh commented Oct 29, 2024

I think we also need to fix the tests. Then I could help to approve.

Signed-off-by: yubonluo <[email protected]>
…yubonluo/OpenSearch-Dashboards into 2.18/fix-create-saved-objects-api-issue
Signed-off-by: yubonluo <[email protected]>
Signed-off-by: yubonluo <[email protected]>
Signed-off-by: yubonluo <[email protected]>
Signed-off-by: yubonluo <[email protected]>
SuZhou-Joe
SuZhou-Joe previously approved these changes Dec 2, 2024
Signed-off-by: yubonluo <[email protected]>
invalidWorkspaces = [workspaces[0]];
}
} else {
const workspaceList = await this.workspaceClient.list(
Copy link
Member

Choose a reason for hiding this comment

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

I'm good with the current implementation, but perhaps we should introduce a new workspaceClient.bulkGet API, can we add a TODO item if it makes sense? @yubonluo @SuZhou-Joe

@ruanyl ruanyl merged commit 340326f into opensearch-project:main Dec 3, 2024
69 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 3, 2024
…ts (#8739)

* Check if workspaces exists when creating saved objects

Signed-off-by: yubonluo <[email protected]>

* Changeset file for PR #8739 created/updated

* optimize the code

Signed-off-by: yubonluo <[email protected]>

* fix test error

Signed-off-by: yubonluo <[email protected]>

* optimize the code

Signed-off-by: yubonluo <[email protected]>

* fix test errors

Signed-off-by: yubonluo <[email protected]>

* add integration tests

Signed-off-by: yubonluo <[email protected]>

---------

Signed-off-by: yubonluo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 340326f)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
wanglam pushed a commit to wanglam/OpenSearch-Dashboards that referenced this pull request Dec 4, 2024
…ts (opensearch-project#8739)

* Check if workspaces exists when creating saved objects

Signed-off-by: yubonluo <[email protected]>

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

* optimize the code

Signed-off-by: yubonluo <[email protected]>

* fix test error

Signed-off-by: yubonluo <[email protected]>

* optimize the code

Signed-off-by: yubonluo <[email protected]>

* fix test errors

Signed-off-by: yubonluo <[email protected]>

* add integration tests

Signed-off-by: yubonluo <[email protected]>

---------

Signed-off-by: yubonluo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
ArgusLi pushed a commit to ArgusLi/OpenSearch-Dashboards that referenced this pull request Dec 11, 2024
…ts (opensearch-project#8739)

* Check if workspaces exists when creating saved objects

Signed-off-by: yubonluo <[email protected]>

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

* optimize the code

Signed-off-by: yubonluo <[email protected]>

* fix test error

Signed-off-by: yubonluo <[email protected]>

* optimize the code

Signed-off-by: yubonluo <[email protected]>

* fix test errors

Signed-off-by: yubonluo <[email protected]>

* add integration tests

Signed-off-by: yubonluo <[email protected]>

---------

Signed-off-by: yubonluo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
silva-qa pushed a commit to silva-qa/OpenSearch-Dashboards that referenced this pull request Dec 12, 2024
…ts (opensearch-project#8739)

* Check if workspaces exists when creating saved objects

Signed-off-by: yubonluo <[email protected]>

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

* optimize the code

Signed-off-by: yubonluo <[email protected]>

* fix test error

Signed-off-by: yubonluo <[email protected]>

* optimize the code

Signed-off-by: yubonluo <[email protected]>

* fix test errors

Signed-off-by: yubonluo <[email protected]>

* add integration tests

Signed-off-by: yubonluo <[email protected]>

---------

Signed-off-by: yubonluo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: Federico Silva <[email protected]>
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