-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[data views] add usage counters to data views REST api endpoints #123107
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
Changes from all commits
17c0619
2c65102
abf76d6
c6bf8be
6bfeffe
20472b2
081161d
18b693b
791a4e6
b2f0949
0a89f9d
68cb8dd
969b72b
4df8211
a27d171
9fa4a62
8083953
18eaa84
a8965f0
1ae61a2
edf0018
6b8ecc0
3800d9f
5305e7d
3648ebd
4b2491c
3dc34d4
03378cb
196b427
51f0f66
dcd8cbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,8 +42,9 @@ export class DataViewsServerPlugin | |
| ) { | ||
| core.savedObjects.registerType(dataViewSavedObjectType); | ||
| core.capabilities.registerProvider(capabilitiesProvider); | ||
| const dataViewRestCounter = usageCollection?.createUsageCounter('dataViewsRestApi'); | ||
|
|
||
| registerRoutes(core.http, core.getStartServices); | ||
| registerRoutes(core.http, core.getStartServices, dataViewRestCounter); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattkime what do you think of accessing the path pattern at the http.registerOnPreResponse((req, res, t) => {
// t.matchedRoute does not exist
usageCollection?.incrementCounter({ counterName: `${req.route.method} ${t.matchedRoute.path}` });
return t.next();
});I'm not sure how common this need is (or what other things that might address). If you agree though perhaps we can suggest it to core. I may also be misunderstanding when
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jloleysens thats an interesting idea - I'll talk to core about it |
||
| expressions.registerFunction(getIndexPatternLoad({ getStartServices: core.getStartServices })); | ||
| registerIndexPatternsUsageCollector(core.getStartServices, usageCollection); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * 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 { createDataView } from './create_data_view'; | ||
| import { dataViewsService } from '../mocks'; | ||
| import { getUsageCollection } from './test_utils'; | ||
|
|
||
| describe('create data view', () => { | ||
| it('call usageCollection', () => { | ||
| const usageCollection = getUsageCollection(); | ||
| createDataView({ | ||
| dataViewsService, | ||
| spec: {}, | ||
| counterName: 'POST /path', | ||
| usageCollection, | ||
| }); | ||
| expect(usageCollection.incrementCounter).toBeCalledTimes(1); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * 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 { setDefault, getDefault } from './default_data_view'; | ||
| import { dataViewsService } from '../mocks'; | ||
| import { getUsageCollection } from './test_utils'; | ||
|
|
||
| describe('default data view', () => { | ||
| it('set - calls usageCollection', () => { | ||
| const usageCollection = getUsageCollection(); | ||
| setDefault({ | ||
| dataViewsService, | ||
| counterName: 'POST /path', | ||
| usageCollection, | ||
| newDefaultId: '1', | ||
| force: false, | ||
| }); | ||
| expect(usageCollection.incrementCounter).toBeCalledTimes(1); | ||
| }); | ||
|
|
||
| it('get - calls usageCollection', () => { | ||
| const usageCollection = getUsageCollection(); | ||
| getDefault({ | ||
| dataViewsService, | ||
| counterName: 'GET /path', | ||
| usageCollection, | ||
| }); | ||
| expect(usageCollection.incrementCounter).toBeCalledTimes(1); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * 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 { deleteDataView } from './delete_data_view'; | ||
| import { dataViewsService } from '../mocks'; | ||
| import { getUsageCollection } from './test_utils'; | ||
|
|
||
| describe('delete data view', () => { | ||
| it('call usageCollection', () => { | ||
| const usageCollection = getUsageCollection(); | ||
| deleteDataView({ | ||
| dataViewsService, | ||
| counterName: 'DELETE /path', | ||
| usageCollection, | ||
| id: '1', | ||
| }); | ||
| expect(usageCollection.incrementCounter).toBeCalledTimes(1); | ||
| }); | ||
| }); |
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.
seems like this isn't used