Skip to content
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

Update core usage stats collection #85706

Merged
merged 5 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/core/server/core_usage_data/core_usage_data_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { config as RawHttpConfig } from '../http/http_config';
import { config as RawLoggingConfig } from '../logging/logging_config';
import { config as RawKibanaConfig } from '../kibana_config';
import { savedObjectsConfig as RawSavedObjectsConfig } from '../saved_objects/saved_objects_config';
import { httpServiceMock } from '../http/http_service.mock';
import { metricsServiceMock } from '../metrics/metrics_service.mock';
import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock';

Expand Down Expand Up @@ -68,11 +69,12 @@ describe('CoreUsageDataService', () => {

describe('setup', () => {
it('creates internal repository', async () => {
const http = httpServiceMock.createInternalSetupContract();
const metrics = metricsServiceMock.createInternalSetupContract();
const savedObjectsStartPromise = Promise.resolve(
savedObjectsServiceMock.createStartContract()
);
service.setup({ metrics, savedObjectsStartPromise });
service.setup({ http, metrics, savedObjectsStartPromise });

const savedObjects = await savedObjectsStartPromise;
expect(savedObjects.createInternalRepository).toHaveBeenCalledTimes(1);
Expand All @@ -81,14 +83,12 @@ describe('CoreUsageDataService', () => {

describe('#registerType', () => {
it('registers core usage stats type', async () => {
const http = httpServiceMock.createInternalSetupContract();
const metrics = metricsServiceMock.createInternalSetupContract();
const savedObjectsStartPromise = Promise.resolve(
savedObjectsServiceMock.createStartContract()
);
const coreUsageData = service.setup({
metrics,
savedObjectsStartPromise,
});
const coreUsageData = service.setup({ http, metrics, savedObjectsStartPromise });
const typeRegistry = typeRegistryMock.create();

coreUsageData.registerType(typeRegistry);
Expand All @@ -104,14 +104,12 @@ describe('CoreUsageDataService', () => {

describe('#getClient', () => {
it('returns client', async () => {
const http = httpServiceMock.createInternalSetupContract();
const metrics = metricsServiceMock.createInternalSetupContract();
const savedObjectsStartPromise = Promise.resolve(
savedObjectsServiceMock.createStartContract()
);
const coreUsageData = service.setup({
metrics,
savedObjectsStartPromise,
});
const coreUsageData = service.setup({ http, metrics, savedObjectsStartPromise });

const usageStatsClient = coreUsageData.getClient();
expect(usageStatsClient).toBeInstanceOf(CoreUsageStatsClient);
Expand All @@ -122,11 +120,12 @@ describe('CoreUsageDataService', () => {
describe('start', () => {
describe('getCoreUsageData', () => {
it('returns core metrics for default config', async () => {
const http = httpServiceMock.createInternalSetupContract();
const metrics = metricsServiceMock.createInternalSetupContract();
const savedObjectsStartPromise = Promise.resolve(
savedObjectsServiceMock.createStartContract()
);
service.setup({ metrics, savedObjectsStartPromise });
service.setup({ http, metrics, savedObjectsStartPromise });
const elasticsearch = elasticsearchServiceMock.createStart();
elasticsearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({
body: [
Expand Down Expand Up @@ -296,6 +295,7 @@ describe('CoreUsageDataService', () => {
observables.push(newObservable);
return newObservable;
});
const http = httpServiceMock.createInternalSetupContract();
const metrics = metricsServiceMock.createInternalSetupContract();
metrics.getOpsMetrics$.mockImplementation(() => {
const newObservable = hot('-a-------');
Expand All @@ -306,7 +306,7 @@ describe('CoreUsageDataService', () => {
savedObjectsServiceMock.createStartContract()
);

service.setup({ metrics, savedObjectsStartPromise });
service.setup({ http, metrics, savedObjectsStartPromise });

// Use the stopTimer$ to delay calling stop() until the third frame
const stopTimer$ = cold('---a|');
Expand Down
7 changes: 4 additions & 3 deletions src/core/server/core_usage_data/core_usage_data_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CoreService } from 'src/core/types';
import { Logger, SavedObjectsServiceStart, SavedObjectTypeRegistry } from 'src/core/server';
import { CoreContext } from '../core_context';
import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config';
import { HttpConfigType } from '../http';
import { HttpConfigType, InternalHttpServiceSetup } from '../http';
import { LoggingConfigType } from '../logging';
import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config';
import {
Expand All @@ -42,6 +42,7 @@ import { CoreUsageStatsClient } from './core_usage_stats_client';
import { MetricsServiceSetup, OpsMetrics } from '..';

export interface SetupDeps {
http: InternalHttpServiceSetup;
metrics: MetricsServiceSetup;
savedObjectsStartPromise: Promise<SavedObjectsServiceStart>;
}
Expand Down Expand Up @@ -248,7 +249,7 @@ export class CoreUsageDataService implements CoreService<CoreUsageDataSetup, Cor
};
}

setup({ metrics, savedObjectsStartPromise }: SetupDeps) {
setup({ http, metrics, savedObjectsStartPromise }: SetupDeps) {
metrics
.getOpsMetrics$()
.pipe(takeUntil(this.stop$))
Expand Down Expand Up @@ -300,7 +301,7 @@ export class CoreUsageDataService implements CoreService<CoreUsageDataSetup, Cor
const getClient = () => {
const debugLogger = (message: string) => this.logger.debug(message);

return new CoreUsageStatsClient(debugLogger, internalRepositoryPromise);
return new CoreUsageStatsClient(debugLogger, http.basePath, internalRepositoryPromise);
};

this.coreUsageStatsClient = getClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import { CoreUsageStatsClient } from '.';
const createUsageStatsClientMock = () =>
(({
getUsageStats: jest.fn().mockResolvedValue({}),
incrementSavedObjectsBulkCreate: jest.fn().mockResolvedValue(null),
incrementSavedObjectsBulkGet: jest.fn().mockResolvedValue(null),
incrementSavedObjectsBulkUpdate: jest.fn().mockResolvedValue(null),
incrementSavedObjectsCreate: jest.fn().mockResolvedValue(null),
incrementSavedObjectsDelete: jest.fn().mockResolvedValue(null),
incrementSavedObjectsFind: jest.fn().mockResolvedValue(null),
incrementSavedObjectsGet: jest.fn().mockResolvedValue(null),
incrementSavedObjectsUpdate: jest.fn().mockResolvedValue(null),
incrementSavedObjectsImport: jest.fn().mockResolvedValue(null),
incrementSavedObjectsResolveImportErrors: jest.fn().mockResolvedValue(null),
incrementSavedObjectsExport: jest.fn().mockResolvedValue(null),
Expand Down
Loading