Skip to content

Commit

Permalink
make type hidden + final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Jun 21, 2021
1 parent 764a6db commit 0992e24
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

export { startTrackingEventLoopDelaysUsage } from './event_loop_delays';
export { registerEventLoopDelaysCollector } from './event_loop_delays_usage_collector';
export { SAVED_OBJECTS_DAILY_TYPE } from './saved_objects';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ISavedObjectsRepository } from '../../../../../../core/server';
import { deleteHistogramSavedObjects } from '../saved_objects';

/**
* Deletes docs older than 3 days
* daily rollup function. Deletes histogram saved objects older than 3 days
* @param logger
* @param savedObjectsClient
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import moment from 'moment';
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
});
let esServer: TestElasticsearchUtils;

function createRawObject(pid: number, date: moment.MomentInput) {
function createRawObject(date: moment.MomentInput) {
const pid = Math.round(Math.random() * 10000);
return {
type: SAVED_OBJECTS_DAILY_TYPE,
id: serializeSavedObjectId({ pid, date }),
Expand All @@ -41,33 +41,36 @@ function createRawObject(pid: number, date: moment.MomentInput) {
}

const rawEventLoopDelaysDaily = [
createRawObject(12351, moment.now()),
createRawObject(9019, moment.now()),
createRawObject(12351, moment().subtract(1, 'days')),
createRawObject(12351, moment().subtract(3, 'days')),
createRawObject(12351, moment().subtract(5, 'days')),
createRawObject(12351, moment().subtract(1, 'weeks')),
createRawObject(moment.now()),
createRawObject(moment.now()),
createRawObject(moment().subtract(1, 'days')),
createRawObject(moment().subtract(3, 'days')),
];

const outdatedRawEventLoopDelaysDaily = [
createRawObject(moment().subtract(5, 'days')),
createRawObject(moment().subtract(7, 'days')),
];

describe('daily rollups integration test', () => {
let esServer: TestElasticsearchUtils;
let root: TestKibanaUtils['root'];
let internalRepository: ISavedObjectsRepository;
let logger: Logger;

beforeAll(async () => {
esServer = await startES();
root = createRootWithCorePlugins({
server: {
basePath: '/daily_test',
},
});
root = createRootWithCorePlugins();

await root.setup();
const start = await root.start();
logger = root.logger.get('test dailt rollups');
internalRepository = start.savedObjects.createInternalRepository();
internalRepository = start.savedObjects.createInternalRepository([SAVED_OBJECTS_DAILY_TYPE]);

await internalRepository.bulkCreate<EventLoopDelaysDaily>(rawEventLoopDelaysDaily);
await internalRepository.bulkCreate<EventLoopDelaysDaily>(
[...rawEventLoopDelaysDaily, ...outdatedRawEventLoopDelaysDaily],
{ refresh: true }
);
});

afterAll(async () => {
Expand All @@ -81,9 +84,9 @@ describe('daily rollups integration test', () => {
total,
saved_objects: savedObjects,
} = await internalRepository.find<EventLoopDelaysDaily>({ type: SAVED_OBJECTS_DAILY_TYPE });
expect(total).toBe(4);
expect(total).toBe(rawEventLoopDelaysDaily.length);
expect(savedObjects.map(({ id, type, attributes }) => ({ id, type, attributes }))).toEqual(
rawEventLoopDelaysDaily.slice(0, 4)
rawEventLoopDelaysDaily
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface EventLoopDelaysDaily extends SavedObjectAttributes, IntervalHis
export function registerSavedObjectTypes(registerType: SavedObjectsServiceSetup['registerType']) {
registerType({
name: SAVED_OBJECTS_DAILY_TYPE,
hidden: false,
hidden: true,
namespaceType: 'agnostic',
mappings: {
dynamic: false,
Expand Down
119 changes: 59 additions & 60 deletions src/plugins/kibana_usage_collection/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
createUsageCollectionSetupMock,
} from '../../usage_collection/server/mocks';
import { cloudDetailsMock } from './mocks';

import { plugin } from './';

describe('kibana_usage_collection', () => {
Expand Down Expand Up @@ -52,65 +51,65 @@ describe('kibana_usage_collection', () => {
})
)
).resolves.toMatchInlineSnapshot(`
Array [
Object {
"isReady": true,
"type": "ui_counters",
},
Object {
"isReady": true,
"type": "usage_counters",
},
Object {
"isReady": false,
"type": "kibana_stats",
},
Object {
"isReady": true,
"type": "kibana",
},
Object {
"isReady": true,
"type": "saved_objects_counts",
},
Object {
"isReady": false,
"type": "stack_management",
},
Object {
"isReady": false,
"type": "ui_metric",
},
Object {
"isReady": false,
"type": "application_usage",
},
Object {
"isReady": false,
"type": "cloud_provider",
},
Object {
"isReady": true,
"type": "csp",
},
Object {
"isReady": false,
"type": "core",
},
Object {
"isReady": false,
"type": "kibana_config_usage",
},
Object {
"isReady": true,
"type": "localization",
},
Object {
"isReady": true,
"type": "event_loop_delays",
},
]
`);
Array [
Object {
"isReady": true,
"type": "ui_counters",
},
Object {
"isReady": true,
"type": "usage_counters",
},
Object {
"isReady": false,
"type": "kibana_stats",
},
Object {
"isReady": true,
"type": "kibana",
},
Object {
"isReady": true,
"type": "saved_objects_counts",
},
Object {
"isReady": false,
"type": "stack_management",
},
Object {
"isReady": false,
"type": "ui_metric",
},
Object {
"isReady": false,
"type": "application_usage",
},
Object {
"isReady": false,
"type": "cloud_provider",
},
Object {
"isReady": true,
"type": "csp",
},
Object {
"isReady": false,
"type": "core",
},
Object {
"isReady": false,
"type": "kibana_config_usage",
},
Object {
"isReady": true,
"type": "localization",
},
Object {
"isReady": true,
"type": "event_loop_delays",
},
]
`);
});

test('Runs the start method without issues', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/kibana_usage_collection/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import type {
CoreUsageDataStart,
} from 'src/core/server';
import { SavedObjectsClient } from '../../../core/server';
import { startTrackingEventLoopDelaysUsage } from './collectors/event_loop_delays';
import {
startTrackingEventLoopDelaysUsage,
SAVED_OBJECTS_DAILY_TYPE,
} from './collectors/event_loop_delays';
import {
registerApplicationUsageCollector,
registerKibanaUsageCollector,
Expand Down Expand Up @@ -78,7 +81,7 @@ export class KibanaUsageCollectionPlugin implements Plugin {

public start(core: CoreStart) {
const { savedObjects, uiSettings } = core;
this.savedObjectsClient = savedObjects.createInternalRepository();
this.savedObjectsClient = savedObjects.createInternalRepository([SAVED_OBJECTS_DAILY_TYPE]);
const savedObjectsClient = new SavedObjectsClient(this.savedObjectsClient);
this.uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient);
core.metrics.getOpsMetrics$().subscribe(this.metric$);
Expand Down

0 comments on commit 0992e24

Please sign in to comment.