Skip to content

Commit

Permalink
[Usage collection] Usage counters (elastic#96696)
Browse files Browse the repository at this point in the history
Co-authored-by: Alejandro Fernández Haro <[email protected]>
  • Loading branch information
2 people authored and kibanamachine committed Apr 14, 2021
1 parent 3a4d96a commit 8d4acfe
Show file tree
Hide file tree
Showing 75 changed files with 3,120 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```typescript
start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps): {
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("../../../../core/server").SavedObjectsClient, "get" | "delete" | "create" | "bulkCreate" | "checkConflicts" | "find" | "bulkGet" | "resolve" | "update" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo" | "openPointInTimeForType" | "closePointInTime" | "createPointInTimeFinder" | "errors">, elasticsearchClient: ElasticsearchClient) => Promise<IndexPatternsCommonService>;
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("../../../../core/server").SavedObjectsClient, "update" | "get" | "delete" | "create" | "bulkCreate" | "checkConflicts" | "find" | "bulkGet" | "resolve" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo" | "openPointInTimeForType" | "closePointInTime" | "createPointInTimeFinder" | "errors">, elasticsearchClient: ElasticsearchClient) => Promise<IndexPatternsCommonService>;
};
```

Expand All @@ -22,6 +22,6 @@ start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps):
<b>Returns:</b>

`{
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("../../../../core/server").SavedObjectsClient, "get" | "delete" | "create" | "bulkCreate" | "checkConflicts" | "find" | "bulkGet" | "resolve" | "update" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo" | "openPointInTimeForType" | "closePointInTime" | "createPointInTimeFinder" | "errors">, elasticsearchClient: ElasticsearchClient) => Promise<IndexPatternsCommonService>;
indexPatternsServiceFactory: (savedObjectsClient: Pick<import("../../../../core/server").SavedObjectsClient, "update" | "get" | "delete" | "create" | "bulkCreate" | "checkConflicts" | "find" | "bulkGet" | "resolve" | "addToNamespaces" | "deleteFromNamespaces" | "bulkUpdate" | "removeReferencesTo" | "openPointInTimeForType" | "closePointInTime" | "createPointInTimeFinder" | "errors">, elasticsearchClient: ElasticsearchClient) => Promise<IndexPatternsCommonService>;
}`

1 change: 1 addition & 0 deletions src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { PublicMethodsOf } from '@kbn/utility-types';
import { RecursiveReadonly } from '@kbn/utility-types';
import { RequestAdapter } from 'src/plugins/inspector/common';
import { RequestHandlerContext } from 'src/core/server';
import * as Rx from 'rxjs';
import { SavedObject } from 'kibana/server';
import { SavedObject as SavedObject_2 } from 'src/core/server';
import { SavedObjectsClientContract } from 'src/core/server';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { savedObjectsRepositoryMock, loggingSystemMock } from '../../../../../co
import {
Collector,
createUsageCollectionSetupMock,
} from '../../../../usage_collection/server/usage_collection.mock';
} from '../../../../usage_collection/server/mocks';
import { MAIN_APP_DEFAULT_VIEW_ID } from '../../../../usage_collection/common/constants';
import { createCollectorFetchContextMock } from 'src/plugins/usage_collection/server/mocks';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,23 @@ import {
Collector,
createUsageCollectionSetupMock,
createCollectorFetchContextMock,
} from '../../../../usage_collection/server/usage_collection.mock';
} from '../../../../usage_collection/server/mocks';

import { registerCloudProviderUsageCollector } from './cloud_provider_collector';

describe('registerCloudProviderUsageCollector', () => {
let collector: Collector<unknown>;
const logger = loggingSystemMock.createLogger();

const usageCollectionMock = createUsageCollectionSetupMock();
usageCollectionMock.makeUsageCollector.mockImplementation((config) => {
collector = new Collector(logger, config);
return createUsageCollectionSetupMock().makeUsageCollector(config);
});

const mockedFetchContext = createCollectorFetchContextMock();

beforeEach(() => {
cloudDetailsMock.mockClear();
detectCloudServiceMock.mockClear();
const usageCollectionMock = createUsageCollectionSetupMock();
usageCollectionMock.makeUsageCollector.mockImplementation((config) => {
collector = new Collector(logger, config);
return createUsageCollectionSetupMock().makeUsageCollector(config);
});
registerCloudProviderUsageCollector(usageCollectionMock);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {
Collector,
createUsageCollectionSetupMock,
} from '../../../../usage_collection/server/usage_collection.mock';
} from '../../../../usage_collection/server/mocks';
import { createCollectorFetchContextMock } from 'src/plugins/usage_collection/server/mocks';
import { registerCoreUsageCollector } from '.';
import { coreUsageDataServiceMock, loggingSystemMock } from '../../../../../core/server/mocks';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export {
registerUiCounterSavedObjectType,
registerUiCountersRollups,
} from './ui_counters';
export {
registerUsageCountersRollups,
registerUsageCountersUsageCollector,
} from './usage_counters';
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Collector,
createCollectorFetchContextMock,
createUsageCollectionSetupMock,
} from '../../../../usage_collection/server/usage_collection.mock';
} from '../../../../usage_collection/server/mocks';
import { registerKibanaUsageCollector } from './';

const logger = loggingSystemMock.createLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Collector,
createUsageCollectionSetupMock,
createCollectorFetchContextMock,
} from '../../../../usage_collection/server/usage_collection.mock';
} from '../../../../usage_collection/server/mocks';

import {
registerManagementUsageCollector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Collector,
createUsageCollectionSetupMock,
createCollectorFetchContextMock,
} from '../../../../usage_collection/server/usage_collection.mock';
} from '../../../../usage_collection/server/mocks';

import { registerOpsStatsCollector } from './';
import { OpsMetrics } from '../../../../../core/server';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 type { UICounterSavedObject } from '../ui_counter_saved_object_type';
export const rawUiCounters: UICounterSavedObject[] = [
{
type: 'ui-counter',
id: 'Kibana_home:23102020:click:different_type',
attributes: {
count: 1,
},
references: [],
updated_at: '2020-11-24T11:27:57.067Z',
version: 'WzI5NDRd',
},
{
type: 'ui-counter',
id: 'Kibana_home:25102020:loaded:intersecting_event',
attributes: {
count: 1,
},
references: [],
updated_at: '2020-10-25T11:27:57.067Z',
version: 'WzI5NDRd',
},
{
type: 'ui-counter',
id: 'Kibana_home:23102020:loaded:intersecting_event',
attributes: {
count: 3,
},
references: [],
updated_at: '2020-10-23T11:27:57.067Z',
version: 'WzI5NDRd',
},
{
type: 'ui-counter',
id: 'Kibana_home:24112020:click:only_reported_in_ui_counters',
attributes: {
count: 1,
},
references: [],
updated_at: '2020-11-24T11:27:57.067Z',
version: 'WzI5NDRd',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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 type { UsageCountersSavedObject } from '../../../../../usage_collection/server';

export const rawUsageCounters: UsageCountersSavedObject[] = [
{
type: 'usage-counters',
id: 'uiCounter:09042021:count:myApp:my_event',
attributes: {
count: 1,
counterName: 'myApp:my_event',
counterType: 'count',
domainId: 'uiCounter',
},
references: [],
coreMigrationVersion: '8.0.0',
updated_at: '2021-04-09T08:17:57.693Z',
},
{
type: 'usage-counters',
id: 'uiCounter:23102020:loaded:Kibana_home:intersecting_event',
attributes: {
count: 60,
counterName: 'Kibana_home:intersecting_event',
counterType: 'loaded',
domainId: 'uiCounter',
},
references: [],
coreMigrationVersion: '8.0.0',
updated_at: '2020-10-23T11:27:57.067Z',
},
{
type: 'usage-counters',
id: 'uiCounter:09042021:count:myApp:my_event_4457914848544',
attributes: {
count: 0,
counterName: 'myApp:my_event_4457914848544',
counterType: 'count',
domainId: 'uiCounter',
},
references: [],
coreMigrationVersion: '8.0.0',
updated_at: '2021-04-09T08:18:03.030Z',
},
{
type: 'usage-counters',
id: 'uiCounter:09042021:count:myApp:my_event_malformed',
attributes: {
// @ts-expect-error
count: 'malformed',
counterName: 'myApp:my_event_malformed',
counterType: 'count',
domainId: 'uiCounter',
},
references: [],
coreMigrationVersion: '8.0.0',
updated_at: '2021-04-09T08:18:03.030Z',
},
{
type: 'usage-counters',
id: 'anotherDomainId:09042021:count:some_event_name',
attributes: {
count: 4,
counterName: 'some_event_name',
counterType: 'count',
domainId: 'anotherDomainId',
},
references: [],
coreMigrationVersion: '8.0.0',
updated_at: '2021-04-09T08:18:03.030Z',
},
{
type: 'usage-counters',
id: 'uiCounter:09042021:count:myApp:my_event_4457914848544_2',
attributes: {
count: 8,
counterName: 'myApp:my_event_4457914848544_2',
counterType: 'count',
domainId: 'uiCounter',
},
references: [],
coreMigrationVersion: '8.0.0',
updated_at: '2021-04-09T08:18:03.031Z',
},
{
type: 'usage-counters',
id: 'uiCounter:09042021:count:myApp:only_reported_in_usage_counters',
attributes: {
count: 1,
counterName: 'myApp:only_reported_in_usage_counters',
counterType: 'count',
domainId: 'uiCounter',
},
references: [],
coreMigrationVersion: '8.0.0',
updated_at: '2021-04-09T08:18:03.031Z',
},
];
Loading

0 comments on commit 8d4acfe

Please sign in to comment.