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

[APM] Avoid APM failing to start when ml is disabled #42815

Merged
merged 2 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { i18n } from '@kbn/i18n';
import { memoize } from 'lodash';
import React, { Fragment } from 'react';
import { InternalCoreStart } from 'src/core/public';
import { idx } from '@kbn/elastic-idx';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { LicenseContext } from '../../../../context/LicenseContext';
import { MachineLearningFlyout } from './MachineLearningFlyout';
Expand All @@ -33,7 +34,7 @@ export class ServiceIntegrations extends React.Component<Props, State> {
static contextType = CoreContext;
public state: State = { isPopoverOpen: false, activeFlyout: null };

public getPanelItems = memoize((mlAvailable: boolean) => {
public getPanelItems = memoize((mlAvailable: boolean | undefined) => {
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved
let panelItems: EuiContextMenuPanelItemDescriptor[] = [];
if (mlAvailable) {
panelItems = panelItems.concat(this.getMLPanelItems());
Expand Down Expand Up @@ -147,7 +148,9 @@ export class ServiceIntegrations extends React.Component<Props, State> {
panels={[
{
id: 0,
items: this.getPanelItems(license.features.ml.is_available)
items: this.getPanelItems(
idx(license, _ => _.features.ml.is_available)
)
}
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Location } from 'history';
import React, { Component } from 'react';
import { isEmpty, flatten } from 'lodash';
import styled from 'styled-components';
import { idx } from '@kbn/elastic-idx';
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n';
import { Coordinate, TimeSeries } from '../../../../../typings/timeseries';
import { ITransactionChartData } from '../../../../selectors/chartSelectors';
Expand Down Expand Up @@ -87,7 +88,7 @@ export class TransactionCharts extends Component<TransactionChartProps> {
: NOT_AVAILABLE_LABEL;
};

public renderMLHeader(hasValidMlLicense: boolean) {
public renderMLHeader(hasValidMlLicense: boolean | undefined) {
const { hasMLJob } = this.props;
if (!hasValidMlLicense || !hasMLJob) {
return null;
Expand Down Expand Up @@ -161,7 +162,9 @@ export class TransactionCharts extends Component<TransactionChartProps> {
</EuiFlexItem>
<LicenseContext.Consumer>
{license =>
this.renderMLHeader(license.features.ml.is_available)
this.renderMLHeader(
idx(license, _ => _.features.ml.is_available)
)
}
</LicenseContext.Consumer>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
*/
import React from 'react';
import { FETCH_STATUS, useFetcher } from '../../hooks/useFetcher';
import { loadLicense } from '../../services/rest/xpack';
import { loadLicense, LicenseApiResponse } from '../../services/rest/xpack';
import { InvalidLicenseNotification } from './InvalidLicenseNotification';

const initialLicense = {
features: {
watcher: { is_available: false },
ml: { is_available: false }
},
features: {},
license: { is_active: false }
};
} as LicenseApiResponse;
Copy link
Member

Choose a reason for hiding this comment

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

should we not use initialLicense:LicenseAPIResponse?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but since the other items in license were required I'd have to add default value for those as well:

license: {
    expiry_date_in_millis: number;
    is_active: boolean;
    type: string;
}

Since we don't use those two properties I'll just remove them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

export const LicenseContext = React.createContext(initialLicense);

export const LicenseProvider: React.FC = ({ children }) => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/apm/public/hooks/useFetcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { useContext, useEffect, useState, useMemo } from 'react';
import { toastNotifications } from 'ui/notify';
import { idx } from '@kbn/elastic-idx/target';
import { idx } from '@kbn/elastic-idx';
import { i18n } from '@kbn/i18n';
import { LoadingIndicatorContext } from '../context/LoadingIndicatorContext';
import { useComponentId } from './useComponentId';
Expand Down
26 changes: 13 additions & 13 deletions x-pack/legacy/plugins/apm/public/services/rest/xpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ export interface LicenseApiResponse {
type: string;
};
features: {
beats_management: StringMap;
graph: StringMap;
grokdebugger: StringMap;
index_management: StringMap;
logstash: StringMap;
ml: {
beats_management?: StringMap;
graph?: StringMap;
grokdebugger?: StringMap;
index_management?: StringMap;
logstash?: StringMap;
ml?: {
is_available: boolean;
license_type: number;
has_expired: boolean;
enable_links: boolean;
show_links: boolean;
};
reporting: StringMap;
rollup: StringMap;
searchprofiler: StringMap;
security: StringMap;
spaces: StringMap;
tilemap: StringMap;
watcher: {
reporting?: StringMap;
rollup?: StringMap;
searchprofiler?: StringMap;
security?: StringMap;
spaces?: StringMap;
tilemap?: StringMap;
watcher?: {
is_available: boolean;
enable_links: boolean;
show_links: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { ESFilter } from 'elasticsearch';
import { Server } from 'hapi';
import { idx } from '@kbn/elastic-idx/target';
import { idx } from '@kbn/elastic-idx';
import { toElasticsearchQuery, fromKueryExpression } from '@kbn/es-query';
import { ISavedObject } from '../../../../public/services/rest/savedObjects';
import { StaticIndexPattern } from '../../../../../../../../src/legacy/core_plugins/data/public';
Expand Down