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

[Observability] Move InspectContextProvider and utils to observability #113842

Merged
merged 3 commits into from
Oct 7, 2021
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
1 change: 0 additions & 1 deletion x-pack/plugins/apm/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"embeddable",
"features",
"infra",
"inspector",
"licensing",
"observability",
"ruleRegistry",
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/apm/public/application/uxApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ import { createCallApmApi } from '../services/rest/createCallApmApi';
import { createStaticIndexPattern } from '../services/rest/index_pattern';
import { UXActionMenu } from '../components/app/RumDashboard/ActionMenu';
import { redirectTo } from '../components/routing/redirect_to';
import { useBreadcrumbs } from '../../../observability/public';
import {
InspectorContextProvider,
useBreadcrumbs,
} from '../../../observability/public';
import { useApmPluginContext } from '../context/apm_plugin/use_apm_plugin_context';
import { APP_WRAPPER_CLASS } from '../../../../../src/core/public';
import { InspectorContextProvider } from '../context/inspector/inspector_context';

export const uxRoutes: APMRouteDefinition[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { i18n } from '@kbn/i18n';
import React from 'react';
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';
import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public';
import { useInspectorContext } from '../../../../context/inspector/use_inspector_context';
import { enableInspectEsQueries } from '../../../../../../observability/common/ui_settings_keys';
import { useInspectorContext } from '../../../../../../observability/public';

export function UxInspectorHeaderLink() {
const { inspector } = useApmPluginContext();
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/apm/public/components/routing/app_root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
RedirectAppLinks,
useUiSetting$,
} from '../../../../../../src/plugins/kibana_react/public';
import { HeaderMenuPortal } from '../../../../observability/public';
import {
HeaderMenuPortal,
InspectorContextProvider,
} from '../../../../observability/public';
import { ScrollToTopOnPathChange } from '../../components/app/Main/ScrollToTopOnPathChange';
import { AnomalyDetectionJobsContextProvider } from '../../context/anomaly_detection_jobs/anomaly_detection_jobs_context';
import {
Expand All @@ -26,7 +29,6 @@ import {
} from '../../context/apm_plugin/apm_plugin_context';
import { useApmPluginContext } from '../../context/apm_plugin/use_apm_plugin_context';
import { BreadcrumbsContextProvider } from '../../context/breadcrumbs/context';
import { InspectorContextProvider } from '../../context/inspector/inspector_context';
import { LicenseProvider } from '../../context/license/license_context';
import { TimeRangeIdContextProvider } from '../../context/time_range_id/time_range_id_context';
import { UrlParamsProvider } from '../../context/url_params_context/url_params_context';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { EuiHeaderLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { enableInspectEsQueries } from '../../../../../observability/public';
import {
enableInspectEsQueries,
useInspectorContext,
} from '../../../../../observability/public';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import { useInspectorContext } from '../../../context/inspector/use_inspector_context';

export function InspectorHeaderLink() {
const { inspector } = useApmPluginContext();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/public/hooks/use_fetcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { i18n } from '@kbn/i18n';
import React, { useEffect, useMemo, useState } from 'react';
import { IHttpFetchError } from 'src/core/public';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import { useInspectorContext } from '../context/inspector/use_inspector_context';
import { useTimeRangeId } from '../context/time_range_id/use_time_range_id';
import {
AutoAbortedAPMClient,
callApmApi,
} from '../services/rest/createCallApmApi';
import { useInspectorContext } from '../../../observability/public';

export enum FETCH_STATUS {
LOADING = 'loading',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {
APIEndpoint,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../server';
import { InspectResponse } from '../../../typings/common';
import { InspectResponse } from '../../../../observability/typings/common';

export type APMClientOptions = Omit<
FetchOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { KibanaRequest } from '../../../../../../../src/core/server';
import { RequestStatus } from '../../../../../../../src/plugins/inspector';
import { WrappedElasticsearchClientError } from '../../../../../observability/server';
import { inspectableEsQueriesMap } from '../../../routes/register_routes';
import { getInspectResponse } from './get_inspect_response';
import { getInspectResponse } from '../../../../../observability/server';

function formatObj(obj: Record<string, any>) {
return JSON.stringify(obj, null, 2);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/register_routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { mergeRt, jsonRt } from '@kbn/io-ts-utils';
import { pickKeys } from '../../../common/utils/pick_keys';
import { APMRouteHandlerResources, TelemetryUsageCounter } from '../typings';
import type { ApmPluginRequestHandlerContext } from '../typings';
import { InspectResponse } from '../../../typings/common';
import { InspectResponse } from '../../../../observability/typings/common';

const inspectRt = t.exact(
t.partial({
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/apm/typings/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import type { UnwrapPromise } from '@kbn/utility-types';
import type { Request } from '../../../../src/plugins/inspector/common';
import '../../../typings/rison_node';
import '../../infra/types/eui';
// EUIBasicTable
Expand All @@ -28,5 +27,3 @@ type AllowUnknownObjectProperties<T> = T extends object
export type PromiseValueType<T extends Promise<any>> = UnwrapPromise<T>;

export type Maybe<T> = T | null | undefined;

export type InspectResponse = Request[];
1 change: 1 addition & 0 deletions x-pack/plugins/observability/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"cases",
"data",
"features",
"inspector",
"ruleRegistry",
"timelines",
"triggersActionsUi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function buildFilterLabel({
return filter;
}

interface Props {
export interface FilterValueLabelProps {
field: string;
label: string;
value: string | string[];
Expand All @@ -60,7 +60,7 @@ export function FilterValueLabel({
invertFilter,
removeFilter,
allowExclusion = true,
}: Props) {
}: FilterValueLabelProps) {
const FilterItem = injectI18n(esFilters.FilterItem);

const filter = buildFilterLabel({ field, value, label, indexPattern, negate });
Expand Down Expand Up @@ -92,3 +92,6 @@ export function FilterValueLabel({
/>
) : null;
}

// eslint-disable-next-line import/no-default-export
export default FilterValueLabel;
11 changes: 11 additions & 0 deletions x-pack/plugins/observability/public/components/shared/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { lazy, Suspense } from 'react';
import { EuiLoadingSpinner } from '@elastic/eui';
import type { CoreVitalProps, HeaderMenuPortalProps } from './types';
import type { FieldValueSuggestionsProps } from './field_value_suggestions/types';
import type { FilterValueLabelProps } from './filter_value_label/filter_value_label';

export { createLazyObservabilityPageTemplate } from './page_template';
export type { LazyObservabilityPageTemplateProps } from './page_template';
Expand Down Expand Up @@ -42,3 +43,13 @@ export function FieldValueSuggestions(props: FieldValueSuggestionsProps) {
</Suspense>
);
}

const FilterValueLabelLazy = lazy(() => import('./filter_value_label/filter_value_label'));

export function FilterValueLabel(props: FilterValueLabelProps) {
return (
<Suspense fallback={null}>
<FilterValueLabelLazy {...props} />
</Suspense>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import React, { createContext, ReactNode, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { RequestAdapter } from '../../../../../../src/plugins/inspector/common';
import { InspectResponse } from '../../../typings/common';
import { FetcherResult } from '../../hooks/use_fetcher';
import { InspectResponse } from '../../../typings/common';

export interface InspectorContextValue {
addInspectorRequest: <Data>(result: FetcherResult<Data>) => void;
Expand All @@ -23,11 +23,7 @@ const value: InspectorContextValue = {

export const InspectorContext = createContext<InspectorContextValue>(value);

export function InspectorContextProvider({
children,
}: {
children: ReactNode;
}) {
export function InspectorContextProvider({ children }: { children: ReactNode }) {
const history = useHistory();
const { inspectorAdapters } = value;

Expand All @@ -37,8 +33,7 @@ export function InspectorContextProvider({
_inspect?: InspectResponse;
}>
) {
const operations =
result.data?._inspect ?? result.data?.mainStatisticsData?._inspect ?? [];
const operations = result.data?._inspect ?? result.data?.mainStatisticsData?._inspect ?? [];

operations.forEach((operation) => {
if (operation.response) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/observability/public/hooks/use_fetcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum FETCH_STATUS {
SUCCESS = 'success',
FAILURE = 'failure',
PENDING = 'pending',
NOT_INITIATED = 'not_initiated',
}

export interface FetcherResult<Data> {
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/observability/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export {
getCoreVitalsComponent,
HeaderMenuPortal,
FieldValueSuggestions,
FilterValueLabel,
} from './components/shared/';

export type { LazyObservabilityPageTemplateProps } from './components/shared';
Expand All @@ -70,7 +71,6 @@ export { useTheme } from './hooks/use_theme';
export { getApmTraceUrl } from './utils/get_apm_trace_url';
export { createExploratoryViewUrl } from './components/shared/exploratory_view/configurations/utils';
export { ALL_VALUES_SELECTED } from './components/shared/field_value_suggestions/field_value_combobox';
export { FilterValueLabel } from './components/shared/filter_value_label/filter_value_label';
export type { AllSeries } from './components/shared/exploratory_view/hooks/use_series_storage';
export type { SeriesUrl } from './components/shared/exploratory_view/types';

Expand All @@ -81,3 +81,6 @@ export type {
} from './rules/create_observability_rule_type_registry';
export { createObservabilityRuleTypeRegistryMock } from './rules/observability_rule_type_registry_mock';
export type { ExploratoryEmbeddableProps } from './components/shared/exploratory_view/embeddable/embeddable';

export { InspectorContextProvider } from './context/inspector/inspector_context';
export { useInspectorContext } from './context/inspector/use_inspector_context';
1 change: 1 addition & 0 deletions x-pack/plugins/observability/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { createOrUpdateIndex, Mappings } from './utils/create_or_update_index';
import { ScopedAnnotationsClient } from './lib/annotations/bootstrap_annotations';
import { unwrapEsResponse, WrappedElasticsearchClientError } from './utils/unwrap_es_response';
export { rangeQuery, kqlQuery } from './utils/queries';
export { getInspectResponse } from './utils/get_inspect_response';

export * from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
*/

import { i18n } from '@kbn/i18n';
import type { KibanaRequest } from '../../../../../../../src/core/server';
import type {
RequestStatistics,
RequestStatus,
} from '../../../../../../../src/plugins/inspector';
import { WrappedElasticsearchClientError } from '../../../../../observability/server';
import type { InspectResponse } from '../../../../typings/common';
import type { KibanaRequest } from 'kibana/server';
import type { RequestStatistics, RequestStatus } from '../../../../../src/plugins/inspector';
import { WrappedElasticsearchClientError } from '../index';
import { InspectResponse } from '../../typings/common';

/**
* Get statistics to show on inspector tab.
Expand All @@ -33,14 +30,11 @@ function getStats({
}) {
const stats: RequestStatistics = {
kibanaApiQueryParameters: {
label: i18n.translate(
'xpack.apm.inspector.stats.kibanaApiQueryParametersLabel',
{
defaultMessage: 'Kibana API query parameters',
}
),
label: i18n.translate('xpack.observability.inspector.stats.kibanaApiQueryParametersLabel', {
defaultMessage: 'Kibana API query parameters',
}),
description: i18n.translate(
'xpack.apm.inspector.stats.kibanaApiQueryParametersDescription',
'xpack.observability.inspector.stats.kibanaApiQueryParametersDescription',
{
defaultMessage:
'The query parameters used in the Kibana API request that initiated the Elasticsearch request.',
Expand All @@ -49,64 +43,52 @@ function getStats({
value: JSON.stringify(kibanaRequest.query, null, 2),
},
kibanaApiRoute: {
label: i18n.translate('xpack.apm.inspector.stats.kibanaApiRouteLabel', {
label: i18n.translate('xpack.observability.inspector.stats.kibanaApiRouteLabel', {
defaultMessage: 'Kibana API route',
}),
description: i18n.translate(
'xpack.apm.inspector.stats.kibanaApiRouteDescription',
{
defaultMessage:
'The route of the Kibana API request that initiated the Elasticsearch request.',
}
),
value: `${kibanaRequest.route.method.toUpperCase()} ${
kibanaRequest.route.path
}`,
description: i18n.translate('xpack.observability.inspector.stats.kibanaApiRouteDescription', {
defaultMessage:
'The route of the Kibana API request that initiated the Elasticsearch request.',
}),
value: `${kibanaRequest.route.method.toUpperCase()} ${kibanaRequest.route.path}`,
},
indexPattern: {
label: i18n.translate('xpack.apm.inspector.stats.indexPatternLabel', {
label: i18n.translate('xpack.observability.inspector.stats.indexPatternLabel', {
defaultMessage: 'Index pattern',
}),
value: esRequestParams.index,
description: i18n.translate(
'xpack.apm.inspector.stats.indexPatternDescription',
{
defaultMessage:
'The index pattern that connected to the Elasticsearch indices.',
}
),
description: i18n.translate('xpack.observability.inspector.stats.indexPatternDescription', {
defaultMessage: 'The index pattern that connected to the Elasticsearch indices.',
}),
},
};

if (esResponse?.hits) {
stats.hits = {
label: i18n.translate('xpack.apm.inspector.stats.hitsLabel', {
label: i18n.translate('xpack.observability.inspector.stats.hitsLabel', {
defaultMessage: 'Hits',
}),
value: `${esResponse.hits.hits.length}`,
description: i18n.translate('xpack.apm.inspector.stats.hitsDescription', {
description: i18n.translate('xpack.observability.inspector.stats.hitsDescription', {
defaultMessage: 'The number of documents returned by the query.',
}),
};
}

if (esResponse?.took) {
stats.queryTime = {
label: i18n.translate('xpack.apm.inspector.stats.queryTimeLabel', {
label: i18n.translate('xpack.observability.inspector.stats.queryTimeLabel', {
defaultMessage: 'Query time',
}),
value: i18n.translate('xpack.apm.inspector.stats.queryTimeValue', {
value: i18n.translate('xpack.observability.inspector.stats.queryTimeValue', {
defaultMessage: '{queryTime}ms',
values: { queryTime: esResponse.took },
}),
description: i18n.translate(
'xpack.apm.inspector.stats.queryTimeDescription',
{
defaultMessage:
'The time it took to process the query. ' +
'Does not include the time to send the request or parse it in the browser.',
}
),
description: i18n.translate('xpack.observability.inspector.stats.queryTimeDescription', {
defaultMessage:
'The time it took to process the query. ' +
'Does not include the time to send the request or parse it in the browser.',
}),
};
}

Expand All @@ -115,20 +97,16 @@ function getStats({
relation: string;
value: number;
};
const hitsTotalValue =
total.relation === 'eq' ? `${total.value}` : `> ${total.value}`;
const hitsTotalValue = total.relation === 'eq' ? `${total.value}` : `> ${total.value}`;

stats.hitsTotal = {
label: i18n.translate('xpack.apm.inspector.stats.hitsTotalLabel', {
label: i18n.translate('xpack.observability.inspector.stats.hitsTotalLabel', {
defaultMessage: 'Hits (total)',
}),
value: hitsTotalValue,
description: i18n.translate(
'xpack.apm.inspector.stats.hitsTotalDescription',
{
defaultMessage: 'The number of documents that match the query.',
}
),
description: i18n.translate('xpack.observability.inspector.stats.hitsTotalDescription', {
defaultMessage: 'The number of documents that match the query.',
}),
};
}
return stats;
Expand Down
Loading