Skip to content

Allow to export and edit dashboards from Serverless environments#3007

Merged
mrodm merged 23 commits intoelastic:mainfrom
mrodm:update_export_dashboards_apis
Oct 23, 2025
Merged

Allow to export and edit dashboards from Serverless environments#3007
mrodm merged 23 commits intoelastic:mainfrom
mrodm:update_export_dashboards_apis

Conversation

@mrodm
Copy link
Contributor

@mrodm mrodm commented Oct 20, 2025

Closes #2949

This PR allows to export dashboards in Serverless environments (elastic-package export dashboards command).

For Serverless environments, a new set of APIs from Elastic Package Manager have been used:

If this command is used in local stacks, the same behavior is kept. Given that, all dashboards are shown to select which ones to export.

Same changes are applied to the elastic-package edit dashboards command.

This new UX is also applied to Elastic stacks >= 9.0.0.

Author's checklist

  • Check elastic-package export dashboards in Serverless
  • Check elastic-package export dashboards in local stacks (same behavior).
  • Check elastic-package edit dashboards in Serverless
  • Check elastic-package edit dashboards in local stacks (same behavior).

Both commands require the same changes to list dashboards.

Example of usage

First step all installed packages are shown:

 $ elastic-package -C ../integrations-main/packages/nginx export dashboards 
Export Kibana dashboards
Which packages would you like to export dashboards from? (nginx-2.3.2)
  elastic_package_registry-0.3.1
  fleet_server-1.6.0            
> nginx-2.3.2                   
  synthetics-1.4.2              
  The dashboard is not part of a package (show all available dashboards) 
                                

enter continue • ctrl+c cancel

If the user selects a package, it will be shown all the dashboards related to that package (e.g. nginx):

 $ elastic-package -C ../integrations-main/packages/nginx export dashboards 
Export Kibana dashboards
? Which packages would you like to export dashboards from?: nginx-2.3.2
Which dashboards would you like to export?
  Use ↑↓ to navigate, space to toggle selection, enter to confirm
> [ ] [Logs Nginx] Access and error logs (ID: nginx-046212a0-a2a1-11e7-928f-5dbe6f6f5519, Type: dashboard)
  [ ] [Logs Nginx] Overview (ID: nginx-55a9e6e0-a29e-11e7-928f-5dbe6f6f5519, Type: dashboard)             
  [ ] [Metrics Nginx] Overview (ID: nginx-023d2930-f1a5-11e7-a9ef-93c69af7b129, Type: dashboard)          

enter continue • ctrl+c cancel

If the user is developing a new dashboard (and therefore not related to any package), they should choose New dashboard option, and all the dashboards available in the Serverless instance will be shown:

 $ elastic-package -C ../integrations-main/packages/nginx export dashboards 
Export Kibana dashboards
Which packages would you like to export dashboards from? (nginx-2.3.2)
  elastic_package_registry-0.3.1
  fleet_server-1.6.0            
  nginx-2.3.2                   
  synthetics-1.4.2              
> The dashboard is not part of a package (show all available dashboards) 
                                

enter continue • ctrl+c cancel

# After choosing "New dashboard" option

 $ epd -C ../integrations-main/packages/nginx export dashboards 
Export Kibana dashboards
? Which packages would you like to export dashboards from?: The dashboard is not part of a package (show all available dashboards)
Which dashboards would you like to export?
  Use ↑↓ to navigate, space to toggle selection, enter to confirm
> [ ] [EPR Metrics] Overview (ID: elastic_package_registry-313c2700-099b-11ed-91b6-3b1f9c2b2771)
  [ ] [Logs Nginx] Access and error logs (ID: nginx-046212a0-a2a1-11e7-928f-5dbe6f6f5519)       
  [ ] [Logs Nginx] Overview (ID: nginx-55a9e6e0-a29e-11e7-928f-5dbe6f6f5519)                    
  [ ] [Metrics Nginx] Overview (ID: nginx-023d2930-f1a5-11e7-a9ef-93c69af7b129)                 

enter continue • ctrl+c cancel

How to test this PR locally

cd /path/to/package
elastic-package install -v

elastic-package export dashboards -v
elastic-package export dashboards -v --id <some_dashboard_id>

elastic-package edit dashboards -v
elastic-package edit dashboards -v --id <some_dashboard_id>

@mrodm mrodm self-assigned this Oct 20, 2025
Comment on lines +56 to +58
// These fields are not expected to be part of responses from APIs
DataStream string `json:"-"`
SourcePath string `json:"-"`
Copy link
Contributor Author

@mrodm mrodm Oct 20, 2025

Choose a reason for hiding this comment

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

I could not find any usage of these two fields in APIs.
It looks like that they are used in test asset and they are filled programmatically.

DataStream: dsManifest.Name,

DataStream: dsManifest.Name,

SourcePath: assetPath,

If the json:"-" tag is not added to the fields, queries with this struct fail with the error of those fields being not available/undefined.

Comment on lines +36 to +46
func (c *Client) exportAllDashboards(ctx context.Context) ([]common.MapStr, error) {
logger.Debug("Export dashboards using the Kibana Saved Objects Export API")

request := ExportSavedObjectsRequest{
ExcludeExportDetails: true,
IncludeReferencesDeep: false,
Type: "dashboard",
}

return c.ExportSavedObjects(ctx, request)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method would return all the dashboards available in the Kibana Instance.

According to the documentation, the number of assets that will be exported depend on savedObjects.maxImportExportSize setting (link):

NOTE: The savedObjects.maxImportExportSize configuration setting limits the number of saved objects which may be exported.

By default that setting is 10000 elements (savedObjects.maxImportExportSize setting):

The maximum count of saved objects that can be imported or exported. This setting exists to prevent the Kibana server from running out of memory when handling large numbers of saved objects. It is recommended to only raise this setting if you are confident your server can hold this many objects in memory. Default: 10000

Copy link
Member

Choose a reason for hiding this comment

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

10K sounds like enough 🙂

@mrodm
Copy link
Contributor Author

mrodm commented Oct 21, 2025

/test

Comment on lines +191 to +195
// Even if no error is returned, we need to check if the import was successful.
if !resp.Success {
return fmt.Errorf("importing %s %s was not successful", savedObjectType, id)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a new check to ensure that the saved object has been imported successfully:
https://www.elastic.co/docs/api/doc/kibana/operation/operation-post-saved-objects-import

success: Indicates when the import was successfully completed. When set to false, some objects may not have been created.

Comment on lines +97 to +107
// Not mandatory to get the package name here, but it would be helpful for users
// to select by default the package where they are located if any.
defaultPackage := ""
packageRoot, err := packages.MustFindPackageRoot()
if err == nil {
m, err := packages.ReadPackageManifestFromPackageRoot(packageRoot)
if err != nil {
return fmt.Errorf("reading package manifest failed (path: %s): %w", packageRoot, err)
}
defaultPackage = m.Name
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it could be helpful for the user to select the package where they are located if any. But this should not raise an error if the command does not run from a package.

@mrodm mrodm marked this pull request as ready for review October 21, 2025 16:19
@mrodm mrodm requested a review from a team October 21, 2025 16:19
@mrodm
Copy link
Contributor Author

mrodm commented Oct 22, 2025

test integrations

@elastic-vault-github-plugin-prod

Created or updated PR in integrations repository to test this version. Check elastic/integrations#15710

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Nice, works great. Thanks!

Added some comments but mostly nitpicking and suggestions, so they could be ignored 🙂 so approving by now.

dashboardTitle, ok := attributes["title"].(string)
if !ok {
return DashboardSavedObject{}, fmt.Errorf("dashboard object does not contain attributes.title field")
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Maybe it would be easier to use unmarshal? Though for that exportAllData would need to return the raw responses.

mrodm and others added 2 commits October 22, 2025 11:31
Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @mrodm

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Nice.

@mrodm mrodm changed the title Allow to export dashboards from Serverless environments Allow to export and edit dashboards from Serverless environments Oct 23, 2025
@mrodm mrodm merged commit b214464 into elastic:main Oct 23, 2025
3 checks passed
@mrodm mrodm deleted the update_export_dashboards_apis branch October 23, 2025 08:12
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.

Fail to export dashboards in Serverless projects

3 participants