Skip to content

Commit

Permalink
Merge branch 'main' into storybook/update-6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
clintandrewhall committed Aug 24, 2022
2 parents 943cf00 + 7a10739 commit 8526a33
Show file tree
Hide file tree
Showing 342 changed files with 11,335 additions and 6,704 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -183,6 +183,7 @@ x-pack/examples/files_example @elastic/kibana-app-services
/src/plugins/controls/ @elastic/kibana-presentation
/test/functional/apps/dashboard/ @elastic/kibana-presentation
/test/functional/apps/dashboard_elements/ @elastic/kibana-presentation
/test/functional/services/dashboard/ @elastic/kibana-presentation
/x-pack/plugins/canvas/ @elastic/kibana-presentation
/x-pack/plugins/dashboard_enhanced/ @elastic/kibana-presentation
/x-pack/test/functional/apps/canvas/ @elastic/kibana-presentation
Expand Down
2 changes: 1 addition & 1 deletion docs/management/advanced-options.asciidoc
Expand Up @@ -89,7 +89,7 @@ Set this property to `false` to prevent the filter editor and KQL autocomplete
from suggesting values for fields.

[[autocomplete-valuesuggestionmethod]]`autocomplete:valueSuggestionMethod`::
When set to `terms_enum`, autocomplete uses the terms enum API for value suggestions. Kibana returns results faster, but suggestions are approximate, sorted alphabetically, and can be outside the selected time range.
When set to `terms_enum`, autocomplete uses the terms enum API for value suggestions. Kibana returns results faster, but suggestions are approximate, sorted alphabetically, and can be outside the selected time range. (Note that this API is incompatible with {ref}/document-level-security.html[Document-Level-Security].)
When set to `terms_agg`, Kibana uses a terms aggregation for value suggestions, which is
slower, but suggestions include all values that optionally match your time range and are sorted by popularity.

Expand Down
6 changes: 3 additions & 3 deletions docs/maps/asset-tracking-tutorial.asciidoc
Expand Up @@ -318,9 +318,9 @@ cloud.auth: <username:password>
. In {kib}, open the main menu, and click *Stack Management > Data Views*.
. Click *Create data view*.
. Give the data view a name: *tri_met_tracks**.
. Click *Next step*.
. Set the *Time field* to *trimet.time*.
. Click *Create data view*.
. Set the index pattern as: *tri_met_tracks**.
. Set the *Timestamp field* to *trimet.time*.
. Click *Save data view to Kibana*.

{kib} shows the fields in your data view.

Expand Down
142 changes: 71 additions & 71 deletions packages/BUILD.bazel

Large diffs are not rendered by default.

Expand Up @@ -54,9 +54,8 @@ export class ApmSynthtraceKibanaClient {
});
}
async fetchLatestApmPackageVersion(currentKibanaVersion: string) {
const url =
'https://epr-snapshot.elastic.co/search?package=apm&prerelease=true&all=true&kibana.version=';
const response = await fetch(url + currentKibanaVersion, { method: 'GET' });
const url = `https://epr-snapshot.elastic.co/search?package=apm&prerelease=true&all=true&kibana.version=${currentKibanaVersion}`;
const response = await fetch(url, { method: 'GET' });
const json = (await response.json()) as Array<{ version: string }>;
const packageVersions = (json ?? []).map((item) => item.version).sort(Semver.rcompare);
const validPackageVersions = packageVersions.filter((v) => Semver.valid(v));
Expand All @@ -71,7 +70,7 @@ export class ApmSynthtraceKibanaClient {

async installApmPackage(kibanaUrl: string, version: string, username: string, password: string) {
const packageVersion = await this.fetchLatestApmPackageVersion(version);
const response = await fetch(kibanaUrl + '/api/fleet/epm/packages/apm/' + packageVersion, {
const response = await fetch(`${kibanaUrl}/api/fleet/epm/packages/apm/${packageVersion}`, {
method: 'POST',
headers: {
Authorization: 'Basic ' + Buffer.from(username + ':' + password).toString('base64'),
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-apm-synthtrace/src/lib/apm/index.ts
Expand Up @@ -13,6 +13,7 @@ import { getChromeUserAgentDefaults } from './defaults/get_chrome_user_agent_def
import { getBreakdownMetrics } from './processors/get_breakdown_metrics';
import { getApmWriteTargets } from './utils/get_apm_write_targets';
import { ApmSynthtraceEsClient } from './client/apm_synthtrace_es_client';
import { ApmSynthtraceKibanaClient } from './client/apm_synthtrace_kibana_client';

import type { ApmException } from './apm_fields';

Expand All @@ -25,6 +26,7 @@ export const apm = {
getBreakdownMetrics,
getApmWriteTargets,
ApmSynthtraceEsClient,
ApmSynthtraceKibanaClient,
};

export type { ApmSynthtraceEsClient, ApmException };
14 changes: 3 additions & 11 deletions packages/kbn-bazel-packages/BUILD.bazel
Expand Up @@ -7,6 +7,7 @@ PKG_REQUIRE_NAME = "@kbn/bazel-packages"

SOURCE_FILES = glob(
[
"src/**/*.js",
"src/**/*.ts",
],
exclude = [
Expand Down Expand Up @@ -37,11 +38,6 @@ NPM_MODULE_EXTRA_FILES = [
# "@npm//name-of-package"
# eg. "@npm//lodash"
RUNTIME_DEPS = [
"//packages/kbn-utils",
"//packages/kbn-std",
"//packages/kbn-synthetic-package-map",
"@npm//globby",
"@npm//normalize-path",
]

# In this array place dependencies necessary to build the types, which will include the
Expand All @@ -55,13 +51,8 @@ RUNTIME_DEPS = [
# References to NPM packages work the same as RUNTIME_DEPS:
# eg. "@npm//@types/babel__core"
TYPES_DEPS = [
"//packages/kbn-utils:npm_module_types",
"//packages/kbn-std:npm_module_types",
"//packages/kbn-synthetic-package-map:npm_module_types",
"@npm//@types/node",
"@npm//@types/normalize-path",
"@npm//globby",
"@npm//normalize-path",
"@npm//@types/jest",
]

jsts_transpiler(
Expand All @@ -87,6 +78,7 @@ ts_project(
deps = TYPES_DEPS,
declaration = True,
declaration_map = True,
allow_js = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
Expand Down
107 changes: 107 additions & 0 deletions packages/kbn-bazel-packages/src/async.js
@@ -0,0 +1,107 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

/**
*
* @template T
* @template T2
* @param {(v: T) => Promise<T2>} fn
* @param {T} item
* @returns {Promise<PromiseSettledResult<T2>>}
*/
const settle = async (fn, item) => {
const [result] = await Promise.allSettled([(async () => fn(item))()]);
return result;
};

/**
* @template T
* @template T2
* @param {Array<T>} source
* @param {number} limit
* @param {(v: T) => Promise<T2>} mapFn
* @returns {Promise<T2[]>}
*/
function asyncMapWithLimit(source, limit, mapFn) {
return new Promise((resolve, reject) => {
if (limit < 1) {
reject(new Error('invalid limit, must be greater than 0'));
return;
}

let failed = false;
let inProgress = 0;
const queue = [...source.entries()];

/** @type {T2[]} */
const results = new Array(source.length);

/**
* this is run for each item, manages the inProgress state,
* calls the mapFn with that item, writes the map result to
* the result array, and calls runMore() after each item
* completes to either start another item or resolve the
* returned promise.
*
* @param {number} index
* @param {T} item
*/
function run(index, item) {
inProgress += 1;
settle(mapFn, item).then((result) => {
inProgress -= 1;

if (failed) {
return;
}

if (result.status === 'fulfilled') {
results[index] = result.value;
runMore();
return;
}

// when an error occurs we update the state to prevent
// holding onto old results and ignore future results
// from in-progress promises
failed = true;
results.length = 0;
reject(result.reason);
});
}

/**
* If there is work in the queue, schedule it, if there isn't
* any work to be scheduled and there isn't anything in progress
* then we're done. This function is called every time a mapFn
* promise resolves and once after initialization
*/
function runMore() {
if (!queue.length) {
if (inProgress === 0) {
resolve(results);
}

return;
}

while (inProgress < limit) {
const entry = queue.shift();
if (!entry) {
break;
}

run(...entry);
}
}

runMore();
});
}

module.exports = { asyncMapWithLimit };
61 changes: 61 additions & 0 deletions packages/kbn-bazel-packages/src/async.test.ts
@@ -0,0 +1,61 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

import { setTimeout } from 'timers/promises';
import { asyncMapWithLimit } from './async';

const NUMS = [1, 2, 3, 4];
const ident = jest.fn(async function ident<T>(x: T) {
return await x;
});
const double = jest.fn(async function double(x: number) {
return x * 2;
});

beforeEach(() => {
jest.clearAllMocks();
});

it('resolves with an empty array', async () => {
const result = await asyncMapWithLimit([], 10, ident);
expect(ident).not.toHaveBeenCalled();
expect(result).toEqual([]);
});

it('resolves with a mapped array', async () => {
const result = await asyncMapWithLimit(NUMS, 10, double);
expect(double).toHaveBeenCalledTimes(NUMS.length);
expect(result.join(',')).toMatchInlineSnapshot(`"2,4,6,8"`);
});

it('rejects when limit it not >= 1', async () => {
await expect(() => asyncMapWithLimit([], -1, ident)).rejects.toMatchInlineSnapshot(
`[Error: invalid limit, must be greater than 0]`
);
await expect(() => asyncMapWithLimit([], 0, ident)).rejects.toMatchInlineSnapshot(
`[Error: invalid limit, must be greater than 0]`
);
await expect(() => asyncMapWithLimit([], -Infinity, ident)).rejects.toMatchInlineSnapshot(
`[Error: invalid limit, must be greater than 0]`
);
});

it('rejects with the first error produced and stops calling mapFn', async () => {
const map = jest.fn(async (num) => {
if (num % 2 === 0) {
throw new Error('even numbers are not supported');
}
return num * 2;
});

await expect(() => asyncMapWithLimit(NUMS, 1, map)).rejects.toMatchInlineSnapshot(
`[Error: even numbers are not supported]`
);
await setTimeout(10);
expect(map).toHaveBeenCalledTimes(2);
});
Expand Up @@ -6,27 +6,31 @@
* Side Public License, v 1.
*/

import { inspect } from 'util';
import Path from 'path';
import Fsp from 'fs/promises';
const { inspect } = require('util');
const Path = require('path');
const Fsp = require('fs/promises');

import normalizePath from 'normalize-path';
import { REPO_ROOT } from '@kbn/utils';

import { readPackageJson, ParsedPackageJson } from './parse_package_json';
/** @typedef {import('./types').ParsedPackageJson} ParsedPackageJson */
const { readPackageJson } = require('./parse_package_json');

const BUILD_RULE_NAME = /(^|\s)name\s*=\s*"build"/;
const BUILD_TYPES_RULE_NAME = /(^|\s)name\s*=\s*"build_types"/;

/**
* Representation of a Bazel Package in the Kibana repository
* @class
* @property {string} normalizedRepoRelativeDir
* @property {import('./types').ParsedPackageJson} pkg
* @property {string | undefined} buildBazelContent
*/
export class BazelPackage {
class BazelPackage {
/**
* Create a BazelPackage object from a package directory. Reads some files from the package and returns
* a Promise for a BazelPackage instance.
* @param {string} repoRoot
* @param {string} dir
*/
static async fromDir(dir: string) {
static async fromDir(repoRoot, dir) {
const pkg = readPackageJson(Path.resolve(dir, 'package.json'));

let buildBazelContent;
Expand All @@ -36,23 +40,30 @@ export class BazelPackage {
throw new Error(`unable to read BUILD.bazel file in [${dir}]: ${error.message}`);
}

return new BazelPackage(normalizePath(Path.relative(REPO_ROOT, dir)), pkg, buildBazelContent);
return new BazelPackage(Path.relative(repoRoot, dir), pkg, buildBazelContent);
}

constructor(
/**
* Relative path from the root of the repository to the package directory
* @type {string}
*/
public readonly normalizedRepoRelativeDir: string,
normalizedRepoRelativeDir,
/**
* Parsed package.json file from the package
* @type {import('./types').ParsedPackageJson}
*/
public readonly pkg: ParsedPackageJson,
pkg,
/**
* Content of the BUILD.bazel file
* @type {string | undefined}
*/
private readonly buildBazelContent?: string
) {}
buildBazelContent = undefined
) {
this.normalizedRepoRelativeDir = normalizedRepoRelativeDir;
this.pkg = pkg;
this.buildBazelContent = buildBazelContent;
}

/**
* Returns true if the package includes a `:build` bazel rule
Expand Down Expand Up @@ -83,3 +94,7 @@ export class BazelPackage {
return `BazelPackage<${this.normalizedRepoRelativeDir}>`;
}
}

module.exports = {
BazelPackage,
};

0 comments on commit 8526a33

Please sign in to comment.