Skip to content

Commit

Permalink
Sets up APM with new shared Kibana core context
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Aug 23, 2019
1 parent 0150c8e commit cca58f8
Show file tree
Hide file tree
Showing 25 changed files with 82 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import React, { Fragment } from 'react';
import styled from 'styled-components';
import url from 'url';
import { px, units } from '../../../style/variables';
import { useCore } from '../../../hooks/useCore';
import { useKibanaCore } from '../../../../../observability/public';

const Container = styled.div`
margin: ${px(units.minus)} 0;
`;

export const GlobalHelpExtension: React.SFC = () => {
const core = useCore();
const core = useKibanaCore();

return (
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Location } from 'history';
import { last } from 'lodash';
import React from 'react';
import { InternalCoreStart } from 'src/core/public';
import { useCore } from '../../../hooks/useCore';
import { useKibanaCore } from '../../../../../observability/public';
import { getAPMHref } from '../../shared/Links/apm/APMLink';
import { Breadcrumb, ProvideBreadcrumbs } from './ProvideBreadcrumbs';
import { routes } from './route_config';
Expand Down Expand Up @@ -45,7 +45,7 @@ class UpdateBreadcrumbsComponent extends React.Component<Props> {
}

export function UpdateBreadcrumbs() {
const core = useCore();
const core = useKibanaCore();
return (
<ProvideBreadcrumbs
routes={routes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mount } from 'enzyme';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { UpdateBreadcrumbs } from '../UpdateBreadcrumbs';
import * as hooks from '../../../../hooks/useCore';
import * as kibanaCore from '../../../../../../observability/public/context/kibana_core';

jest.mock('ui/kfetch');
jest.mock('ui/index_patterns');
Expand All @@ -20,7 +20,7 @@ const coreMock = {
}
};

jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock);
jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock);

function expectBreadcrumbToMatchSnapshot(route) {
mount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import { i18n } from '@kbn/i18n';
import { useEffect } from 'react';
import { capabilities } from 'ui/capabilities';
import { useCore } from '../../../hooks/useCore';
import { useKibanaCore } from '../../../../../observability/public';

export const useUpdateBadgeEffect = () => {
const { chrome } = useCore();
const { chrome } = useKibanaCore();

useEffect(() => {
const uiCapabilities = capabilities.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import React, { Component } from 'react';
import styled from 'styled-components';
import { toastNotifications } from 'ui/notify';
import { InternalCoreStart } from 'src/core/public';
import { KibanaCoreContext } from '../../../../../../observability/public';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { KibanaLink } from '../../../shared/Links/KibanaLink';
import { createErrorGroupWatch, Schedule } from './createErrorGroupWatch';
import { ElasticDocsLink } from '../../../shared/Links/ElasticDocsLink';
import { CoreContext } from '../../../../context/CoreContext';

type ScheduleKey = keyof Schedule;

Expand Down Expand Up @@ -83,7 +83,8 @@ export class WatcherFlyout extends Component<
WatcherFlyoutProps,
WatcherFlyoutState
> {
static contextType = CoreContext;
static contextType = KibanaCoreContext;
context!: React.ContextType<typeof KibanaCoreContext>;
public state: WatcherFlyoutState = {
schedule: 'daily',
threshold: 10,
Expand Down Expand Up @@ -156,7 +157,7 @@ export class WatcherFlyout extends Component<
};

public createWatch = () => {
const core: InternalCoreStart = this.context;
const core = this.context;
const { serviceName } = this.props.urlParams;

if (!serviceName) {
Expand Down Expand Up @@ -278,7 +279,7 @@ export class WatcherFlyout extends Component<
return null;
}

const core: InternalCoreStart = this.context;
const core = this.context;
const userTimezoneSetting = getUserTimezone(core);
const dailyTime = this.state.daily;
const inputTime = `${dailyTime}Z`; // Add tz to make into UTC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import {
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 { KibanaCoreContext } from '../../../../../../observability/public';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { LicenseContext } from '../../../../context/LicenseContext';
import { MachineLearningFlyout } from './MachineLearningFlyout';
import { WatcherFlyout } from './WatcherFlyout';
import { CoreContext } from '../../../../context/CoreContext';

interface Props {
urlParams: IUrlParams;
Expand All @@ -31,7 +30,9 @@ interface State {
type FlyoutName = null | 'ML' | 'Watcher';

export class ServiceIntegrations extends React.Component<Props, State> {
static contextType = CoreContext;
static contextType = KibanaCoreContext;
context!: React.ContextType<typeof KibanaCoreContext>;

public state: State = { isPopoverOpen: false, activeFlyout: null };

public getPanelItems = memoize((mlAvailable: boolean | undefined) => {
Expand Down Expand Up @@ -67,7 +68,7 @@ export class ServiceIntegrations extends React.Component<Props, State> {
};

public getWatcherPanelItems = () => {
const core: InternalCoreStart = this.context;
const core = this.context;

return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { toastNotifications } from 'ui/notify';
import * as callApmApi from '../../../../services/rest/callApmApi';
import { ServiceOverview } from '..';
import * as urlParamsHooks from '../../../../hooks/useUrlParams';
import * as coreHooks from '../../../../hooks/useCore';
import * as kibanaCore from '../../../../../../observability/public/context/kibana_core';
import { InternalCoreStart } from 'src/core/public';
import * as useLocalUIFilters from '../../../../hooks/useLocalUIFilters';
import { FETCH_STATUS } from '../../../../hooks/useFetcher';
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Service Overview -> View', () => {
end: 'myEnd'
}
});
spyOn(coreHooks, 'useCore').and.returnValue(coreMock);
spyOn(kibanaCore, 'useKibanaCore').and.returnValue(coreMock);

jest.spyOn(useLocalUIFilters, 'useLocalUIFilters').mockReturnValue({
filters: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { NoServicesMessage } from './NoServicesMessage';
import { ServiceList } from './ServiceList';
import { useUrlParams } from '../../../hooks/useUrlParams';
import { useTrackPageview } from '../../../../../infra/public';
import { useCore } from '../../../hooks/useCore';
import { useKibanaCore } from '../../../../../observability/public';
import { PROJECTION } from '../../../../common/projections/typings';
import { LocalUIFilters } from '../../shared/LocalUIFilters';
import { callApmApi } from '../../../services/rest/callApmApi';
Expand All @@ -29,7 +29,7 @@ const initalData = {
let hasDisplayedToast = false;

export function ServiceOverview() {
const core = useCore();
const core = useKibanaCore();
const {
urlParams: { start, end },
uiFilters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { useUrlParams } from '../../../hooks/useUrlParams';
import { history } from '../../../utils/history';
import { useMatchedRoutes } from '../../../hooks/useMatchedRoutes';
import { RouteName } from '../../app/Main/route_config/route_names';
import { useCore } from '../../../hooks/useCore';
import { useKibanaCore } from '../../../../../observability/public';
import { getAPMIndexPattern } from '../../../services/rest/savedObjects';

const Container = styled.div`
Expand Down Expand Up @@ -86,7 +86,7 @@ function getSuggestions(
}

export function KueryBar() {
const core = useCore();
const core = useKibanaCore();
const [state, setState] = useState<State>({
indexPattern: null,
suggestions: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import rison, { RisonValue } from 'rison-node';
import { useAPMIndexPattern } from '../../../../hooks/useAPMIndexPattern';
import { useLocation } from '../../../../hooks/useLocation';
import { getTimepickerRisonData } from '../rison_helpers';
import { useCore } from '../../../../hooks/useCore';
import { useKibanaCore } from '../../../../../../observability/public';

interface Props {
query: {
Expand All @@ -31,7 +31,7 @@ interface Props {
}

export function DiscoverLink({ query = {}, ...rest }: Props) {
const core = useCore();
const core = useKibanaCore();
const apmIndexPattern = useAPMIndexPattern();
const location = useLocation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getRenderedHref } from '../../../../../utils/testHelpers';
import { DiscoverErrorLink } from '../DiscoverErrorLink';
import { DiscoverSpanLink } from '../DiscoverSpanLink';
import { DiscoverTransactionLink } from '../DiscoverTransactionLink';
import * as hooks from '../../../../../hooks/useCore';
import * as kibanaCore from '../../../../../../../observability/public/context/kibana_core';
import { InternalCoreStart } from 'src/core/public';

jest.mock('ui/kfetch');
Expand All @@ -34,7 +34,7 @@ beforeAll(() => {
}
} as unknown) as InternalCoreStart;

jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock);
jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock);
});

afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Location } from 'history';
import React from 'react';
import { getRenderedHref } from '../../../utils/testHelpers';
import { InfraLink } from './InfraLink';
import * as hooks from '../../../hooks/useCore';
import * as kibanaCore from '../../../../../observability/public/context/kibana_core';
import { InternalCoreStart } from 'src/core/public';

const coreMock = ({
Expand All @@ -19,7 +19,7 @@ const coreMock = ({
}
} as unknown) as InternalCoreStart;

jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock);
jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock);

test('InfraLink produces the correct URL', async () => {
const href = await getRenderedHref(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { compact } from 'lodash';
import React from 'react';
import url from 'url';
import { fromQuery } from './url_helpers';
import { useCore } from '../../../hooks/useCore';
import { useKibanaCore } from '../../../../../observability/public';

interface InfraQueryParams {
time?: number;
Expand All @@ -24,7 +24,7 @@ interface Props extends EuiLinkAnchorProps {
}

export function InfraLink({ path, query = {}, ...rest }: Props) {
const core = useCore();
const core = useKibanaCore();
const nextSearch = fromQuery(query);
const href = url.format({
pathname: core.http.basePath.prepend('/app/infra'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Location } from 'history';
import React from 'react';
import { getRenderedHref } from '../../../utils/testHelpers';
import { KibanaLink } from './KibanaLink';
import * as hooks from '../../../hooks/useCore';
import * as kibanaCore from '../../../../../observability/public/context/kibana_core';
import { InternalCoreStart } from 'src/core/public';

describe('KibanaLink', () => {
Expand All @@ -21,7 +21,7 @@ describe('KibanaLink', () => {
}
} as unknown) as InternalCoreStart;

jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock);
jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui';
import React from 'react';
import url from 'url';
import { useCore } from '../../../hooks/useCore';
import { useKibanaCore } from '../../../../../observability/public';

interface Props extends EuiLinkAnchorProps {
path?: string;
children?: React.ReactNode;
}

export function KibanaLink({ path, ...rest }: Props) {
const core = useCore();
const core = useKibanaCore();
const href = url.format({
pathname: core.http.basePath.prepend('/app/kibana'),
hash: path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Location } from 'history';
import React from 'react';
import { getRenderedHref } from '../../../../utils/testHelpers';
import { MLJobLink } from './MLJobLink';
import * as hooks from '../../../../hooks/useCore';
import * as kibanaCore from '../../../../../../observability/public/context/kibana_core';
import { InternalCoreStart } from 'src/core/public';

describe('MLJobLink', () => {
Expand All @@ -21,7 +21,7 @@ describe('MLJobLink', () => {
}
} as unknown) as InternalCoreStart;

spyOn(hooks, 'useCore').and.returnValue(coreMock);
spyOn(kibanaCore, 'useKibanaCore').and.returnValue(coreMock);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import { getRenderedHref } from '../../../../utils/testHelpers';
import { MLLink } from './MLLink';
import * as savedObjects from '../../../../services/rest/savedObjects';
import * as hooks from '../../../../hooks/useCore';
import * as kibanaCore from '../../../../../../observability/public/context/kibana_core';
import { InternalCoreStart } from 'src/core/public';

jest.mock('ui/kfetch');
Expand All @@ -22,7 +22,7 @@ const coreMock = ({
}
} as unknown) as InternalCoreStart;

jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock);
jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock);

jest
.spyOn(savedObjects, 'getAPMIndexPattern')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import url from 'url';
import rison, { RisonValue } from 'rison-node';
import { useLocation } from '../../../../hooks/useLocation';
import { getTimepickerRisonData, TimepickerRisonData } from '../rison_helpers';
import { useCore } from '../../../../hooks/useCore';
import { useKibanaCore } from '../../../../../../observability/public';

interface MlRisonData {
ml?: {
Expand All @@ -25,7 +25,7 @@ interface Props {
}

export function MLLink({ children, path = '', query = {} }: Props) {
const core = useCore();
const core = useKibanaCore();
const location = useLocation();

const risonQuery: MlRisonData & TimepickerRisonData = getTimepickerRisonData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { DiscoverTransactionLink } from '../Links/DiscoverLinks/DiscoverTransact
import { InfraLink } from '../Links/InfraLink';
import { useUrlParams } from '../../../hooks/useUrlParams';
import { fromQuery } from '../Links/url_helpers';
import { useCore } from '../../../hooks/useCore';
import { useKibanaCore } from '../../../../../observability/public';

function getInfraMetricsQuery(transaction: Transaction) {
const plus5 = new Date(transaction['@timestamp']);
Expand Down Expand Up @@ -66,7 +66,7 @@ export const TransactionActionMenu: FunctionComponent<Props> = (
) => {
const { transaction } = props;

const core = useCore();
const core = useKibanaCore();

const [isOpen, setIsOpen] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TransactionActionMenu } from '../TransactionActionMenu';
import { Transaction } from '../../../../../typings/es_schemas/ui/Transaction';
import * as Transactions from './mockData';
import * as apmIndexPatternHooks from '../../../../hooks/useAPMIndexPattern';
import * as coreHoooks from '../../../../hooks/useCore';
import * as kibanaCore from '../../../../../../observability/public/context/kibana_core';
import { ISavedObject } from '../../../../services/rest/savedObjects';
import { InternalCoreStart } from 'src/core/public';

Expand Down Expand Up @@ -40,7 +40,7 @@ describe('TransactionActionMenu component', () => {
jest
.spyOn(apmIndexPatternHooks, 'useAPMIndexPattern')
.mockReturnValue({ id: 'foo' } as ISavedObject);
jest.spyOn(coreHoooks, 'useCore').mockReturnValue(coreMock);
jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock);
});

afterEach(() => {
Expand Down
Loading

0 comments on commit cca58f8

Please sign in to comment.