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

[Monitoring] Usage collection #75878

Merged
merged 35 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cc0518b
First stab at some internal telemetry
chrisronline Aug 21, 2020
40be20c
Add missing files
chrisronline Aug 24, 2020
89505b7
mbCount telemetry
chrisronline Aug 25, 2020
70dfde0
Merge remote-tracking branch 'elastic/master' into monitoring/telemetry
chrisronline Aug 26, 2020
f86830a
Merge remote-tracking branch 'elastic/master' into monitoring/telemetry
chrisronline Aug 28, 2020
0289496
Include more data
chrisronline Aug 31, 2020
08510f0
Remove unused field
chrisronline Aug 31, 2020
6bd91ee
This file isn't used
chrisronline Aug 31, 2020
55f8400
Mock in tests
chrisronline Aug 31, 2020
b0f71fd
Add schema
chrisronline Aug 31, 2020
c4ed834
Store schema
chrisronline Aug 31, 2020
8556915
Merge remote-tracking branch 'elastic/master' into monitoring/telemetry
chrisronline Sep 8, 2020
cb1851a
Use sample cluster instead
chrisronline Sep 8, 2020
326732f
Fix telemetry schema
chrisronline Sep 8, 2020
569b880
Fix type issues
chrisronline Sep 8, 2020
9d890b9
Merge remote-tracking branch 'elastic/master' into monitoring/telemetry
chrisronline Sep 10, 2020
d43f908
Updates
chrisronline Sep 11, 2020
d517051
Fix schema and tests
chrisronline Sep 11, 2020
e841acf
Merge remote-tracking branch 'elastic/master' into monitoring/telemetry
chrisronline Sep 14, 2020
078fb06
Add tests
chrisronline Sep 14, 2020
18b409e
Add tests
chrisronline Sep 14, 2020
84a9181
Go back to using an array
chrisronline Sep 14, 2020
fa006f2
Fix schema
chrisronline Sep 14, 2020
79257a5
Add page view data
chrisronline Sep 14, 2020
9b25ad2
Remove debug
chrisronline Sep 14, 2020
2e341c6
Merge in master
chrisronline Sep 15, 2020
feb4d08
Handle loading scenario here
chrisronline Sep 15, 2020
5189bd2
Add delay tracking too
chrisronline Sep 15, 2020
8cf79cb
Merge remote-tracking branch 'elastic/master' into monitoring/telemetry
chrisronline Sep 16, 2020
811cbe6
Add clicks for setup mode
chrisronline Sep 16, 2020
b45d372
Add clicks for setup mode
chrisronline Sep 17, 2020
8057843
Merge remote-tracking branch 'elastic/master' into monitoring/telemetry
chrisronline Sep 23, 2020
5152574
Fix beats/apm page views
chrisronline Sep 23, 2020
11e1077
Merge remote-tracking branch 'elastic/master' into monitoring/telemetry
chrisronline Sep 23, 2020
b01ed4d
Fix typings
chrisronline Sep 23, 2020
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
3 changes: 2 additions & 1 deletion x-pack/plugins/monitoring/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"triggers_actions_ui",
"alerts",
"actions",
"encryptedSavedObjects"
"encryptedSavedObjects",
"observability"
],
"optionalPlugins": ["infra", "telemetryCollectionManager", "usageCollection", "home", "cloud"],
"server": true,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/monitoring/public/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class AngularApp {
pluginInitializerContext,
externalConfig,
triggersActionsUi,
usageCollection,
kibanaLegacy,
} = deps;
const app: IModule = localAppModule(deps);
Expand All @@ -42,6 +43,7 @@ export class AngularApp {
externalConfig,
kibanaLegacy,
triggersActionsUi,
usageCollection,
},
this.injector
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import './page_loading.scss';
import { useTrackPageview } from '../../../../observability/public';

export function PageLoading() {
function PageLoadingUI() {
return (
<EuiPage style={{ height: 'calc(100vh - 50px)' }}>
<EuiPageBody>
Expand Down Expand Up @@ -45,3 +46,18 @@ export function PageLoading() {
</EuiPage>
);
}

function PageLoadingTracking({ pageViewTitle }) {
const path = pageViewTitle.toLowerCase().replace(/-/g, '').replace(/\s+/g, '_');
console.log({ pageViewTitle, path });
useTrackPageview({ app: 'stack_monitoring', path });
Copy link
Member

@jasonrhodes jasonrhodes Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these page titles include dynamic names? You may not want to track every single unique page title/path a user visits, but rather just a subset of normalized ones without dynamic/variable segments.

I also recommend throwing in a 2nd track pageview but with a delay: 15000 on the call, which shows how many clusters stayed on the page some "significant amount of time" and will allow your page views to be compared to other observability ones which are currently all doing that. (We can eventually normalize that so it happens with one call across the board consistently, but for now we are keeping it all very manual.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonrhodes Great idea. I was wondering why that was there for the examples I went through.

In terms of dynamic data, this page titles will not contain that. I went through all the unique instance/node pages and ensured the tracking name just said something like kibana_instance. With that said, we still have the beats/apm pages in legacy formats, which I hope to resolve in #76946 before updating here

return <PageLoadingUI />;
}

export function PageLoading({ pageViewTitle }) {
if (pageViewTitle) {
return <PageLoadingTracking pageViewTitle={pageViewTitle} />;
}

return <PageLoadingUI />;
}
5 changes: 4 additions & 1 deletion x-pack/plugins/monitoring/public/legacy_shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TriggersAndActionsUIPublicPluginSetup } from '../../triggers_actions_ui
import { TypeRegistry } from '../../triggers_actions_ui/public/application/type_registry';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ActionTypeModel, AlertTypeModel } from '../../triggers_actions_ui/public/types';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public';

interface BreadcrumbItem {
['data-test-subj']?: string;
Expand Down Expand Up @@ -59,13 +60,14 @@ export interface IShims {
) => Promise<any>;
isCloud: boolean;
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup;
usageCollection: UsageCollectionSetup;
}

export class Legacy {
private static _shims: IShims;

public static init(
{ core, data, isCloud, triggersActionsUi }: MonitoringStartPluginDependencies,
{ core, data, isCloud, triggersActionsUi, usageCollection }: MonitoringStartPluginDependencies,
ngInjector: angular.auto.IInjectorService
) {
this._shims = {
Expand Down Expand Up @@ -119,6 +121,7 @@ export class Legacy {
}),
isCloud,
triggersActionsUi,
usageCollection,
};
}

Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/monitoring/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Plugin,
PluginInitializerContext,
} from 'kibana/public';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public';
import {
FeatureCatalogueCategory,
HomePublicPluginSetup,
Expand All @@ -28,6 +29,7 @@ interface MonitoringSetupPluginDependencies {
home?: HomePublicPluginSetup;
cloud?: { isCloudEnabled: boolean };
triggers_actions_ui: TriggersAndActionsUIPublicPluginSetup;
usageCollection: UsageCollectionSetup;
}

export class MonitoringPlugin
Expand Down Expand Up @@ -93,6 +95,7 @@ export class MonitoringPlugin
pluginInitializerContext: this.initializerContext,
externalConfig: this.getExternalConfig(),
triggersActionsUi: plugins.triggers_actions_ui,
usageCollection: plugins.usageCollection,
};

pluginsStart.kibanaLegacy.loadFontAwesome();
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/monitoring/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { NavigationPublicPluginStart as NavigationStart } from '../../../../src/
import { DataPublicPluginStart } from '../../../../src/plugins/data/public';
import { TriggersAndActionsUIPublicPluginSetup } from '../../triggers_actions_ui/public';
import { KibanaLegacyStart } from '../../../../src/plugins/kibana_legacy/public';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { MonitoringConfig } from '../server';
Expand All @@ -23,4 +24,5 @@ export interface MonitoringStartPluginDependencies {
pluginInitializerContext: PluginInitializerContext;
externalConfig: Array<Array<string | number> | Array<string | boolean>>;
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup;
usageCollection: UsageCollectionSetup;
}
20 changes: 18 additions & 2 deletions x-pack/plugins/monitoring/public/views/base_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Legacy } from '../legacy_shims';
import { PromiseWithCancel } from '../../common/cancel_promise';
import { SetupModeFeature } from '../../common/enums';
import { updateSetupModeData, isSetupModeFeatureEnabled } from '../lib/setup_mode';
import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';

/**
* Given a timezone, this function will calculate the offset in milliseconds
Expand Down Expand Up @@ -88,6 +89,7 @@ export class MonitoringViewBaseController {
options = {},
alerts = { shouldFetch: false, options: {} },
fetchDataImmediately = true,
telemetryPageViewTitle = '',
}) {
const titleService = $injector.get('title');
const $executor = $injector.get('$executor');
Expand All @@ -99,6 +101,7 @@ export class MonitoringViewBaseController {
$scope.pageData = this.data = { ...defaultData };
this._isDataInitialized = false;
this.reactNodeId = reactNodeId;
this.telemetryPageViewTitle = telemetryPageViewTitle || title;

let deferTimer;
let zoomInLevel = 0;
Expand Down Expand Up @@ -204,6 +207,8 @@ export class MonitoringViewBaseController {
deferTimer = setTimeout(() => addPopstateHandler(), 10);
};

// Render loading state
this.renderReact(null, true);
fetchDataImmediately && this.updateData();
});

Expand All @@ -225,15 +230,26 @@ export class MonitoringViewBaseController {
this.setTitle = (title) => titleService($scope.cluster, title);
}

renderReact(component) {
renderReact(component, trackPageView = false) {
const renderElement = document.getElementById(this.reactNodeId);
if (!renderElement) {
console.warn(`"#${this.reactNodeId}" element has not been added to the DOM yet`);
return;
}
const services = {
usageCollection: Legacy.shims.usageCollection,
};
const I18nContext = Legacy.shims.I18nContext;
const wrappedComponent = (
<I18nContext>{!this._isDataInitialized ? <PageLoading /> : component}</I18nContext>
<KibanaContextProvider services={services}>
<I18nContext>
{!this._isDataInitialized ? (
<PageLoading pageViewTitle={trackPageView ? this.telemetryPageViewTitle : null} />
) : (
component
)}
</I18nContext>
</KibanaContextProvider>
);
render(wrappedComponent, renderElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ uiRoutes
$scope,
$injector,
reactNodeId: 'monitoringClusterListingApp',
telemetryPageViewTitle: 'cluster_listing',
});

const $route = $injector.get('$route');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ uiRoutes.when('/overview', {
alerts: {
shouldFetch: true,
},
telemetryPageViewTitle: 'cluster_overview',
});

this.init = () => this.renderReact(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ uiRoutes.when('/elasticsearch/ccr', {
$scope.$watch(
() => this.data,
(data) => {
this.renderReact(data);
if (!data) {
return;
}
this.renderReact(<Ccr data={data.data} />);
}
);

this.renderReact = ({ data }) => {
super.renderReact(<Ccr data={data} />);
};
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ uiRoutes.when('/elasticsearch/ccr/:index/shard/:shardId', {
$scope.$watch(
() => this.data,
(data) => {
this.renderReact(data);
if (!data) {
return;
}
this.renderReact(<CcrShard {...data} />);
}
);

this.renderReact = (props) => {
super.renderReact(<CcrShard {...props} />);
};
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,24 @@ uiRoutes.when('/elasticsearch/indices', {
$scope.$watch(
() => this.data,
(data) => {
this.renderReact(data);
if (!data) {
return;
}

const { clusterStatus, indices } = data;
this.renderReact(
<ElasticsearchIndices
clusterStatus={clusterStatus}
indices={indices}
showSystemIndices={showSystemIndices}
toggleShowSystemIndices={toggleShowSystemIndices}
sorting={this.sorting}
pagination={this.pagination}
onTableChange={this.onTableChange}
/>
);
}
);

this.renderReact = ({ clusterStatus, indices }) => {
super.renderReact(
<ElasticsearchIndices
clusterStatus={clusterStatus}
indices={indices}
showSystemIndices={showSystemIndices}
toggleShowSystemIndices={toggleShowSystemIndices}
sorting={this.sorting}
pagination={this.pagination}
onTableChange={this.onTableChange}
/>
);
};
}
},
});
63 changes: 33 additions & 30 deletions x-pack/plugins/monitoring/public/views/elasticsearch/nodes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,41 @@ uiRoutes.when('/elasticsearch/nodes', {

$scope.$watch(
() => this.data,
() => this.renderReact(this.data || {})
);
(data) => {
if (!data) {
return;
}

this.renderReact = ({ clusterStatus, nodes, totalNodeCount }) => {
const pagination = {
...this.pagination,
totalItemCount: totalNodeCount,
};
const { clusterStatus, nodes, totalNodeCount } = data;
const pagination = {
...this.pagination,
totalItemCount: totalNodeCount,
};

super.renderReact(
<SetupModeRenderer
scope={$scope}
injector={$injector}
productName={ELASTICSEARCH_SYSTEM_ID}
render={({ setupMode, flyoutComponent, bottomBarComponent }) => (
<Fragment>
{flyoutComponent}
<ElasticsearchNodes
clusterStatus={clusterStatus}
clusterUuid={globalState.cluster_uuid}
setupMode={setupMode}
nodes={nodes}
alerts={this.alerts}
showCgroupMetricsElasticsearch={showCgroupMetricsElasticsearch}
{...this.getPaginationTableProps(pagination)}
/>
{bottomBarComponent}
</Fragment>
)}
/>
);
};
this.renderReact(
<SetupModeRenderer
scope={$scope}
injector={$injector}
productName={ELASTICSEARCH_SYSTEM_ID}
render={({ setupMode, flyoutComponent, bottomBarComponent }) => (
<Fragment>
{flyoutComponent}
<ElasticsearchNodes
clusterStatus={clusterStatus}
clusterUuid={globalState.cluster_uuid}
setupMode={setupMode}
nodes={nodes}
alerts={this.alerts}
showCgroupMetricsElasticsearch={showCgroupMetricsElasticsearch}
{...this.getPaginationTableProps(pagination)}
/>
{bottomBarComponent}
</Fragment>
)}
/>
);
}
);
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ uiRoutes.when('/kibana/instances/:uuid', {
constructor($injector, $scope) {
super({
title: `Kibana - ${get($scope.pageData, 'kibanaSummary.name')}`,
telemetryPageViewTitle: 'kibana_instance',
defaultData: {},
getPageData,
reactNodeId: 'monitoringKibanaInstanceApp',
Expand All @@ -85,7 +86,6 @@ uiRoutes.when('/kibana/instances/:uuid', {
if (!data || !data.metrics) {
return;
}

this.setTitle(`Kibana - ${get(data, 'kibanaSummary.name')}`);

this.renderReact(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ uiRoutes.when('/logstash/node/:uuid/advanced', {
reactNodeId: 'monitoringLogstashNodeAdvancedApp',
$scope,
$injector,
telemetryPageViewTitle: 'logstash_node_advanced',
});

$scope.$watch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ uiRoutes.when('/logstash/node/:uuid', {
alertTypeIds: [ALERT_LOGSTASH_VERSION_MISMATCH],
},
},
telemetryPageViewTitle: 'logstash_node',
});

$scope.$watch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ uiRoutes.when('/logstash/node/:uuid/pipelines', {
$scope,
$injector,
fetchDataImmediately: false, // We want to apply pagination before sending the first request
telemetryPageViewTitle: 'logstash_node_pipelines',
});

$scope.$watch(
Expand Down