[Observability] Move InspectContextProvider and utils to observability (#113842)
This commit is contained in:
parent
380c51ab33
commit
c2049ed754
20 changed files with 79 additions and 80 deletions
|
@ -13,7 +13,6 @@
|
|||
"embeddable",
|
||||
"features",
|
||||
"infra",
|
||||
"inspector",
|
||||
"licensing",
|
||||
"observability",
|
||||
"ruleRegistry",
|
||||
|
|
|
@ -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[] = [
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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';
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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({
|
||||
|
|
3
x-pack/plugins/apm/typings/common.d.ts
vendored
3
x-pack/plugins/apm/typings/common.d.ts
vendored
|
@ -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
|
||||
|
@ -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[];
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"cases",
|
||||
"data",
|
||||
"features",
|
||||
"inspector",
|
||||
"ruleRegistry",
|
||||
"timelines",
|
||||
"triggersActionsUi"
|
||||
|
|
|
@ -41,7 +41,7 @@ export function buildFilterLabel({
|
|||
return filter;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
export interface FilterValueLabelProps {
|
||||
field: string;
|
||||
label: string;
|
||||
value: string | string[];
|
||||
|
@ -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 });
|
||||
|
@ -92,3 +92,6 @@ export function FilterValueLabel({
|
|||
/>
|
||||
) : null;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default FilterValueLabel;
|
||||
|
|
|
@ -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';
|
||||
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
|
@ -12,6 +12,7 @@ export enum FETCH_STATUS {
|
|||
SUCCESS = 'success',
|
||||
FAILURE = 'failure',
|
||||
PENDING = 'pending',
|
||||
NOT_INITIATED = 'not_initiated',
|
||||
}
|
||||
|
||||
export interface FetcherResult<Data> {
|
||||
|
|
|
@ -45,6 +45,7 @@ export {
|
|||
getCoreVitalsComponent,
|
||||
HeaderMenuPortal,
|
||||
FieldValueSuggestions,
|
||||
FilterValueLabel,
|
||||
} from './components/shared/';
|
||||
|
||||
export type { LazyObservabilityPageTemplateProps } from './components/shared';
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -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.',
|
||||
|
@ -49,42 +43,33 @@ 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.',
|
||||
}),
|
||||
};
|
||||
|
@ -92,21 +77,18 @@ function getStats({
|
|||
|
||||
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.',
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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;
|
|
@ -5,6 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { Request } from '../../../../src/plugins/inspector';
|
||||
|
||||
export type ObservabilityApp =
|
||||
| 'infra_metrics'
|
||||
| 'infra_logs'
|
||||
|
@ -22,3 +24,5 @@ export type PromiseReturnType<Func> = Func extends (...args: any[]) => Promise<i
|
|||
: Func;
|
||||
|
||||
export { Coordinates } from '../public/typings/fetch_overview_data/';
|
||||
|
||||
export type InspectResponse = Request[];
|
||||
|
|
Loading…
Reference in a new issue