Skip to content

Commit

Permalink
Merge branch 'main' into ml-apm-correlations-fix-load-balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Nov 3, 2021
2 parents c0b6b3e + 6c4373f commit 2b755d3
Show file tree
Hide file tree
Showing 43 changed files with 478 additions and 228 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
/src/core/ @elastic/kibana-core
/src/plugins/saved_objects_tagging_oss @elastic/kibana-core
/config/kibana.yml @elastic/kibana-core
/typings/ @elastic/kibana-core
/x-pack/plugins/banners/ @elastic/kibana-core
/x-pack/plugins/features/ @elastic/kibana-core
/x-pack/plugins/licensing/ @elastic/kibana-core
Expand Down
2 changes: 1 addition & 1 deletion docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ The default values for the session timeout `xpack.security.session.{lifespan|idl
*Impact* +
Use the following default values:
* `xpack.security.session.idleTimeout: 1h`
* `xpack.security.session.idleTimeout: 8h`
* `xpack.security.session.lifespan: 30d`
====

Expand Down
8 changes: 4 additions & 4 deletions test/functional/apps/discover/_discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('discover test', function describeIndexTests() {
before(async function () {
log.debug('load kibana index with default index pattern');

await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json');

await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover');
// and load a set of makelogs data
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional');
await kibanaServer.uiSettings.replace(defaultSettings);
await PageObjects.common.navigateToApp('discover');
await PageObjects.timePicker.setDefaultAbsoluteRange();
});

after(async () => {
await kibanaServer.savedObjects.clean({ types: ['search', 'index-pattern'] });
});
describe('query', function () {
const queryName1 = 'Query # 1';

Expand Down
41 changes: 39 additions & 2 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import expect from '@kbn/expect';
// @ts-ignore
import fetch from 'node-fetch';
import { getUrl } from '@kbn/test';
import moment from 'moment';
import { FtrService } from '../ftr_provider_context';

interface NavigateProps {
Expand Down Expand Up @@ -502,11 +503,47 @@ export class CommonPageObject extends FtrService {
}
}

async setTime(time: { from: string; to: string }) {
await this.kibanaServer.uiSettings.replace({ 'timepicker:timeDefaults': JSON.stringify(time) });
/**
* Due to a warning thrown, documented at:
* https://github.com/elastic/kibana/pull/114997#issuecomment-950823874
* this fn formats time in a format specified, or defaulted
* to the same format in
* [getTimeDurationInHours()](https://github.com/elastic/kibana/blob/main/test/functional/page_objects/time_picker.ts#L256)
* @param time
* @param fmt
*/
formatTime(time: TimeStrings, fmt: string = 'MMM D, YYYY @ HH:mm:ss.SSS') {
return Object.keys(time)
.map((x) => moment(time[x], [fmt]).format())
.reduce(
(acc, curr, idx) => {
if (idx === 0) acc.from = curr;
acc.to = curr;
return acc;
},
{ from: '', to: '' }
);
}

/**
* Previously, many tests were using the time picker.
* To speed things up, we are now setting time here.
* The formatting fn is called here, such that the tests
* that were using the time picker can use the same time
* parameters as before, but they are auto-formatted.
* @param time
*/
async setTime(time: TimeStrings) {
await this.kibanaServer.uiSettings.replace({
'timepicker:timeDefaults': JSON.stringify(this.formatTime(time)),
});
}

async unsetTime() {
await this.kibanaServer.uiSettings.unset('timepicker:timeDefaults');
}
}
export interface TimeStrings extends Record<string, any> {
from: string;
to: string;
}
9 changes: 6 additions & 3 deletions x-pack/examples/reporting_example/public/containers/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ import { BrowserRouter as Router, useHistory } from 'react-router-dom';
import * as Rx from 'rxjs';
import { takeWhile } from 'rxjs/operators';
import { ScreenshotModePluginSetup } from 'src/plugins/screenshot_mode/public';
import type {
JobAppParamsPDF,
JobParamsPDFV2,
JobParamsPNGV2,
} from '../../../../plugins/reporting/public';
import { constants, ReportingStart } from '../../../../plugins/reporting/public';
import type { JobParamsPDFV2 } from '../../../../plugins/reporting/server/export_types/printable_pdf_v2/types';
import type { JobParamsPNGV2 } from '../../../../plugins/reporting/server/export_types/png_v2/types';

import { REPORTING_EXAMPLE_LOCATOR_ID } from '../../common';

Expand Down Expand Up @@ -81,7 +84,7 @@ export const Main = ({ basename, reporting, screenshotMode }: ReportingExampleAp
});
});

const getPDFJobParamsDefault = () => {
const getPDFJobParamsDefault = (): JobAppParamsPDF => {
return {
layout: {
id: constants.LAYOUT_TYPES.PRESERVE_LAYOUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getApmSettings({
'xpack.apm.fleet_integration.settings.apm.hostDescription',
{
defaultMessage:
'Choose a name and description to help identify how this integration will be used.',
'Host defines the host and port the server is listening on. URL is the unchangeable, publicly reachable server URL for deployments on Elastic Cloud or ECK.',
}
),

Expand Down Expand Up @@ -164,10 +164,7 @@ export function getApmSettings({
),
rowDescription: i18n.translate(
'xpack.apm.fleet_integration.settings.apm.responseHeadersDescription',
{
defaultMessage:
'Set limits on request headers sizes and timing configurations.',
}
{ defaultMessage: 'Custom HTTP headers added to HTTP responses' }
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import Style from 'style-it';
// @ts-expect-error
import { WorkpadPage } from '../workpad_page';
import { Fullscreen } from '../fullscreen';
import { HEADER_BANNER_HEIGHT, WORKPAD_CANVAS_BUFFER } from '../../../common/lib/constants';
import {
HEADER_BANNER_HEIGHT,
WORKPAD_CANVAS_BUFFER,
DEFAULT_WORKPAD_CSS,
} from '../../../common/lib/constants';
import { CommitFn, CanvasPage } from '../../../types';
import { WorkpadShortcuts } from './workpad_shortcuts.component';

Expand Down Expand Up @@ -122,7 +126,7 @@ export const Workpad: FC<Props> = ({

// NOTE: the data-shared-* attributes here are used for reporting
return Style.it(
workpadCss,
workpadCss || DEFAULT_WORKPAD_CSS,
<div
className={`canvasWorkpad ${isFullscreenProp ? 'fullscreen' : ''}`}
style={fsStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { RedirectOptions } from 'src/plugins/share/public';
import { CANVAS_APP_LOCATOR } from '../../../../common/locator';
import { CanvasAppLocatorParams } from '../../../../common/locator';
import { CanvasWorkpad } from '../../../../types';
import { JobAppParamsPDFV2 } from '../../../../../reporting/public';

export interface CanvasWorkpadSharingData {
workpad: Pick<CanvasWorkpad, 'id' | 'name' | 'height' | 'width'>;
Expand All @@ -18,7 +19,7 @@ export interface CanvasWorkpadSharingData {
export function getPdfJobParams(
{ workpad: { id, name: title, width, height }, pageCount }: CanvasWorkpadSharingData,
version: string
) {
): JobAppParamsPDFV2 {
// The viewport in Reporting by specifying the dimensions. In order for things to work,
// we need a viewport that will include all of the pages in the workpad. The viewport
// also needs to include any offset values from the 0,0 position, otherwise the cropped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,8 @@ export const AddSourceLogic = kea<MakeLogicType<AddSourceValues, AddSourceAction
navigateToUrl(getSourcesPath(SOURCES_PATH, isOrganization));
}
} catch (e) {
flashAPIErrors(e);
navigateToUrl(getSourcesPath(SOURCES_PATH, isOrganization));
flashAPIErrors(e);
}
},
createContentSource: async ({ serviceType, successCallback, errorCallback }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ import {

import styled from 'styled-components';

import type {
AgentPolicy,
PackageInfo,
PackagePolicy,
NewPackagePolicy,
RegistryVarsEntry,
} from '../../../types';
import type { AgentPolicy, PackageInfo, NewPackagePolicy, RegistryVarsEntry } from '../../../types';
import { packageToPackagePolicy, pkgKeyFromPackageInfo } from '../../../services';
import { Loading } from '../../../components';
import { useStartServices } from '../../../hooks';
import { useStartServices, useGetPackagePolicies } from '../../../hooks';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../../constants';
import { SO_SEARCH_LIMIT } from '../../../../../../common';

import { isAdvancedVar } from './services';
import type { PackagePolicyValidationResults } from './services';
Expand Down Expand Up @@ -65,6 +61,14 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
submitAttempted,
}) => {
const { docLinks } = useStartServices();

// Fetch all packagePolicies having the package name
const { data: packagePolicyData, isLoading: isLoadingPackagePolicies } = useGetPackagePolicies({
perPage: SO_SEARCH_LIMIT,
page: 1,
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:${packageInfo.name}`,
});

// Form show/hide states
const [isShowingAdvanced, setIsShowingAdvanced] = useState<boolean>(false);

Expand All @@ -84,33 +88,37 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{

// Update package policy's package and agent policy info
useEffect(() => {
if (isLoadingPackagePolicies) {
return;
}
const pkg = packagePolicy.package;
const currentPkgKey = pkg ? pkgKeyFromPackageInfo(pkg) : '';
const pkgKey = pkgKeyFromPackageInfo(packageInfo);

// If package has changed, create shell package policy with input&stream values based on package info
if (currentPkgKey !== pkgKey) {
// Existing package policies on the agent policy using the package name, retrieve highest number appended to package policy name
// Retrieve highest number appended to package policy name and increment it by one
const pkgPoliciesNamePattern = new RegExp(`${packageInfo.name}-(\\d+)`);
const pkgPoliciesWithMatchingNames = agentPolicy
? (agentPolicy.package_policies as PackagePolicy[])
const pkgPoliciesWithMatchingNames = packagePolicyData?.items
? packagePolicyData.items
.filter((ds) => Boolean(ds.name.match(pkgPoliciesNamePattern)))
.map((ds) => parseInt(ds.name.match(pkgPoliciesNamePattern)![1], 10))
.sort((a, b) => a - b)
: [];

const incrementedName = `${packageInfo.name}-${
pkgPoliciesWithMatchingNames.length
? pkgPoliciesWithMatchingNames[pkgPoliciesWithMatchingNames.length - 1] + 1
: 1
}`;

updatePackagePolicy(
packageToPackagePolicy(
packageInfo,
agentPolicy?.id || '',
packagePolicy.output_id,
packagePolicy.namespace,
packagePolicy.name ||
`${packageInfo.name}-${
pkgPoliciesWithMatchingNames.length
? pkgPoliciesWithMatchingNames[pkgPoliciesWithMatchingNames.length - 1] + 1
: 1
}`,
packagePolicy.name || incrementedName,
packagePolicy.description,
integrationToEnable
)
Expand All @@ -124,7 +132,15 @@ export const StepDefinePackagePolicy: React.FunctionComponent<{
namespace: agentPolicy.namespace,
});
}
}, [packagePolicy, agentPolicy, packageInfo, updatePackagePolicy, integrationToEnable]);
}, [
packagePolicy,
agentPolicy,
packageInfo,
updatePackagePolicy,
integrationToEnable,
packagePolicyData,
isLoadingPackagePolicies,
]);

return validationResults ? (
<FormGroupResponsiveFields
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,16 @@ class AgentPolicyService {
options
);

// Copy all package policies
// Copy all package policies and append (copy) to their names
if (baseAgentPolicy.package_policies.length) {
const newPackagePolicies = (baseAgentPolicy.package_policies as PackagePolicy[]).map(
(packagePolicy: PackagePolicy) => {
const { id: packagePolicyId, version, ...newPackagePolicy } = packagePolicy;
return newPackagePolicy;
const updatedPackagePolicy = {
...newPackagePolicy,
name: `${packagePolicy.name} (copy)`,
};
return updatedPackagePolicy;
}
);
await packagePolicyService.bulkCreate(
Expand Down
51 changes: 18 additions & 33 deletions x-pack/plugins/fleet/server/services/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import type {
} from '../../common';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../constants';
import {
HostedAgentPolicyRestrictionRelatedError,
IngestManagerError,
ingestErrorToResponseOptions,
PackagePolicyIneligibleForUpgradeError,
Expand Down Expand Up @@ -99,24 +98,14 @@ class PackagePolicyService {
skipEnsureInstalled?: boolean;
}
): Promise<PackagePolicy> {
// Check that its agent policy does not have a package policy with the same name
const parentAgentPolicy = await agentPolicyService.get(soClient, packagePolicy.policy_id);
if (!parentAgentPolicy) {
throw new Error('Agent policy not found');
}
if (parentAgentPolicy.is_managed && !options?.force) {
throw new HostedAgentPolicyRestrictionRelatedError(
`Cannot add integrations to hosted agent policy ${parentAgentPolicy.id}`
);
}
if (
(parentAgentPolicy.package_policies as PackagePolicy[]).find(
(siblingPackagePolicy) => siblingPackagePolicy.name === packagePolicy.name
)
) {
throw new IngestManagerError(
'There is already a package with the same name on this agent policy'
);
const existingPoliciesWithName = await this.list(soClient, {
perPage: 1,
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name: "${packagePolicy.name}"`,
});

// Check that the name does not exist already
if (existingPoliciesWithName.items.length > 0) {
throw new IngestManagerError('There is already a package with the same name');
}
let elasticsearch: PackagePolicy['elasticsearch'];
// Add ids to stream
Expand Down Expand Up @@ -320,12 +309,12 @@ class PackagePolicyService {
});

return {
items: packagePolicies.saved_objects.map((packagePolicySO) => ({
items: packagePolicies?.saved_objects.map((packagePolicySO) => ({
id: packagePolicySO.id,
version: packagePolicySO.version,
...packagePolicySO.attributes,
})),
total: packagePolicies.total,
total: packagePolicies?.total,
page,
perPage,
};
Expand Down Expand Up @@ -369,19 +358,15 @@ class PackagePolicyService {
if (!oldPackagePolicy) {
throw new Error('Package policy not found');
}
// Check that the name does not exist already but exclude the current package policy
const existingPoliciesWithName = await this.list(soClient, {
perPage: 1,
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name: "${packagePolicy.name}"`,
});
const filtered = (existingPoliciesWithName?.items || []).filter((p) => p.id !== id);

// Check that its agent policy does not have a package policy with the same name
const parentAgentPolicy = await agentPolicyService.get(soClient, packagePolicy.policy_id);
if (!parentAgentPolicy) {
throw new Error('Agent policy not found');
}
if (
(parentAgentPolicy.package_policies as PackagePolicy[]).find(
(siblingPackagePolicy) =>
siblingPackagePolicy.id !== id && siblingPackagePolicy.name === packagePolicy.name
)
) {
throw new Error('There is already a package with the same name on this agent policy');
if (filtered.length > 0) {
throw new IngestManagerError('There is already a package with the same name');
}

let inputs = restOfPackagePolicy.inputs.map((input) =>
Expand Down
Loading

0 comments on commit 2b755d3

Please sign in to comment.