Skip to content

Commit

Permalink
test(NA): add new telemetry variables to the integration test fixture. (
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic committed Feb 5, 2019
1 parent 45b1f5d commit 9eae769
Show file tree
Hide file tree
Showing 20 changed files with 910 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/server/saved_objects/service/lib/repository.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { BaseOptions, SavedObject } from '../saved_objects_client';

export interface SavedObjectsRepositoryOptions {
index: string | string[];
mappings: unknown;
Expand All @@ -30,5 +32,13 @@ export interface SavedObjectsRepositoryOptions {
export declare class SavedObjectsRepository {
// ATTENTION: this interface is incomplete

public get: (type: string, id: string, options?: BaseOptions) => Promise<SavedObject>;
public incrementCounter: (
type: string,
id: string,
counterFieldName: string,
options?: BaseOptions
) => Promise<SavedObject>;

constructor(options: SavedObjectsRepositoryOptions);
}
66 changes: 66 additions & 0 deletions x-pack/plugins/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Legacy } from 'kibana';
import {
SavedObject,
SavedObjectAttributes,
Expand Down Expand Up @@ -54,3 +55,68 @@ export enum IndexGroup {
ml = '___ML_REINDEX_LOCK___',
watcher = '___WATCHER_REINDEX_LOCK___',
}

// Telemetry types
export const UPGRADE_ASSISTANT_TYPE = 'upgrade-assistant-telemetry';
export const UPGRADE_ASSISTANT_DOC_ID = 'upgrade-assistant-telemetry';
export type UIOpenOption = 'overview' | 'cluster' | 'indices';
export type UIReindexOption = 'close' | 'open' | 'start' | 'stop';

export interface UIOpen {
overview: boolean;
cluster: boolean;
indices: boolean;
}

export interface UIReindex {
close: boolean;
open: boolean;
start: boolean;
stop: boolean;
}

export interface UpgradeAssistantTelemetryServer extends Legacy.Server {
usage: {
collectorSet: {
makeUsageCollector: any;
register: any;
};
};
}

export interface UpgradeAssistantTelemetrySavedObject {
ui_open: {
overview: number;
cluster: number;
indices: number;
};
ui_reindex: {
close: number;
open: number;
start: number;
stop: number;
};
}

export interface UpgradeAssistantTelemetry {
ui_open: {
overview: number;
cluster: number;
indices: number;
};
ui_reindex: {
close: number;
open: number;
start: number;
stop: number;
};
features: {
deprecation_logging: {
enabled: boolean;
};
};
}

export interface UpgradeAssistantTelemetrySavedObjectAttributes {
[key: string]: any;
}
8 changes: 6 additions & 2 deletions x-pack/plugins/upgrade_assistant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Server } from 'hapi';
import Joi from 'joi';
import { resolve } from 'path';
import mappings from './mappings.json';
import { initServer } from './server';

export function upgradeAssistant(kibana: any) {
Expand All @@ -14,13 +15,16 @@ export function upgradeAssistant(kibana: any) {
require: ['elasticsearch'],
uiExports: {
managementSections: ['plugins/upgrade_assistant'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
mappings: require('./mappings.json'),
savedObjectSchemas: {
'upgrade-assistant-reindex-operation': {
isNamespaceAgnostic: true,
},
'upgrade-assistant-telemetry': {
isNamespaceAgnostic: true,
},
},
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
mappings,
},
publicDir: resolve(__dirname, 'public'),

Expand Down
52 changes: 52 additions & 0 deletions x-pack/plugins/upgrade_assistant/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,57 @@
"type": "integer"
}
}
},
"upgrade-assistant-telemetry": {
"properties": {
"ui_open": {
"properties": {
"overview": {
"type": "long",
"null_value": 0
},
"cluster": {
"type": "long",
"null_value": 0
},
"indices": {
"type": "long",
"null_value": 0
}
}
},
"ui_reindex": {
"properties": {
"close": {
"type": "long",
"null_value": 0
},
"open": {
"type": "long",
"null_value": 0
},
"start": {
"type": "long",
"null_value": 0
},
"stop": {
"type": "long",
"null_value": 0
}
}
},
"features": {
"properties": {
"deprecation_logging": {
"properties": {
"enabled": {
"type": "boolean",
"null_value": true
}
}
}
}
}
}
}
}
44 changes: 39 additions & 5 deletions x-pack/plugins/upgrade_assistant/public/components/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
*/

import axios from 'axios';
import { findIndex } from 'lodash';
import { findIndex, set } from 'lodash';
import React from 'react';

import { EuiTabbedContent, EuiTabbedContentTab } from '@elastic/eui';
import { injectI18n } from '@kbn/i18n/react';

import chrome from 'ui/chrome';
import { kfetch } from 'ui/kfetch';

import { UpgradeAssistantStatus } from '../../server/lib/es_migration_apis';
import { CheckupTab } from './tabs/checkup';
import { OverviewTab } from './tabs/overview';
import { LoadingState, UpgradeAssistantTabProps } from './types';
import { LoadingState, TelemetryState, UpgradeAssistantTabProps } from './types';

interface TabsState {
loadingState: LoadingState;
loadingError?: Error;
checkupData?: UpgradeAssistantStatus;
selectedTabIndex: number;
telemetryState: TelemetryState;
}

export class UpgradeAssistantTabsUI extends React.Component<
Expand All @@ -35,19 +37,26 @@ export class UpgradeAssistantTabsUI extends React.Component<
this.state = {
loadingState: LoadingState.Loading,
selectedTabIndex: 0,
telemetryState: TelemetryState.Complete,
};
}

public componentDidMount() {
this.loadData();
public async componentDidMount() {
await this.loadData();

// Send telemetry info about the default selected tab
this.sendTelemetryInfo(this.tabs[this.state.selectedTabIndex].id);
}

public render() {
const { selectedTabIndex } = this.state;
const { selectedTabIndex, telemetryState } = this.state;
const tabs = this.tabs;

return (
<EuiTabbedContent
data-test-subj={
telemetryState === TelemetryState.Running ? 'upgradeAssistantTelemetryRunning' : undefined
}
tabs={tabs}
onTabClick={this.onTabClick}
selectedTab={tabs[selectedTabIndex]}
Expand All @@ -61,6 +70,13 @@ export class UpgradeAssistantTabsUI extends React.Component<
throw new Error(`Clicked tab did not exist in tabs array`);
}

// Send telemetry info about the current selected tab
// only in case the clicked tab id it's different from the
// current selected tab id
if (this.tabs[this.state.selectedTabIndex].id !== selectedTab.id) {
this.sendTelemetryInfo(selectedTab.id);
}

this.setSelectedTabIndex(selectedTabIndex);
};

Expand Down Expand Up @@ -139,6 +155,24 @@ export class UpgradeAssistantTabsUI extends React.Component<
},
];
}

private async sendTelemetryInfo(tabName: string) {
// In case we don't have any data yet, we wanna to ignore the
// telemetry info update
if (this.state.loadingState !== LoadingState.Success) {
return;
}

this.setState({ telemetryState: TelemetryState.Running });

await kfetch({
pathname: '/api/upgrade_assistant/telemetry/ui_open',
method: 'PUT',
body: JSON.stringify(set({}, tabName, true)),
});

this.setState({ telemetryState: TelemetryState.Complete });
}
}

export const UpgradeAssistantTabs = injectI18n(UpgradeAssistantTabsUI);
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { set } from 'lodash';
import React, { Fragment, ReactNode } from 'react';
import { Subscription } from 'rxjs';

import { EuiButton, EuiLoadingSpinner } from '@elastic/eui';
import { ReindexStatus } from '../../../../../../common/types';
import { kfetch } from 'ui/kfetch';
import { ReindexStatus, UIReindexOption } from '../../../../../../common/types';
import { LoadingState } from '../../../../types';
import { ReindexFlyout } from './flyout';
import { ReindexPollingService, ReindexState } from './polling_service';
Expand Down Expand Up @@ -104,7 +106,7 @@ export class ReindexButton extends React.Component<ReindexButtonProps, ReindexBu
indexName={indexName}
closeFlyout={this.closeFlyout}
reindexState={reindexState}
startReindex={this.service.startReindex}
startReindex={this.startReindex}
/>
)}
</Fragment>
Expand Down Expand Up @@ -133,11 +135,30 @@ export class ReindexButton extends React.Component<ReindexButtonProps, ReindexBu
}
}

private startReindex = async () => {
if (!this.state.reindexState.status) {
// if status didn't exist we are starting a reindex action
this.sendUIReindexTelemetryInfo('start');
}

await this.service.startReindex();
};

private showFlyout = () => {
this.sendUIReindexTelemetryInfo('open');
this.setState({ flyoutVisible: true });
};

private closeFlyout = () => {
this.sendUIReindexTelemetryInfo('close');
this.setState({ flyoutVisible: false });
};

private async sendUIReindexTelemetryInfo(uiReindexAction: UIReindexOption) {
await kfetch({
pathname: '/api/upgrade_assistant/telemetry/ui_reindex',
method: 'PUT',
body: JSON.stringify(set({}, uiReindexAction, true)),
});
}
}
5 changes: 5 additions & 0 deletions x-pack/plugins/upgrade_assistant/public/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ export enum GroupByOption {
index = 'index',
node = 'node',
}

export enum TelemetryState {
Running,
Complete,
}
7 changes: 7 additions & 0 deletions x-pack/plugins/upgrade_assistant/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
*/

import { Legacy } from 'kibana';
import { UpgradeAssistantTelemetryServer } from '../common/types';
import { credentialStoreFactory } from './lib/reindexing/credential_store';
import { makeUpgradeAssistantUsageCollector } from './lib/telemetry';
import { registerClusterCheckupRoutes } from './routes/cluster_checkup';
import { registerDeleteTasksRoutes } from './routes/delete_tasks';
import { registerDeprecationLoggingRoutes } from './routes/deprecation_logging';
import { registerReindexIndicesRoutes, registerReindexWorker } from './routes/reindex_indices';
import { registerTelemetryRoutes } from './routes/telemetry';

export function initServer(server: Legacy.Server) {
registerClusterCheckupRoutes(server);
Expand All @@ -26,4 +29,8 @@ export function initServer(server: Legacy.Server) {

const worker = registerReindexWorker(server, credentialStore);
registerReindexIndicesRoutes(server, worker, credentialStore);

// Bootstrap the needed routes and the collector for the telemetry
registerTelemetryRoutes(server as UpgradeAssistantTelemetryServer);
makeUpgradeAssistantUsageCollector(server as UpgradeAssistantTelemetryServer);
}

0 comments on commit 9eae769

Please sign in to comment.