-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Adds get all REST API to data views #131683
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c989871
Adds get all API to data views
lukasolson 62994dc
Move size to query params
lukasolson 72eba7e
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 02fd034
Use ids/titles instead of entire object
lukasolson 49c18a9
Merge branch 'data-views/get-all' of github.com:lukasolson/kibana int…
lukasolson 9b32e3c
Add docs
lukasolson ce8ad06
Merge remote-tracking branch 'origin' into data-views/get-all
lukasolson 5cae40c
Merge branch 'main' into data-views/get-all
lukasolson f626ac3
Add integration test
lukasolson 03318e8
Fix docs
lukasolson 5b9a329
Merge branch 'main' into data-views/get-all
lukasolson b2d95a4
Update docs
lukasolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
[[data-views-api-get-all]] | ||
=== Get all data views API | ||
++++ | ||
<titleabbrev>Get all data views</titleabbrev> | ||
++++ | ||
|
||
experimental[] Retrieve a list of all data views. | ||
|
||
|
||
[[data-views-api-get-all-request]] | ||
==== Request | ||
|
||
`GET <kibana host>:<port>/api/data_views` | ||
|
||
`GET <kibana host>:<port>/s/<space_id>/api/data_views` | ||
|
||
|
||
[[data-views-api-get-all-codes]] | ||
==== Response code | ||
|
||
`200`:: | ||
Indicates a successful call. | ||
|
||
|
||
[[data-views-api-get-all-example]] | ||
==== Example | ||
|
||
Retrieve the list of data views: | ||
|
||
[source,sh] | ||
-------------------------------------------------- | ||
$ curl -X GET api/data_views | ||
-------------------------------------------------- | ||
// KIBANA | ||
|
||
The API returns a list of data views: | ||
|
||
[source,sh] | ||
-------------------------------------------------- | ||
{ | ||
"data_views": [ | ||
{ | ||
"id": "e9e024f0-d098-11ec-bbe9-c753adcb34bc", | ||
"namespaces": [ | ||
"default" | ||
], | ||
"title": "tmp*", | ||
"typeMeta": {} | ||
}, | ||
{ | ||
"id": "90943e30-9a47-11e8-b64d-95841ca0b247", | ||
"namespaces": [ | ||
"default" | ||
], | ||
"title": "kibana_sample_data_logs" | ||
} | ||
] | ||
} | ||
-------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/plugins/data_views/server/rest_api_routes/get_data_views.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getDataViews } from './get_data_views'; | ||
import { dataViewsService } from '../mocks'; | ||
import { getUsageCollection } from './test_utils'; | ||
|
||
describe('get all data views', () => { | ||
it('call usageCollection', () => { | ||
const usageCollection = getUsageCollection(); | ||
getDataViews({ | ||
dataViewsService, | ||
counterName: 'GET /path', | ||
usageCollection, | ||
}); | ||
expect(usageCollection.incrementCounter).toBeCalledTimes(1); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
src/plugins/data_views/server/rest_api_routes/get_data_views.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { UsageCounter } from '@kbn/usage-collection-plugin/server'; | ||
import { IRouter, StartServicesAccessor } from '@kbn/core/server'; | ||
import { DataViewsService } from '../../common'; | ||
import { handleErrors } from './util/handle_errors'; | ||
import type { DataViewsServerPluginStartDependencies, DataViewsServerPluginStart } from '../types'; | ||
import { SERVICE_PATH, SERVICE_KEY_MULTIPLE } from '../constants'; | ||
|
||
interface GetDataViewsArgs { | ||
dataViewsService: DataViewsService; | ||
usageCollection?: UsageCounter; | ||
counterName: string; | ||
} | ||
|
||
export const getDataViews = async ({ | ||
dataViewsService, | ||
usageCollection, | ||
counterName, | ||
}: GetDataViewsArgs) => { | ||
usageCollection?.incrementCounter({ counterName }); | ||
return dataViewsService.getIdsWithTitle(); | ||
}; | ||
|
||
const getDataViewsRouteFactory = | ||
(path: string, serviceKey: string) => | ||
( | ||
router: IRouter, | ||
getStartServices: StartServicesAccessor< | ||
DataViewsServerPluginStartDependencies, | ||
DataViewsServerPluginStart | ||
>, | ||
usageCollection?: UsageCounter | ||
) => { | ||
router.get( | ||
{ | ||
path, | ||
validate: {}, | ||
}, | ||
router.handleLegacyErrors( | ||
handleErrors(async (ctx, req, res) => { | ||
const core = await ctx.core; | ||
const savedObjectsClient = core.savedObjects.client; | ||
const elasticsearchClient = core.elasticsearch.client.asCurrentUser; | ||
const [, , { dataViewsServiceFactory }] = await getStartServices(); | ||
const dataViewsService = await dataViewsServiceFactory( | ||
savedObjectsClient, | ||
elasticsearchClient, | ||
req | ||
); | ||
|
||
const dataViews = await getDataViews({ | ||
dataViewsService, | ||
usageCollection, | ||
counterName: `${req.route.method} ${path}`, | ||
}); | ||
|
||
return res.ok({ | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
body: { | ||
[serviceKey]: dataViews, | ||
}, | ||
}); | ||
}) | ||
) | ||
); | ||
}; | ||
|
||
export const registerGetDataViewsRoute = getDataViewsRouteFactory( | ||
SERVICE_PATH, | ||
SERVICE_KEY_MULTIPLE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this also return the
type
if not default. add"type": "rollup"
to make this a rollup data view example