Skip to content

Commit

Permalink
Merge branch 'master' into tech-debt/rename_examples
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jul 31, 2020
2 parents 8a2e21e + 5fa162c commit cbde433
Show file tree
Hide file tree
Showing 134 changed files with 625 additions and 485 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState, useCallback, useMemo } from 'react';
import React, { useState, useCallback } from 'react';
import { EuiPopover, EuiButtonEmpty, EuiContextMenuItem, EuiContextMenuPanel } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { useAlertPrefillContext } from '../../../alerting/use_alert_prefill';
import { AlertFlyout } from './alert_flyout';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { ManageAlertsContextMenuItem } from './manage_alerts_context_menu_item';

export const InventoryAlertDropdown = () => {
const [popoverOpen, setPopoverOpen] = useState(false);
const [flyoutVisible, setFlyoutVisible] = useState(false);
const kibana = useKibana();

const { inventoryPrefill } = useAlertPrefillContext();
const { nodeType, metric, filterQuery } = inventoryPrefill;
Expand All @@ -27,26 +26,12 @@ export const InventoryAlertDropdown = () => {
setPopoverOpen(true);
}, [setPopoverOpen]);

const menuItems = useMemo(() => {
return [
<EuiContextMenuItem icon="bell" key="createLink" onClick={() => setFlyoutVisible(true)}>
<FormattedMessage
id="xpack.infra.alerting.createAlertButton"
defaultMessage="Create alert"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="tableOfContents"
key="manageLink"
href={kibana.services?.application?.getUrlForApp(
'management/insightsAndAlerting/triggersActions/alerts'
)}
>
<FormattedMessage id="xpack.infra.alerting.manageAlerts" defaultMessage="Manage alerts" />
</EuiContextMenuItem>,
];
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [kibana.services]);
const menuItems = [
<EuiContextMenuItem icon="bell" key="createLink" onClick={() => setFlyoutVisible(true)}>
<FormattedMessage id="xpack.infra.alerting.createAlertButton" defaultMessage="Create alert" />
</EuiContextMenuItem>,
<ManageAlertsContextMenuItem />,
];

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiContextMenuItem } from '@elastic/eui';
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { useLinkProps } from '../../../hooks/use_link_props';

export const ManageAlertsContextMenuItem = () => {
const manageAlertsLinkProps = useLinkProps({
app: 'management',
pathname: '/insightsAndAlerting/triggersActions/alerts',
});
return (
<EuiContextMenuItem icon="tableOfContents" key="manageLink" {...manageAlertsLinkProps}>
<FormattedMessage id="xpack.infra.alerting.manageAlerts" defaultMessage="Manage alerts" />
</EuiContextMenuItem>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState, useCallback, useMemo } from 'react';
import React, { useState, useCallback } from 'react';
import { EuiPopover, EuiButtonEmpty, EuiContextMenuItem, EuiContextMenuPanel } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { useAlertPrefillContext } from '../../use_alert_prefill';
import { AlertFlyout } from './alert_flyout';
import { ManageAlertsContextMenuItem } from '../../inventory/components/manage_alerts_context_menu_item';

export const MetricsAlertDropdown = () => {
const [popoverOpen, setPopoverOpen] = useState(false);
const [flyoutVisible, setFlyoutVisible] = useState(false);
const kibana = useKibana();

const { metricThresholdPrefill } = useAlertPrefillContext();
const { groupBy, filterQuery, metrics } = metricThresholdPrefill;
Expand All @@ -27,26 +26,12 @@ export const MetricsAlertDropdown = () => {
setPopoverOpen(true);
}, [setPopoverOpen]);

const menuItems = useMemo(() => {
return [
<EuiContextMenuItem icon="bell" key="createLink" onClick={() => setFlyoutVisible(true)}>
<FormattedMessage
id="xpack.infra.alerting.createAlertButton"
defaultMessage="Create alert"
/>
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="tableOfContents"
key="manageLink"
href={kibana.services?.application?.getUrlForApp(
'management/insightsAndAlerting/triggersActions/alerts'
)}
>
<FormattedMessage id="xpack.infra.alerting.manageAlerts" defaultMessage="Manage alerts" />
</EuiContextMenuItem>,
];
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [kibana.services]);
const menuItems = [
<EuiContextMenuItem icon="bell" key="createLink" onClick={() => setFlyoutVisible(true)}>
<FormattedMessage id="xpack.infra.alerting.createAlertButton" defaultMessage="Create alert" />
</EuiContextMenuItem>,
<ManageAlertsContextMenuItem />,
];

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const Expressions: React.FC<Props> = (props) => {

const preFillAlertCriteria = useCallback(() => {
const md = alertsContext.metadata;
if (md && md.currentOptions?.metrics) {
if (md?.currentOptions?.metrics?.length) {
setAlertParams(
'criteria',
md.currentOptions.metrics.map((metric) => ({
Expand Down Expand Up @@ -249,13 +249,18 @@ export const Expressions: React.FC<Props> = (props) => {
if (!alertParams.sourceId) {
setAlertParams('sourceId', source?.id || 'default');
}
}, [alertsContext.metadata, defaultExpression, source]); // eslint-disable-line react-hooks/exhaustive-deps
}, [alertsContext.metadata, source]); // eslint-disable-line react-hooks/exhaustive-deps

const handleFieldSearchChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => onFilterChange(e.target.value),
[onFilterChange]
);

const groupByPreviewDisplayName = useMemo(() => {
if (Array.isArray(alertParams.groupBy)) return alertParams.groupBy.join(', ');
return alertParams.groupBy;
}, [alertParams.groupBy]);

return (
<>
<EuiSpacer size={'m'} />
Expand Down Expand Up @@ -400,7 +405,7 @@ export const Expressions: React.FC<Props> = (props) => {
showNoDataResults={alertParams.alertOnNoData}
validate={validateMetricThreshold}
fetch={alertsContext.http.fetch}
groupByDisplayName={alertParams.groupBy}
groupByDisplayName={groupByPreviewDisplayName}
/>
<EuiSpacer size={'m'} />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface Props {
derivedIndexPattern: IIndexPattern;
source: InfraSource | null;
filterQuery?: string;
groupBy?: string;
groupBy?: string | string[];
}

const tooltipProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useMetricsExplorerChartData = (
derivedIndexPattern: IIndexPattern,
source: InfraSource | null,
filterQuery?: string,
groupBy?: string
groupBy?: string | string[]
) => {
const { timeSize, timeUnit } = expression || { timeSize: 1, timeUnit: 'm' };
const options: MetricsExplorerOptions = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface ExpressionChartData {

export interface AlertParams {
criteria: MetricExpression[];
groupBy?: string;
groupBy?: string[];
filterQuery?: string;
sourceId?: string;
filterQueryText?: string;
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/ingest_manager/common/constants/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

export const PACKAGES_SAVED_OBJECT_TYPE = 'epm-packages';
export const INDEX_PATTERN_SAVED_OBJECT_TYPE = 'index-pattern';
export const DEFAULT_REGISTRY_URL = 'https://epr-snapshot.ea-web.elastic.dev';
export const INDEX_PATTERN_PLACEHOLDER_SUFFIX = '-index_pattern_placeholder';
1 change: 0 additions & 1 deletion x-pack/plugins/ingest_manager/server/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ export {
// Defaults
DEFAULT_AGENT_CONFIG,
DEFAULT_OUTPUT,
DEFAULT_REGISTRY_URL,
} from '../../common';
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_manager/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { schema, TypeOf } from '@kbn/config-schema';
import { PluginInitializerContext } from 'src/core/server';
import { IngestManagerPlugin } from './plugin';
export { AgentService, ESIndexPatternService } from './services';
export { AgentService, ESIndexPatternService, getRegistryUrl } from './services';
export {
IngestManagerSetupContract,
IngestManagerSetupDeps,
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/ingest_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export interface IngestManagerAppContext {
security?: SecurityPluginSetup;
config$?: Observable<IngestManagerConfigType>;
savedObjects: SavedObjectsServiceStart;
isProductionMode: boolean;
kibanaVersion: string;
kibanaBranch: string;
isProductionMode: PluginInitializerContext['env']['mode']['prod'];
kibanaVersion: PluginInitializerContext['env']['packageInfo']['version'];
kibanaBranch: PluginInitializerContext['env']['packageInfo']['branch'];
cloud?: CloudSetup;
logger?: Logger;
httpSetup?: HttpServiceSetup;
Expand Down Expand Up @@ -144,9 +144,9 @@ export class IngestManagerPlugin
private cloud: CloudSetup | undefined;
private logger: Logger | undefined;

private isProductionMode: boolean;
private kibanaVersion: string;
private kibanaBranch: string;
private isProductionMode: IngestManagerAppContext['isProductionMode'];
private kibanaVersion: IngestManagerAppContext['kibanaVersion'];
private kibanaBranch: IngestManagerAppContext['kibanaBranch'];
private httpSetup: HttpServiceSetup | undefined;
private encryptedSavedObjectsSetup: EncryptedSavedObjectsPluginSetup | undefined;

Expand Down
13 changes: 4 additions & 9 deletions x-pack/plugins/ingest_manager/server/services/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EncryptedSavedObjectsClient,
EncryptedSavedObjectsPluginSetup,
} from '../../../encrypted_saved_objects/server';
import packageJSON from '../../../../../package.json';
import { SecurityPluginSetup } from '../../../security/server';
import { IngestManagerConfigType } from '../../common';
import { ExternalCallback, ExternalCallbacksStorage, IngestManagerAppContext } from '../plugin';
Expand All @@ -22,9 +23,9 @@ class AppContextService {
private config$?: Observable<IngestManagerConfigType>;
private configSubject$?: BehaviorSubject<IngestManagerConfigType>;
private savedObjects: SavedObjectsServiceStart | undefined;
private isProductionMode: boolean = false;
private kibanaVersion: string | undefined;
private kibanaBranch: string | undefined;
private isProductionMode: IngestManagerAppContext['isProductionMode'] = false;
private kibanaVersion: IngestManagerAppContext['kibanaVersion'] = packageJSON.version;
private kibanaBranch: IngestManagerAppContext['kibanaBranch'] = packageJSON.branch;
private cloud?: CloudSetup;
private logger: Logger | undefined;
private httpSetup?: HttpServiceSetup;
Expand Down Expand Up @@ -121,16 +122,10 @@ class AppContextService {
}

public getKibanaVersion() {
if (!this.kibanaVersion) {
throw new Error('Kibana version is not set.');
}
return this.kibanaVersion;
}

public getKibanaBranch() {
if (!this.kibanaBranch) {
throw new Error('Kibana branch is not set.');
}
return this.kibanaBranch;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,43 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { DEFAULT_REGISTRY_URL } from '../../../constants';
import { appContextService, licenseService } from '../../';

// from https://github.com/elastic/package-registry#docker (maybe from OpenAPI one day)
// the unused variables cause a TS warning about unused values
// chose to comment them out vs @ts-ignore or @ts-expect-error on each line

const PRODUCTION_REGISTRY_URL_CDN = 'https://epr.elastic.co';
// const STAGING_REGISTRY_URL_CDN = 'https://epr-staging.elastic.co';
// const EXPERIMENTAL_REGISTRY_URL_CDN = 'https://epr-experimental.elastic.co/';
const SNAPSHOT_REGISTRY_URL_CDN = 'https://epr-snapshot.elastic.co';

// const PRODUCTION_REGISTRY_URL_NO_CDN = 'https://epr.ea-web.elastic.dev';
// const STAGING_REGISTRY_URL_NO_CDN = 'https://epr-staging.ea-web.elastic.dev';
// const EXPERIMENTAL_REGISTRY_URL_NO_CDN = 'https://epr-experimental.ea-web.elastic.dev/';
// const SNAPSHOT_REGISTRY_URL_NO_CDN = 'https://epr-snapshot.ea-web.elastic.dev';

const getDefaultRegistryUrl = (): string => {
const branch = appContextService.getKibanaBranch();
if (branch === 'master') {
return SNAPSHOT_REGISTRY_URL_CDN;
} else {
return PRODUCTION_REGISTRY_URL_CDN;
}
};

export const getRegistryUrl = (): string => {
const license = licenseService.getLicenseInformation();
const customUrl = appContextService.getConfig()?.registryUrl;
const isGoldPlus = license?.isAvailable && license?.isActive && license?.hasAtLeast('gold');

if (
customUrl &&
license &&
license.isAvailable &&
license.hasAtLeast('gold') &&
license.isActive
) {
if (customUrl && isGoldPlus) {
return customUrl;
}

if (customUrl) {
appContextService.getLogger().warn('Gold license is required to use a custom registry url.');
}

return DEFAULT_REGISTRY_URL;
return getDefaultRegistryUrl();
};
2 changes: 2 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { AgentStatus, Agent } from '../types';
import * as settingsService from './settings';
export { ESIndexPatternSavedObjectService } from './es_index_pattern';

export { getRegistryUrl } from './epm/registry/registry_url';

/**
* Service to return the index pattern of EPM packages
*/
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lists/common/schemas/common/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';

import { exactCheck, foldLeftRight, getPaths } from '../../siem_common_deps';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';

import {
EsDataTypeGeoPoint,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lists/common/schemas/common/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import * as t from 'io-ts';

import { DefaultNamespace } from '../types/default_namespace';
import { DefaultStringArray, NonEmptyString } from '../../siem_common_deps';
import { DefaultStringArray, NonEmptyString } from '../../shared_imports';

export const name = t.string;
export type Name = t.TypeOf<typeof name>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';

import { exactCheck, foldLeftRight, getPaths } from '../../siem_common_deps';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';

import { SearchEsListItemSchema, searchEsListItemSchema } from './search_es_list_item_schema';
import { getSearchEsListItemMock } from './search_es_list_item_schema.mock';
Expand All @@ -22,7 +22,7 @@ describe('search_es_list_item_schema', () => {
expect(message.schema).toEqual(payload);
});

test('it should not validate with a madeup value', () => {
test('it should FAIL validation when a madeup value', () => {
const payload: SearchEsListItemSchema & { madeupValue: string } = {
...getSearchEsListItemMock(),
madeupValue: 'madeupvalue',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';

import { exactCheck, foldLeftRight, getPaths } from '../../siem_common_deps';
import { exactCheck, foldLeftRight, getPaths } from '../../shared_imports';

import { SearchEsListSchema, searchEsListSchema } from './search_es_list_schema';
import { getSearchEsListMock } from './search_es_list_schema.mock';
Expand All @@ -22,7 +22,7 @@ describe('search_es_list_schema', () => {
expect(message.schema).toEqual(payload);
});

test('it should not validate with a madeup value', () => {
test('it should FAIL validation when a madeup value', () => {
const payload: SearchEsListSchema & { madeupValue: string } = {
...getSearchEsListMock(),
madeupValue: 'madeupvalue',
Expand Down
Loading

0 comments on commit cbde433

Please sign in to comment.