Skip to content

Commit

Permalink
Merge branch 'master' into generate-errors-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 18, 2021
2 parents b2372ab + d08f091 commit 95d6c31
Show file tree
Hide file tree
Showing 209 changed files with 3,887 additions and 4,487 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1582,8 +1582,8 @@ module.exports = {
plugins: ['react', '@typescript-eslint'],
files: ['x-pack/plugins/osquery/**/*.{js,mjs,ts,tsx}'],
rules: {
// 'arrow-body-style': ['error', 'as-needed'],
// 'prefer-arrow-callback': 'error',
'arrow-body-style': ['error', 'as-needed'],
'prefer-arrow-callback': 'error',
'no-unused-vars': 'off',
'react/prop-types': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
"react-moment-proptypes": "^1.7.0",
"react-monaco-editor": "^0.41.2",
"react-popper-tooltip": "^2.10.1",
"react-query": "^3.21.1",
"react-query": "^3.27.0",
"react-redux": "^7.2.0",
"react-resizable": "^1.7.5",
"react-resize-detector": "^4.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const previouslyRegisteredTypes = [
'ml-module',
'ml-telemetry',
'monitoring-telemetry',
'osquery-pack',
'osquery-saved-query',
'osquery-usage-metric',
'osquery-manager-usage-metric',
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/apm/scripts/upload-telemetry-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { argv } from 'yargs';
import { Logger } from 'kibana/server';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { CollectTelemetryParams } from '../../server/lib/apm_telemetry/collect_data_telemetry';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { unwrapEsResponse } from '../../../observability/server/utils/unwrap_es_response';
import { unwrapEsResponse } from '../../../observability/common/utils/unwrap_es_response';
import { downloadTelemetryTemplate } from '../shared/download-telemetry-template';
import { mergeApmTelemetryMapping } from '../../common/apm_telemetry';
import { generateSampleDocuments } from './generate-sample-documents';
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import {
getAgentById,
} from './services/agents';
import { registerFleetUsageCollector } from './collectors/register';
import { getInstallation } from './services/epm/packages';
import { getInstallation, ensureInstalledPackage } from './services/epm/packages';
import { makeRouterEnforcingSuperuser } from './routes/security';
import { startFleetServerSetup } from './services/fleet_server';
import { FleetArtifactsClient } from './services/artifacts';
Expand Down Expand Up @@ -306,6 +306,7 @@ export class FleetPlugin
esIndexPatternService: new ESIndexPatternSavedObjectService(),
packageService: {
getInstallation,
ensureInstalledPackage,
},
agentService: {
getAgent: getAgentById,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { GetAgentStatusResponse } from '../../common';
import type { getAgentById, getAgentsByKuery } from './agents';
import type { agentPolicyService } from './agent_policy';
import * as settingsService from './settings';
import type { getInstallation } from './epm/packages';
import type { getInstallation, ensureInstalledPackage } from './epm/packages';

export { ESIndexPatternSavedObjectService } from './es_index_pattern';
export { getRegistryUrl } from './epm/registry/registry_url';
Expand All @@ -37,6 +37,7 @@ export interface ESIndexPatternService {

export interface PackageService {
getInstallation: typeof getInstallation;
ensureInstalledPackage: typeof ensureInstalledPackage;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import { i18n } from '@kbn/i18n';
import type { KibanaRequest } from 'kibana/server';
import type { RequestStatistics, RequestStatus } from '../../../../../src/plugins/inspector';
import { WrappedElasticsearchClientError } from '../index';
import { InspectResponse } from '../../typings/common';
import { WrappedElasticsearchClientError } from './unwrap_es_response';

/**
* Get statistics to show on inspector tab.
Expand All @@ -29,19 +29,26 @@ function getStats({
kibanaRequest: KibanaRequest;
}) {
const stats: RequestStatistics = {
kibanaApiQueryParameters: {
label: i18n.translate('xpack.observability.inspector.stats.kibanaApiQueryParametersLabel', {
defaultMessage: 'Kibana API query parameters',
}),
description: i18n.translate(
'xpack.observability.inspector.stats.kibanaApiQueryParametersDescription',
{
defaultMessage:
'The query parameters used in the Kibana API request that initiated the Elasticsearch request.',
...(kibanaRequest.query
? {
kibanaApiQueryParameters: {
label: i18n.translate(
'xpack.observability.inspector.stats.kibanaApiQueryParametersLabel',
{
defaultMessage: 'Kibana API query parameters',
}
),
description: i18n.translate(
'xpack.observability.inspector.stats.kibanaApiQueryParametersDescription',
{
defaultMessage:
'The query parameters used in the Kibana API request that initiated the Elasticsearch request.',
}
),
value: JSON.stringify(kibanaRequest.query, null, 2),
},
}
),
value: JSON.stringify(kibanaRequest.query, null, 2),
},
: {}),
kibanaApiRoute: {
label: i18n.translate('xpack.observability.inspector.stats.kibanaApiRouteLabel', {
defaultMessage: 'Kibana API route',
Expand Down Expand Up @@ -93,11 +100,17 @@ function getStats({
}

if (esResponse?.hits?.total !== undefined) {
const total = esResponse.hits.total as {
relation: string;
value: number;
};
const hitsTotalValue = total.relation === 'eq' ? `${total.value}` : `> ${total.value}`;
let hitsTotalValue;

if (typeof esResponse.hits.total === 'number') {
hitsTotalValue = esResponse.hits.total;
} else {
const total = esResponse.hits.total as {
relation: string;
value: number;
};
hitsTotalValue = total.relation === 'eq' ? `${total.value}` : `> ${total.value}`;
}

stats.hitsTotal = {
label: i18n.translate('xpack.observability.inspector.stats.hitsTotalLabel', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { useAppIndexPatternContext } from '../hooks/use_app_index_pattern';
import { ESFilter } from '../../../../../../../../src/core/types/elasticsearch';
import { PersistableFilter } from '../../../../../../lens/common';

export function useFilterValues({ field, series, baseFilters }: FilterProps, query?: string) {
export function useFilterValues(
{ field, series, baseFilters, label }: FilterProps,
query?: string
) {
const { indexPatterns } = useAppIndexPatternContext(series.dataType);

const queryFilters: ESFilter[] = [];
Expand All @@ -28,6 +31,7 @@ export function useFilterValues({ field, series, baseFilters }: FilterProps, que

return useValuesList({
query,
label,
sourceField: field,
time: series.time,
keepHistory: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function FieldValueSuggestions({
required,
allowExclusions = true,
cardinalityField,
inspector,
asCombobox = true,
onChange: onSelectionChange,
}: FieldValueSuggestionsProps) {
Expand All @@ -44,7 +45,9 @@ export function FieldValueSuggestions({
sourceField,
filters,
time,
inspector,
cardinalityField,
label,
keepHistory: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { PopoverAnchorPosition } from '@elastic/eui';
import { Dispatch, SetStateAction } from 'react';
import { ESFilter } from 'src/core/types/elasticsearch';
import { IInspectorInfo } from '../../../../../../../src/plugins/data/common';

interface CommonProps {
selectedValue?: string[];
Expand Down Expand Up @@ -37,6 +38,7 @@ export type FieldValueSuggestionsProps = CommonProps & {
onChange: (val?: string[], excludedValue?: string[]) => void;
filters: ESFilter[];
time?: { from: string; to: string };
inspector?: IInspectorInfo;
};

export type FieldValueSelectionProps = CommonProps & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ const value: InspectorContextValue = {

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

export type AddInspectorRequest = (
result: FetcherResult<{
mainStatisticsData?: { _inspect?: InspectResponse };
_inspect?: InspectResponse;
}>
) => void;

export function InspectorContextProvider({ children }: { children: ReactNode }) {
const history = useHistory();
const { inspectorAdapters } = value;
Expand Down
46 changes: 40 additions & 6 deletions x-pack/plugins/observability/public/hooks/use_es_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,61 @@ import { estypes } from '@elastic/elasticsearch';
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
import { ESSearchResponse } from '../../../../../src/core/types/elasticsearch';
import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import { isCompleteResponse } from '../../../../../src/plugins/data/common';
import { useFetcher } from './use_fetcher';
import { IInspectorInfo, isCompleteResponse } from '../../../../../src/plugins/data/common';
import { FETCH_STATUS, useFetcher } from './use_fetcher';
import { useInspectorContext } from '../context/inspector/use_inspector_context';
import { getInspectResponse } from '../../common/utils/get_inspect_response';

export const useEsSearch = <DocumentSource extends unknown, TParams extends estypes.SearchRequest>(
params: TParams,
fnDeps: any[]
fnDeps: any[],
options: { inspector?: IInspectorInfo; name: string }
) => {
const {
services: { data },
} = useKibana<{ data: DataPublicPluginStart }>();

const { name } = options ?? {};

const { addInspectorRequest } = useInspectorContext();

const { data: response = {}, loading } = useFetcher(() => {
if (params.index) {
const startTime = Date.now();
return new Promise((resolve) => {
const search$ = data.search
.search({
params,
})
.search(
{
params,
},
{}
)
.subscribe({
next: (result) => {
if (isCompleteResponse(result)) {
if (addInspectorRequest) {
addInspectorRequest({
data: {
_inspect: [
getInspectResponse({
startTime,
esRequestParams: params,
esResponse: result.rawResponse,
esError: null,
esRequestStatus: 1,
operationName: name,
kibanaRequest: {
route: {
path: '/internal/bsearch',
method: 'POST',
},
} as any,
}),
],
},
status: FETCH_STATUS.SUCCESS,
});
}
// Final result
resolve(result);
search$.unsubscribe();
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/observability/public/hooks/use_values_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ import { useEffect, useState } from 'react';
import useDebounce from 'react-use/lib/useDebounce';
import { ESFilter } from '../../../../../src/core/types/elasticsearch';
import { createEsParams, useEsSearch } from './use_es_search';
import { IInspectorInfo } from '../../../../../src/plugins/data/common';
import { TRANSACTION_URL } from '../components/shared/exploratory_view/configurations/constants/elasticsearch_fieldnames';

export interface Props {
sourceField: string;
label: string;
query?: string;
indexPatternTitle?: string;
filters?: ESFilter[];
time?: { from: string; to: string };
keepHistory?: boolean;
cardinalityField?: string;
inspector?: IInspectorInfo;
}

export interface ListItem {
Expand Down Expand Up @@ -60,6 +63,7 @@ export const useValuesList = ({
query = '',
filters,
time,
label,
keepHistory,
cardinalityField,
}: Props): { values: ListItem[]; loading?: boolean } => {
Expand Down Expand Up @@ -131,7 +135,8 @@ export const useValuesList = ({
},
},
}),
[debouncedQuery, from, to, JSON.stringify(filters), indexPatternTitle, sourceField]
[debouncedQuery, from, to, JSON.stringify(filters), indexPatternTitle, sourceField],
{ name: `get${label.replace(/\s/g, '')}ValuesList` }
);

useEffect(() => {
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 @@ -83,5 +83,8 @@ export type {
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 {
InspectorContextProvider,
AddInspectorRequest,
} from './context/inspector/inspector_context';
export { useInspectorContext } from './context/inspector/use_inspector_context';
7 changes: 5 additions & 2 deletions x-pack/plugins/observability/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import { PluginConfigDescriptor, PluginInitializerContext } from 'src/core/serve
import { ObservabilityPlugin, ObservabilityPluginSetup } from './plugin';
import { createOrUpdateIndex, Mappings } from './utils/create_or_update_index';
import { ScopedAnnotationsClient } from './lib/annotations/bootstrap_annotations';
import { unwrapEsResponse, WrappedElasticsearchClientError } from './utils/unwrap_es_response';
import {
unwrapEsResponse,
WrappedElasticsearchClientError,
} from '../common/utils/unwrap_es_response';
export { rangeQuery, kqlQuery } from './utils/queries';
export { getInspectResponse } from './utils/get_inspect_response';
export { getInspectResponse } from '../common/utils/get_inspect_response';

export * from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../../../common/annotations';
import { createOrUpdateIndex } from '../../utils/create_or_update_index';
import { mappings } from './mappings';
import { unwrapEsResponse } from '../../utils/unwrap_es_response';
import { unwrapEsResponse } from '../../../common/utils/unwrap_es_response';

type CreateParams = t.TypeOf<typeof createAnnotationRt>;
type DeleteParams = t.TypeOf<typeof deleteAnnotationRt>;
Expand Down
Loading

0 comments on commit 95d6c31

Please sign in to comment.