Skip to content

Commit

Permalink
Merge branch 'master' into 82710
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Nov 16, 2020
2 parents af81f5c + 253495b commit 55bdbbd
Show file tree
Hide file tree
Showing 36 changed files with 2,758 additions and 1,100 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
"rison-node": "1.0.2",
"rxjs": "^6.5.5",
"seedrandom": "^3.0.5",
"semver": "^5.7.0",
"semver": "^7.3.2",
"set-value": "^3.0.2",
"source-map-support": "^0.5.19",
"squel": "^5.13.0",
Expand Down Expand Up @@ -536,7 +536,7 @@
"@types/request": "^2.48.2",
"@types/seedrandom": ">=2.0.0 <4.0.0",
"@types/selenium-webdriver": "^4.0.9",
"@types/semver": "^5.5.0",
"@types/semver": "^7",
"@types/set-value": "^2.0.0",
"@types/sinon": "^7.0.13",
"@types/source-map-support": "^0.5.3",
Expand Down
3,507 changes: 2,498 additions & 1,009 deletions packages/kbn-pm/dist/index.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/plugins/dashboard/common/migrate_to_730_panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import { i18n } from '@kbn/i18n';
import semver from 'semver';
import semverSatisfies from 'semver/functions/satisfies';
import uuid from 'uuid';
import {
GridData,
Expand Down Expand Up @@ -60,23 +60,23 @@ function isPre61Panel(
}

function is61Panel(panel: unknown | RawSavedDashboardPanel610): panel is RawSavedDashboardPanel610 {
return semver.satisfies((panel as RawSavedDashboardPanel610).version, '6.1.x');
return semverSatisfies((panel as RawSavedDashboardPanel610).version, '6.1.x');
}

function is62Panel(panel: unknown | RawSavedDashboardPanel620): panel is RawSavedDashboardPanel620 {
return semver.satisfies((panel as RawSavedDashboardPanel620).version, '6.2.x');
return semverSatisfies((panel as RawSavedDashboardPanel620).version, '6.2.x');
}

function is63Panel(panel: unknown | RawSavedDashboardPanel630): panel is RawSavedDashboardPanel630 {
return semver.satisfies((panel as RawSavedDashboardPanel630).version, '6.3.x');
return semverSatisfies((panel as RawSavedDashboardPanel630).version, '6.3.x');
}

function is640To720Panel(
panel: unknown | RawSavedDashboardPanel640To720
): panel is RawSavedDashboardPanel640To720 {
return (
semver.satisfies((panel as RawSavedDashboardPanel630).version, '>6.3') &&
semver.satisfies((panel as RawSavedDashboardPanel630).version, '<7.3')
semverSatisfies((panel as RawSavedDashboardPanel630).version, '>6.3') &&
semverSatisfies((panel as RawSavedDashboardPanel630).version, '<7.3')
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import semver from 'semver';
import semverSatisfies from 'semver/functions/satisfies';
import { i18n } from '@kbn/i18n';
import { METRIC_TYPE } from '@kbn/analytics';

Expand Down Expand Up @@ -68,7 +68,7 @@ export function migrateAppState(
usageCollection.reportUiStats('DashboardPanelVersionInUrl', METRIC_TYPE.LOADED, `${version}`);
}

return semver.satisfies(version, '<7.3');
return semverSatisfies(version, '<7.3');
});

if (panelNeedsMigration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

import semver from 'semver';
import SemVer from 'semver/classes/semver';
import semverParse from 'semver/functions/parse';
import { TelemetrySavedObject } from './types';

interface GetTelemetryOptInConfig {
Expand Down Expand Up @@ -80,10 +81,10 @@ export const getTelemetryOptIn: GetTelemetryOptIn = ({
return savedOptIn;
};

function parseSemver(version: string): semver.SemVer | null {
function parseSemver(version: string): SemVer | null {
// semver functions both return nulls AND throw exceptions: "it depends!"
try {
return semver.parse(version);
return semverParse(version);
} catch (err) {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/vis_type_timeseries/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export const MAX_BUCKETS_SETTING = 'metrics:max_buckets';
export const INDEXES_SEPARATOR = ',';
20 changes: 19 additions & 1 deletion src/plugins/vis_type_timeseries/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import { EditorController } from './application';
// @ts-ignore
import { PANEL_TYPES } from '../common/panel_types';
import { VisEditor } from './application/components/vis_editor_lazy';
import { VIS_EVENT_TO_TRIGGER, VisGroups } from '../../visualizations/public';
import { VIS_EVENT_TO_TRIGGER, VisGroups, VisParams } from '../../visualizations/public';
import { getDataStart } from './services';
import { INDEXES_SEPARATOR } from '../common/constants';

export const metricsVisDefinition = {
name: 'metrics',
Expand Down Expand Up @@ -84,5 +86,21 @@ export const metricsVisDefinition = {
return [VIS_EVENT_TO_TRIGGER.applyFilter];
},
inspectorAdapters: {},
getUsedIndexPattern: async (params: VisParams) => {
const { indexPatterns } = getDataStart();
const indexes: string = params.index_pattern;

if (indexes) {
const cachedIndexes = await indexPatterns.getIdsWithTitle();
const ids = indexes
.split(INDEXES_SEPARATOR)
.map((title) => cachedIndexes.find((i) => i.title === title)?.id)
.filter((id) => id);

return Promise.all(ids.map((id) => indexPatterns.get(id!)));
}

return [];
},
responseHandler: 'none',
};
6 changes: 4 additions & 2 deletions src/plugins/vis_type_vega/public/vega_visualization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ describe('VegaVisualizations', () => {
mockHeight.mockRestore();
});

test('should show vegalite graph and update on resize (may fail in dev env)', async () => {
// SKIP: https://github.com/elastic/kibana/issues/83385
test.skip('should show vegalite graph and update on resize (may fail in dev env)', async () => {
let vegaVis;
try {
vegaVis = new VegaVisualization(domNode, jest.fn());
Expand Down Expand Up @@ -131,7 +132,8 @@ describe('VegaVisualizations', () => {
}
});

test('should show vega graph (may fail in dev env)', async () => {
// SKIP: https://github.com/elastic/kibana/issues/83385
test.skip('should show vega graph (may fail in dev env)', async () => {
let vegaVis;
try {
vegaVis = new VegaVisualization(domNode, jest.fn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory';
import { VISUALIZE_ENABLE_LABS_SETTING } from '../../common/constants';
import { SavedVisualizationsLoader } from '../saved_visualizations';
import { IndexPattern } from '../../../data/public';

export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDeps) => async (
vis: Vis,
Expand Down Expand Up @@ -69,8 +70,14 @@ export const createVisEmbeddableFromObject = (deps: VisualizeEmbeddableFactoryDe
return new DisabledLabEmbeddable(vis.title, input);
}

const indexPattern = vis.data.indexPattern;
const indexPatterns = indexPattern ? [indexPattern] : [];
let indexPatterns: IndexPattern[] = [];

if (vis.type.getUsedIndexPattern) {
indexPatterns = await vis.type.getUsedIndexPattern(vis.params);
} else if (vis.data.indexPattern) {
indexPatterns = [vis.data.indexPattern];
}

const editable = getCapabilities().visualize.save as boolean;

return new VisualizeEmbeddable(
Expand Down
1 change: 0 additions & 1 deletion src/plugins/visualizations/public/vis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export class Vis<TVisParams = VisParams> {
if (state.params || typeChanged) {
this.params = this.getParams(state.params);
}

if (state.data && state.data.searchSource) {
this.data.searchSource = await getSearch().searchSource.create(state.data.searchSource!);
this.data.indexPattern = this.data.searchSource.getField('index');
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/visualizations/public/vis_types/base_vis_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface CommonBaseVisTypeOptions<TVisParams>
| 'editorConfig'
| 'hidden'
| 'stage'
| 'getUsedIndexPattern'
| 'useCustomNoDataScreen'
| 'visConfig'
| 'group'
Expand Down Expand Up @@ -96,6 +97,7 @@ export class BaseVisType<TVisParams = VisParams> implements VisType<TVisParams>
public readonly responseHandler;
public readonly hierarchicalData;
public readonly setup;
public readonly getUsedIndexPattern;
public readonly useCustomNoDataScreen;
public readonly inspectorAdapters;
public readonly toExpressionAst;
Expand Down Expand Up @@ -126,6 +128,7 @@ export class BaseVisType<TVisParams = VisParams> implements VisType<TVisParams>
this.responseHandler = opts.responseHandler ?? 'none';
this.setup = opts.setup;
this.hierarchicalData = opts.hierarchicalData ?? false;
this.getUsedIndexPattern = opts.getUsedIndexPattern;
this.useCustomNoDataScreen = opts.useCustomNoDataScreen ?? false;
this.inspectorAdapters = opts.inspectorAdapters;
this.toExpressionAst = opts.toExpressionAst;
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/visualizations/public/vis_types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import { IconType } from '@elastic/eui';
import React from 'react';
import { Adapters } from 'src/plugins/inspector';
import { IndexPattern } from 'src/plugins/data/public';
import { VisEditorConstructor } from 'src/plugins/visualize/public';
import { ISchemas } from 'src/plugins/vis_default_editor/public';
import { TriggerContextMapping } from '../../../ui_actions/public';
import { Vis, VisToExpressionAst, VisualizationControllerConstructor } from '../types';
import { Vis, VisParams, VisToExpressionAst, VisualizationControllerConstructor } from '../types';

export interface VisTypeOptions {
showTimePicker: boolean;
Expand Down Expand Up @@ -64,6 +65,13 @@ export interface VisType<TVisParams = unknown> {
* If given, it will return the supported triggers for this vis.
*/
readonly getSupportedTriggers?: () => Array<keyof TriggerContextMapping>;

/**
* Some visualizations are created without SearchSource and may change the used indexes during the visualization configuration.
* Using this method we can rewrite the standard mechanism for getting used indexes
*/
readonly getUsedIndexPattern?: (visParams: VisParams) => IndexPattern[] | Promise<IndexPattern[]>;

readonly isAccessible?: boolean;
readonly requestHandler?: string | unknown;
readonly responseHandler?: string | unknown;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/enterprise_search/common/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SemVer } from 'semver';
import SemVer from 'semver/classes/semver';
import pkg from '../../../../package.json';

export const CURRENT_VERSION = new SemVer(pkg.version as string);
Expand Down
9 changes: 5 additions & 4 deletions x-pack/plugins/fleet/common/services/is_agent_upgradeable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import semver from 'semver';
import semverCoerce from 'semver/functions/coerce';
import semverLt from 'semver/functions/lt';
import { Agent } from '../types';

export function isAgentUpgradeable(agent: Agent, kibanaVersion: string) {
Expand All @@ -17,9 +18,9 @@ export function isAgentUpgradeable(agent: Agent, kibanaVersion: string) {
if (!agent.local_metadata.elastic.agent.upgradeable) return false;

// make sure versions are only the number before comparison
const agentVersionNumber = semver.coerce(agentVersion);
const agentVersionNumber = semverCoerce(agentVersion);
if (!agentVersionNumber) throw new Error('agent version is invalid');
const kibanaVersionNumber = semver.coerce(kibanaVersion);
const kibanaVersionNumber = semverCoerce(kibanaVersion);
if (!kibanaVersionNumber) throw new Error('kibana version is invalid');
return semver.lt(agentVersionNumber, kibanaVersionNumber);
return semverLt(agentVersionNumber, kibanaVersionNumber);
}
6 changes: 3 additions & 3 deletions x-pack/plugins/fleet/server/routes/agent/upgrade_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { RequestHandler } from 'src/core/server';
import { TypeOf } from '@kbn/config-schema';
import semver from 'semver';
import semverCoerce from 'semver/functions/coerce';
import {
AgentSOAttributes,
PostAgentUpgradeResponse,
Expand Down Expand Up @@ -122,9 +122,9 @@ export const postBulkAgentsUpgradeHandler: RequestHandler<

export const checkVersionIsSame = (version: string, kibanaVersion: string) => {
// get version number only in case "-SNAPSHOT" is in it
const kibanaVersionNumber = semver.coerce(kibanaVersion)?.version;
const kibanaVersionNumber = semverCoerce(kibanaVersion)?.version;
if (!kibanaVersionNumber) throw new Error(`kibanaVersion ${kibanaVersionNumber} is not valid`);
const versionToUpgradeNumber = semver.coerce(version)?.version;
const versionToUpgradeNumber = semverCoerce(version)?.version;
if (!versionToUpgradeNumber)
throw new Error(`version to upgrade ${versionToUpgradeNumber} is not valid`);
// temporarily only allow upgrading to the same version as the installed kibana version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import semver from 'semver';
import semverParse from 'semver/functions/parse';
import semverLt from 'semver/functions/lt';

import { timer, from, Observable, TimeoutError, of, EMPTY } from 'rxjs';
import { omit } from 'lodash';
import {
Expand Down Expand Up @@ -132,18 +134,14 @@ export async function createAgentActionFromPolicyAction(
policyAction: AgentPolicyAction
) {
// Transform the policy action for agent version <= 7.9.x for BWC
const agentVersion = semver.parse((agent.local_metadata?.elastic as any)?.agent?.version);
const agentVersion = semverParse((agent.local_metadata?.elastic as any)?.agent?.version);
const agentPolicyAction: AgentPolicyAction | AgentPolicyActionV7_9 =
agentVersion &&
semver.lt(
semverLt(
agentVersion,
// A prerelease tag is added here so that agent versions with prerelease tags can be compared
// correctly using `semvar`
'7.10.0-SNAPSHOT',
// `@types/semvar` is out of date with the version of `semvar` we use and doesn't have a
// corresponding release version we can update the typing to :( so, the typing error is
// suppressed here even though it is supported by `semvar`
// @ts-expect-error
{ includePrerelease: true }
)
? {
Expand Down
13 changes: 8 additions & 5 deletions x-pack/plugins/fleet/server/services/agents/enroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*/

import Boom from '@hapi/boom';
import semver from 'semver';
import semverParse from 'semver/functions/parse';
import semverDiff from 'semver/functions/diff';
import semverLte from 'semver/functions/lte';

import { SavedObjectsClientContract } from 'src/core/server';
import { AgentType, Agent, AgentSOAttributes } from '../../types';
import { savedObjectToAgent } from './saved_objects';
Expand Down Expand Up @@ -94,17 +97,17 @@ export function validateAgentVersion(
agentVersion: string,
kibanaVersion = appContextService.getKibanaVersion()
) {
const agentVersionParsed = semver.parse(agentVersion);
const agentVersionParsed = semverParse(agentVersion);
if (!agentVersionParsed) {
throw Boom.badRequest('Agent version not provided');
}

const kibanaVersionParsed = semver.parse(kibanaVersion);
const kibanaVersionParsed = semverParse(kibanaVersion);
if (!kibanaVersionParsed) {
throw Boom.badRequest('Kibana version is not set or provided');
}

const diff = semver.diff(agentVersion, kibanaVersion);
const diff = semverDiff(agentVersion, kibanaVersion);
switch (diff) {
// section 1) very close versions, only patch release differences - all combos should work
// Agent a.b.1 < Kibana a.b.2
Expand All @@ -130,7 +133,7 @@ export function validateAgentVersion(
// Agent 7.10.x > Kibana 7.9.x
// Agent 8.0.x > Kibana 7.9.x
default:
if (semver.lte(agentVersionParsed, kibanaVersionParsed)) return;
if (semverLte(agentVersionParsed, kibanaVersionParsed)) return;
else
throw Boom.badRequest(
`Agent version ${agentVersion} is not compatible with Kibana version ${kibanaVersion}`
Expand Down
7 changes: 4 additions & 3 deletions x-pack/plugins/fleet/server/services/epm/packages/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import semver from 'semver';
import semverGt from 'semver/functions/gt';
import semverLt from 'semver/functions/lt';
import Boom from '@hapi/boom';
import { UnwrapPromise } from '@kbn/utility-types';
import { SavedObject, SavedObjectsClientContract } from 'src/core/server';
Expand Down Expand Up @@ -185,7 +186,7 @@ export async function upgradePackage({
latestPkg,
pkgToUpgrade,
}: UpgradePackageParams): Promise<BulkInstallResponse> {
if (!installedPkg || semver.gt(latestPkg.version, installedPkg.attributes.version)) {
if (!installedPkg || semverGt(latestPkg.version, installedPkg.attributes.version)) {
const pkgkey = Registry.pkgToPkgKey({
name: latestPkg.name,
version: latestPkg.version,
Expand Down Expand Up @@ -255,7 +256,7 @@ async function installPackageFromRegistry({
// let the user install if using the force flag or needing to reinstall or install a previous version due to failed update
const installOutOfDateVersionOk =
installType === 'reinstall' || installType === 'reupdate' || installType === 'rollback';
if (semver.lt(pkgVersion, latestPackage.version) && !force && !installOutOfDateVersionOk) {
if (semverLt(pkgVersion, latestPackage.version) && !force && !installOutOfDateVersionOk) {
throw new PackageOutdatedError(`${pkgkey} is out-of-date and cannot be installed or updated`);
}

Expand Down
Loading

0 comments on commit 55bdbbd

Please sign in to comment.