Skip to content

Commit

Permalink
Merge branch 'main' into add-authentication-rcf-sharepoint-server
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-shelkovnikov authored Jul 24, 2024
2 parents 3899b80 + 85a90a7 commit 85496d9
Show file tree
Hide file tree
Showing 223 changed files with 669 additions and 9,627 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/alert-failed-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Alert on failed test
if: |
!github.event.issue.pull_request
&& github.event.comment.user.login == 'kibanamachine'
&& (github.event.comment.user.login == 'kibanamachine' || github.event.comment.user.login == 'elasticmachine')
runs-on: ubuntu-latest
steps:
- name: Checkout kibana-operations
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ The plugin exposes the static DefaultEditorController class to consume.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud/README.md[cloud]
|The cloud plugin adds Cloud-specific features to Kibana.
|The cloud plugin exposes Cloud-specific metadata to Kibana.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_chat/README.md[cloudChat]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class HapiResponseAdapter {
return response;
}

private toError(kibanaResponse: KibanaResponse<ResponseError | Buffer | stream.Readable>) {
private toError(kibanaResponse: KibanaResponse<ResponseError>) {
const { payload } = kibanaResponse;

// Special case for when we are proxying requests and want to enable streaming back error responses opaquely.
Expand Down Expand Up @@ -153,7 +153,12 @@ function getErrorMessage(payload?: ResponseError): string {
if (!payload) {
throw new Error('expected error message to be provided');
}
if (typeof payload === 'string') return payload;
if (typeof payload === 'string') {
return payload;
}
if (isStreamOrBuffer(payload)) {
throw new Error(`can't resolve error message from stream or buffer`);
}
// for ES response errors include nested error reason message. it doesn't contain sensitive data.
if (isElasticsearchResponseError(payload)) {
return `[${payload.message}]: ${
Expand All @@ -164,6 +169,10 @@ function getErrorMessage(payload?: ResponseError): string {
return getErrorMessage(payload.message);
}

function isStreamOrBuffer(payload: ResponseError): payload is stream.Stream | Buffer {
return Buffer.isBuffer(payload) || stream.isReadable(payload as stream.Readable);
}

function getErrorAttributes(payload?: ResponseError): ResponseErrorAttributes | undefined {
return typeof payload === 'object' && 'attributes' in payload ? payload.attributes : undefined;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/http/core-http-server/src/router/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export type ResponseErrorAttributes = Record<string, any>;
*/
export type ResponseError =
| string
| Buffer
| Stream
| Error
| {
message: string | Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/

import type { Stream } from 'stream';
import type {
CustomHttpResponseOptions,
HttpResponseOptions,
Expand Down Expand Up @@ -139,7 +138,7 @@ export interface KibanaErrorResponseFactory {
* Creates an error response with defined status code and payload.
* @param options - {@link CustomHttpResponseOptions} configures HTTP response headers, error message and other error details to pass to the client
*/
customError(options: CustomHttpResponseOptions<ResponseError | Buffer | Stream>): IKibanaResponse;
customError(options: CustomHttpResponseOptions<ResponseError>): IKibanaResponse;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/kbn-analytics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# `@kbn/analytics`

> [!NOTE]
> The term _analytics_ here refers to _Usage Analytics_, and should not be confused with the Kibana (Data) Analytics tools.
> [!IMPORTANT]
> This package is exclusively used by the plugin `usage_collection` and it's not expected to be used elsewhere.
> If you are still here for _Usage Analytics_, you might be looking for [core-analytics](../core/analytics), the [EBT packages](../analytics).
This package implements the report that batches updates from Application Usage, UI Counters, and User Agent.
It defines the contract of the report, and the strategy to ship it to the server.

7 changes: 3 additions & 4 deletions packages/kbn-esql-ast/src/walker/walker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,7 @@ describe('Walker.params', () => {
});

test('can collect all params from grouping functions', () => {
const query =
'ROW x=1, time=2024-07-10 | stats z = avg(x) by bucket(time, 20, ?earliest,?latest)';
const query = 'ROW x=1, time=2024-07-10 | stats z = avg(x) by bucket(time, 20, ?start,?end)';
const { ast } = getAstAndSyntaxErrors(query);
const params = Walker.params(ast);

Expand All @@ -602,13 +601,13 @@ describe('Walker.params', () => {
type: 'literal',
literalType: 'param',
paramType: 'named',
value: 'earliest',
value: 'start',
},
{
type: 'literal',
literalType: 'param',
paramType: 'named',
value: 'latest',
value: 'end',
},
]);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-esql-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export {
getESQLQueryColumnsRaw,
getESQLResults,
getTimeFieldFromESQLQuery,
getEarliestLatestParams,
hasEarliestLatestParams,
getStartEndParams,
hasStartEndParams,
TextBasedLanguages,
} from './src';

Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-esql-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export {
getESQLQueryColumns,
getESQLQueryColumnsRaw,
getESQLResults,
getEarliestLatestParams,
hasEarliestLatestParams,
getStartEndParams,
hasStartEndParams,
} from './utils/run_query';
10 changes: 4 additions & 6 deletions packages/kbn-esql-utils/src/utils/query_parsing_helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,25 @@ describe('esql query helpers', () => {
});

it('should return the time field if there is at least one time param', () => {
expect(getTimeFieldFromESQLQuery('from a | eval b = 1 | where time >= ?earliest')).toBe(
'time'
);
expect(getTimeFieldFromESQLQuery('from a | eval b = 1 | where time >= ?start')).toBe('time');
});

it('should return undefined if there is one named param but is not ?earliest or ?latest', () => {
it('should return undefined if there is one named param but is not ?start or ?end', () => {
expect(
getTimeFieldFromESQLQuery('from a | eval b = 1 | where time >= ?late')
).toBeUndefined();
});

it('should return undefined if there is one named param but is used without a time field', () => {
expect(
getTimeFieldFromESQLQuery('from a | eval b = DATE_TRUNC(1 day, ?earliest)')
getTimeFieldFromESQLQuery('from a | eval b = DATE_TRUNC(1 day, ?start)')
).toBeUndefined();
});

it('should return the time field if there is at least one time param in the bucket function', () => {
expect(
getTimeFieldFromESQLQuery(
'from a | stats meow = avg(bytes) by bucket(event.timefield, 200, ?earliest, ?latest)'
'from a | stats meow = avg(bytes) by bucket(event.timefield, 200, ?start, ?end)'
)
).toBe('event.timefield');
});
Expand Down
6 changes: 2 additions & 4 deletions packages/kbn-esql-utils/src/utils/query_parsing_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function removeDropCommandsFromESQLQuery(esql?: string): string {
}

/**
* When the ?earliest and ?latest params are used, we want to retrieve the timefield from the query.
* When the ?start and ?end params are used, we want to retrieve the timefield from the query.
* @param esql:string
* @returns string
*/
Expand All @@ -69,9 +69,7 @@ export const getTimeFieldFromESQLQuery = (esql: string) => {
});

const params = Walker.params(ast);
const timeNamedParam = params.find(
(param) => param.value === 'earliest' || param.value === 'latest'
);
const timeNamedParam = params.find((param) => param.value === 'start' || param.value === 'end');
if (!timeNamedParam || !functions.length) {
return undefined;
}
Expand Down
32 changes: 16 additions & 16 deletions packages/kbn-esql-utils/src/utils/run_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,38 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { getEarliestLatestParams } from './run_query';
import { getStartEndParams } from './run_query';

describe('getEarliestLatestParams', () => {
describe('getStartEndParams', () => {
it('should return an empty array if there are no time params', () => {
const time = { from: 'now-15m', to: 'now' };
const query = 'FROM foo';
const params = getEarliestLatestParams(query, time);
const params = getStartEndParams(query, time);
expect(params).toEqual([]);
});

it('should return an array with the earliest param if exists at the query', () => {
it('should return an array with the start param if exists at the query', () => {
const time = { from: 'Jul 5, 2024 @ 08:03:56.849', to: 'Jul 5, 2024 @ 10:03:56.849' };
const query = 'FROM foo | where time > ?earliest';
const params = getEarliestLatestParams(query, time);
const query = 'FROM foo | where time > ?start';
const params = getStartEndParams(query, time);
expect(params).toHaveLength(1);
expect(params[0]).toHaveProperty('earliest');
expect(params[0]).toHaveProperty('start');
});

it('should return an array with the latest param if exists at the query', () => {
it('should return an array with the end param if exists at the query', () => {
const time = { from: 'Jul 5, 2024 @ 08:03:56.849', to: 'Jul 5, 2024 @ 10:03:56.849' };
const query = 'FROM foo | where time < ?latest';
const params = getEarliestLatestParams(query, time);
const query = 'FROM foo | where time < ?end';
const params = getStartEndParams(query, time);
expect(params).toHaveLength(1);
expect(params[0]).toHaveProperty('latest');
expect(params[0]).toHaveProperty('end');
});

it('should return an array with the latest and earliest params if exist at the query', () => {
it('should return an array with the end and start params if exist at the query', () => {
const time = { from: 'Jul 5, 2024 @ 08:03:56.849', to: 'Jul 5, 2024 @ 10:03:56.849' };
const query = 'FROM foo | where time < ?latest amd time > ?earliest';
const params = getEarliestLatestParams(query, time);
const query = 'FROM foo | where time < ?end amd time > ?start';
const params = getStartEndParams(query, time);
expect(params).toHaveLength(2);
expect(params[0]).toHaveProperty('earliest');
expect(params[1]).toHaveProperty('latest');
expect(params[0]).toHaveProperty('start');
expect(params[1]).toHaveProperty('end');
});
});
26 changes: 13 additions & 13 deletions packages/kbn-esql-utils/src/utils/run_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ import { esFieldTypeToKibanaFieldType } from '@kbn/field-types';
import type { ESQLColumn, ESQLSearchResponse, ESQLSearchParams } from '@kbn/es-types';
import { lastValueFrom } from 'rxjs';

export const hasEarliestLatestParams = (query: string) => /\?earliest|\?latest/i.test(query);
export const hasStartEndParams = (query: string) => /\?start|\?end/i.test(query);

export const getEarliestLatestParams = (query: string, time?: TimeRange) => {
const earliestNamedParams = /\?earliest/i.test(query);
const latestNamedParams = /\?latest/i.test(query);
if (time && (earliestNamedParams || latestNamedParams)) {
export const getStartEndParams = (query: string, time?: TimeRange) => {
const startNamedParams = /\?start/i.test(query);
const endNamedParams = /\?end/i.test(query);
if (time && (startNamedParams || endNamedParams)) {
const timeParams = {
earliest: earliestNamedParams ? dateMath.parse(time.from)?.toISOString() : undefined,
latest: latestNamedParams ? dateMath.parse(time.to)?.toISOString() : undefined,
start: startNamedParams ? dateMath.parse(time.from)?.toISOString() : undefined,
end: endNamedParams ? dateMath.parse(time.to)?.toISOString() : undefined,
};
const namedParams = [];
if (timeParams?.earliest) {
namedParams.push({ earliest: timeParams.earliest });
if (timeParams?.start) {
namedParams.push({ start: timeParams.start });
}
if (timeParams?.latest) {
namedParams.push({ latest: timeParams.latest });
if (timeParams?.end) {
namedParams.push({ end: timeParams.end });
}
return namedParams;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function getESQLQueryColumnsRaw({
timeRange?: TimeRange;
}): Promise<ESQLColumn[]> {
try {
const namedParams = getEarliestLatestParams(esqlQuery, timeRange);
const namedParams = getStartEndParams(esqlQuery, timeRange);
const response = await lastValueFrom(
search(
{
Expand Down Expand Up @@ -135,7 +135,7 @@ export async function getESQLResults({
response: ESQLSearchResponse;
params: ESQLSearchParams;
}> {
const namedParams = getEarliestLatestParams(esqlQuery, timeRange);
const namedParams = getStartEndParams(esqlQuery, timeRange);
const result = await lastValueFrom(
search(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const allFunctions = statsAggregationFunctionDefinitions
.concat(evalFunctionDefinitions)
.concat(groupingFunctionDefinitions);

export const TIME_SYSTEM_PARAMS = ['?earliest', '?latest'];
export const TIME_SYSTEM_PARAMS = ['?start', '?end'];

export const TRIGGER_SUGGESTION_COMMAND = {
title: 'Trigger Suggestion Dialog',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ test('should allow param inside agg function argument', async () => {
test('allow params in WHERE command expressions', async () => {
const { validate } = await setup();

const res1 = await validate('FROM index | WHERE stringField >= ?earliest');
const res1 = await validate('FROM index | WHERE stringField >= ?start');
const res2 = await validate(`
FROM index
| WHERE stringField >= ?earliest
| WHERE stringField >= ?start
| WHERE stringField <= ?0
| WHERE stringField == ?
`);
const res3 = await validate(`
FROM index
| WHERE stringField >= ?earliest
| WHERE stringField >= ?start
AND stringField <= ?0
AND stringField == ?
`);
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/search/expressions/esql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { i18n } from '@kbn/i18n';
import type { IKibanaSearchResponse, IKibanaSearchRequest } from '@kbn/search-types';
import type { Datatable, ExpressionFunctionDefinition } from '@kbn/expressions-plugin/common';
import { RequestAdapter } from '@kbn/inspector-plugin/common';
import { getEarliestLatestParams } from '@kbn/esql-utils';
import { getStartEndParams } from '@kbn/esql-utils';

import { zipObject } from 'lodash';
import { Observable, defer, throwError } from 'rxjs';
Expand Down Expand Up @@ -154,7 +154,7 @@ export const getEsqlFn = ({ getStartDependencies }: EsqlFnArguments) => {
uiSettings as Parameters<typeof getEsQueryConfig>[0]
);

const namedParams = getEarliestLatestParams(query, input.timeRange);
const namedParams = getStartEndParams(query, input.timeRange);

if (namedParams.length) {
params.params = namedParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('getEsqlDataView', () => {
});

it('returns an adhoc dataview if it is adhoc with named params and query index pattern is the same as the dataview index pattern', async () => {
const query = { esql: 'from data-view-ad-hoc-title | where time >= ?earliest' };
const query = { esql: 'from data-view-ad-hoc-title | where time >= ?start' };
const dataView = await getEsqlDataView(query, dataViewAdHocNoAtTimestamp, services);
expect(dataView.timeFieldName).toBe('time');
});
Expand Down
4 changes: 2 additions & 2 deletions test/functional/apps/discover/esql/_esql_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await testSubjects.exists('unifiedHistogramChart')).to.be(false);
});

it('should render the histogram for indices with no @timestamp field when the ?earliest, ?latest params are in the query', async function () {
it('should render the histogram for indices with no @timestamp field when the ?start, ?end params are in the query', async function () {
await PageObjects.discover.selectTextBaseLang();
await PageObjects.unifiedFieldList.waitUntilSidebarHasLoaded();

const testQuery = `from kibana_sample_data_flights | limit 10 | where timestamp >= ?earliest and timestamp <= ?latest`;
const testQuery = `from kibana_sample_data_flights | limit 10 | where timestamp >= ?start and timestamp <= ?end`;

await monacoEditor.setCodeEditorValue(testQuery);
await testSubjects.click('querySubmitButton');
Expand Down
Loading

0 comments on commit 85496d9

Please sign in to comment.