Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into nls/sb/alias
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Dec 19, 2024
2 parents 443518f + 094e4ae commit 8b99be9
Show file tree
Hide file tree
Showing 61 changed files with 568 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { Transform, Readable } from 'stream';
import { inspect } from 'util';

import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { Client } from '@elastic/elasticsearch';
import { ToolingLog } from '@kbn/tooling-log';

Expand Down
13 changes: 13 additions & 0 deletions packages/kbn-es-query/src/filters/build_filters/exists_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ export const buildExistsFilter = (field: DataViewFieldBase, indexPattern: DataVi
},
} as ExistsFilter;
};

export const buildSimpleExistFilter = (fieldName: string, dataViewId: string) => {
return {
meta: {
index: dataViewId,
},
query: {
exists: {
field: fieldName,
},
},
} as ExistsFilter;
};
14 changes: 14 additions & 0 deletions packages/kbn-es-query/src/filters/build_filters/range_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ export const buildRangeFilter = (
}
};

export const buildSimpleNumberRangeFilter = (
fieldName: string,
params: RangeFilterParams,
value: string,
dataViewId: string
) => {
return buildRangeFilter(
{ name: fieldName, type: 'number' },
params,
{ id: dataViewId, title: dataViewId },
value
);
};

/**
* @internal
*/
Expand Down
39 changes: 28 additions & 11 deletions packages/kbn-eslint-plugin-css/src/rules/no_css_color.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
filename: '/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import React from 'react';
function TestComponent() {
return (
<EuiCode style={{ color: '#dd4040' }}>This is a test</EuiCode>
Expand Down Expand Up @@ -86,7 +86,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
filename: '/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import React from 'react';
function TestComponent() {
const baseStyle = { background: 'rgb(255, 255, 255)' };
Expand Down Expand Up @@ -116,7 +116,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
filename: '/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import React from 'react';
function TestComponent() {
return (
<EuiCode style={{ background: '#dd4040' }}>This is a test</EuiCode>
Expand All @@ -129,7 +129,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
filename: '/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import React from 'react';
function TestComponent() {
return (
<EuiCode css={{ color: '#dd4040' }}>This is a test</EuiCode>
Expand All @@ -153,7 +153,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
code: `
import React from 'react';
import { css } from '@emotion/css';
function TestComponent() {
return (
<EuiCode css={css\` color: #dd4040; \`}>This is a test</EuiCode>
Expand All @@ -171,7 +171,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
const codeCss = css({
color: '#dd4040',
})
function TestComponent() {
return (
<EuiCode css={codeCss}>This is a test</EuiCode>
Expand All @@ -187,7 +187,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
import { css } from '@emotion/css';
const codeCss = css\` color: #dd4040; \`
function TestComponent() {
return (
<EuiCode css={codeCss}>This is a test</EuiCode>
Expand All @@ -200,7 +200,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
filename: '/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import React from 'react';
function TestComponent() {
return (
<EuiCode css={() => ({ color: '#dd4040' })}>This is a test</EuiCode>
Expand All @@ -213,7 +213,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
filename: '/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import React from 'react';
function TestComponent() {
return (
<EuiCode css={function () { return { color: '#dd4040' }; }}>This is a test</EuiCode>
Expand All @@ -227,7 +227,7 @@ const invalid: RuleTester.InvalidTestCase[] = [
code: `
import React from 'react';
import { css } from '@emotion/css';
function TestComponent() {
return (
<EuiCode className={css\` color: #dd4040; \`}>This is a test</EuiCode>
Expand All @@ -237,7 +237,24 @@ const invalid: RuleTester.InvalidTestCase[] = [
},
];

const valid: RuleTester.ValidTestCase[] = [];
const valid: RuleTester.ValidTestCase[] = [
{
name: 'Does not raise an error when a CSS color is not used in a JSX css prop attribute',
filename: '/x-pack/plugins/observability_solution/observability/public/test_component.tsx',
code: `
import React from 'react';
import { EuiCode } from '@elastic/eui';
import { css } from '@emotion/react';
function TestComponent() {
return (
<EuiCode css={css\`
border-top: none;
border-radius: 0 0 6px 6px;
\`}>This is a test</EuiCode>
)
}`,
},
];

for (const [name, tester] of [tsTester, babelTester]) {
describe(name, () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/kbn-eslint-plugin-css/src/rules/no_css_color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const checkPropertySpecifiesInvalidCSSColor = ([property, value]: string[]) => {

const style = new CSSStyleDeclaration();

// @ts-ignore the types for this packages specifics an index signature of number, alongside other valid CSS properties
style[property] = value;
// @ts-ignore the types for this packages specifies an index signature of number, alongside other valid CSS properties
style[property.trim()] = typeof value === 'string' ? value.trim() : value;

const anchor = propertiesSupportingCssColor.find((resolvedProperty) =>
property.includes(resolvedProperty)
Expand All @@ -42,9 +42,9 @@ const checkPropertySpecifiesInvalidCSSColor = ([property, value]: string[]) => {
// build the resolved color property to check if the value is a string after parsing the style declaration
const resolvedColorProperty = anchor === 'color' ? 'color' : anchor + 'Color';

// in trying to keep this rule simple, it's enough if a string is used to define a color to mark it as invalid
// in trying to keep this rule simple, it's enough if we get a value back, because if it was an identifier we would have been able to set a value within this invocation
// @ts-ignore the types for this packages specifics an index signature of number, alongside other valid CSS properties
return typeof style[resolvedColorProperty] === 'string';
return Boolean(style[resolvedColorProperty]);
};

const resolveMemberExpressionRoot = (node: TSESTree.MemberExpression): TSESTree.Identifier => {
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-management/settings/setting_ids/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const OBSERVABILITY_LOGS_EXPLORER_ALLOWED_DATA_VIEWS_ID =
export const OBSERVABILITY_LOGS_SHARED_NEW_LOGS_OVERVIEW_ID = 'observability:newLogsOverview';
export const OBSERVABILITY_ENTITY_CENTRIC_EXPERIENCE = 'observability:entityCentricExperience';
export const OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID = 'observability:logSources';
export const OBSERVABILITY_ENABLE_LOGS_STREAM = 'observability:enableLogsStream';
export const OBSERVABILITY_AI_ASSISTANT_SIMULATED_FUNCTION_CALLING =
'observability:aiAssistantSimulatedFunctionCalling';
export const OBSERVABILITY_AI_ASSISTANT_SEARCH_CONNECTOR_INDEX_PATTERN =
Expand Down
36 changes: 17 additions & 19 deletions packages/kbn-performance-testing-dataset-extractor/src/es_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { Client } from '@elastic/elasticsearch';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { SearchRequest, MsearchRequestItem } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { SearchRequest, MsearchRequestItem } from '@elastic/elasticsearch/lib/api/types';
import { ToolingLog } from '@kbn/tooling-log';

interface ClientOptions {
Expand Down Expand Up @@ -116,26 +116,24 @@ export class ESClient {
async getTransactions<T>(queryFilters: QueryDslQueryContainer[]) {
const searchRequest: SearchRequest = {
index: this.tracesIndex,
body: {
sort: [
{
'@timestamp': {
order: 'asc',
unmapped_type: 'boolean',
},
sort: [
{
'@timestamp': {
order: 'asc',
unmapped_type: 'boolean',
},
],
size: 10000,
query: {
bool: {
filter: [
{
bool: {
filter: queryFilters,
},
},
],
size: 10000,
query: {
bool: {
filter: [
{
bool: {
filter: queryFilters,
},
],
},
},
],
},
},
};
Expand Down
1 change: 1 addition & 0 deletions src/platform/packages/shared/kbn-esql-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export {
isESQLColumnGroupable,
isESQLFieldGroupable,
TextBasedLanguages,
sanitazeESQLInput,
queryCannotBeSampled,
} from './src';

Expand Down
1 change: 1 addition & 0 deletions src/platform/packages/shared/kbn-esql-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export {
isESQLColumnGroupable,
isESQLFieldGroupable,
} from './utils/esql_fields_utils';
export { sanitazeESQLInput } from './utils/sanitaze_input';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import { getAstAndSyntaxErrors } from '@kbn/esql-ast';
import { sanitazeESQLInput } from './sanitaze_input';

// Append in a new line the appended text to take care of the case where the user adds a comment at the end of the query
// in these cases a base query such as "from index // comment" will result in errors or wrong data if we don't append in a new line
Expand Down Expand Up @@ -43,7 +44,7 @@ export function appendWhereClauseToESQLQuery(
let filterValue =
typeof value === 'string' ? `"${value.replace(/\\/g, '\\\\').replace(/\"/g, '\\"')}"` : value;
// Adding the backticks here are they are needed for special char fields
let fieldName = `\`${field}\``;
let fieldName = sanitazeESQLInput(field);

// casting to string
// there are some field types such as the ip that need
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export function sanitazeESQLInput(input: string): string | undefined {
return `\`${input.replace(/`/g, '``')}\``;
}
Original file line number Diff line number Diff line change
Expand Up @@ -612,22 +612,30 @@ async function getExpressionSuggestionsByType(
(fragment) => Boolean(getColumnByName(fragment, references)),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// COMMAND fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text + (['grok', 'dissect'].includes(command.name) ? ' ' : ''),
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text + (['grok', 'dissect'].includes(command.name) ? ' ' : ''),
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// COMMAND field<suggest>
if (['grok', 'dissect'].includes(command.name)) {
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text + ' ',
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text + ' ',
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
}

const finalSuggestions = [{ ...pipeCompleteItem, text: ' | ' }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export async function suggest(
(fragment) => columnExists(fragment),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// KEEP fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// KEEP field<suggest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export async function suggest(
(fragment) => columnExists(fragment),
(_fragment: string, rangeToReplace?: { start: number; end: number }) => {
// KEEP fie<suggest>
return fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}));
return fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
text: suggestion.text,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
});
},
(fragment: string, rangeToReplace: { start: number; end: number }) => {
// KEEP field<suggest>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ export async function suggest(
// SORT fie<suggest>
return [
...pushItUpInTheList(
fieldSuggestions.map((suggestion) => ({
...suggestion,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
})),
fieldSuggestions.map((suggestion) => {
// if there is already a command, we don't want to override it
if (suggestion.command) return suggestion;
return {
...suggestion,
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
};
}),
true
),
...functionSuggestions,
Expand Down
Loading

0 comments on commit 8b99be9

Please sign in to comment.