Skip to content

Commit

Permalink
Merge branch 'main' into removing-use-of-ignore_throttled
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic authored Nov 14, 2024
2 parents a00cdc6 + 1862b59 commit 98c9646
Show file tree
Hide file tree
Showing 32 changed files with 495 additions and 153 deletions.
85 changes: 84 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,90 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai
/.eslintrc.js @elastic/kibana-operations
/.eslintignore @elastic/kibana-operations

# Appex QA
# QA - Appex QA
/test/server_integration/services/index.js @elastic/appex-qa
/x-pack/test/stack_functional_integration/configs/config.stack_functional_integration_base.js @elastic/appex-qa
/x-pack/test/stack_functional_integration/configs/consume_state.js @elastic/appex-qa
/x-pack/test/functional/services/remote_es/remote_es_archiver.ts @elastic/appex-qa
/test/functional/services/remote_es/remote_es_archiver.ts @elastic/appex-qa
/x-pack/test/kibana.jsonc @elastic/appex-qa
/x-pack/test/functional_with_es_ssl/ftr_provider_context.d.ts @elastic/appex-qa
/x-pack/test/stack_functional_integration/apps @elastic/appex-qa
/x-pack/test/plugin_functional/config.ts @elastic/appex-qa
/x-pack/test/plugin_functional/ftr_provider_context.d.ts @elastic/appex-qa
/x-pack/test/plugin_functional/page_objects.ts @elastic/appex-qa
/x-pack/test/upgrade/services/index.ts @elastic/appex-qa
/x-pack/test/upgrade/ftr_provider_context.d.ts @elastic/appex-qa
/x-pack/test/upgrade/config.ts @elastic/appex-qa
/x-pack/test/functional_basic/ftr_provider_context.d.ts @elastic/appex-qa
/x-pack/test/functional/services/remote_es/remote_es.ts @elastic/appex-qa
/x-pack/test/functional/services/random.js @elastic/appex-qa
/x-pack/test/functional/services/index.ts @elastic/appex-qa
/x-pack/test/functional/page_objects/index.ts @elastic/appex-qa
/x-pack/test/functional/ftr_provider_context.ts @elastic/appex-qa
/x-pack/test/functional/README.md @elastic/appex-qa
/x-pack/test/examples/config.ts @elastic/appex-qa
/x-pack/test/common/services/index.ts @elastic/appex-qa
/x-pack/test/common/services/bsearch_secure.ts @elastic/appex-qa
/x-pack/test/common/ftr_provider_context.ts @elastic/appex-qa
/x-pack/test/api_integration_basic/ftr_provider_context.d.ts @elastic/appex-qa
/x-pack/test/api_integration_basic/config.ts @elastic/appex-qa
/x-pack/test/api_integration_basic/apis/index.ts @elastic/appex-qa
/x-pack/test/api_integration/services/index.ts @elastic/appex-qa
/x-pack/test/api_integration/services/es_supertest_without_auth.js @elastic/appex-qa
/x-pack/test/api_integration/config.ts @elastic/appex-qa
/x-pack/test/api_integration/apis/kibana/config.ts @elastic/appex-qa
/x-pack/test/tsconfig.json @elastic/appex-qa
/x-pack/test/load @elastic/appex-qa
/test/tsconfig.json @elastic/appex-qa
/test/plugin_functional/services/index.ts @elastic/appex-qa
/test/plugin_functional/README.md @elastic/appex-qa
/test/plugin_functional/config.ts @elastic/appex-qa
/test/kibana.jsonc @elastic/appex-qa
/test/harden @elastic/appex-qa
/test/functional/services/supertest.ts @elastic/appex-qa
/test/functional/services/remote_es/remote_es.ts @elastic/appex-qa
/test/functional/services/query_bar.ts @elastic/appex-qa
/test/functional/services/menu_toggle.ts @elastic/appex-qa
/test/functional/services/listing_table.ts @elastic/appex-qa
/test/common/fixtures/plugins/coverage @elastic/appex-qa
/test/functional/services/index.ts @elastic/appex-qa
/test/functional/services/global_nav.ts @elastic/appex-qa
/test/functional/services/flyout.ts @elastic/appex-qa
/test/functional/services/filter_bar.ts @elastic/appex-qa
/test/functional/services/field_editor.ts @elastic/appex-qa
/test/functional/services/embedding.ts @elastic/appex-qa
/test/functional/services/doc_table.ts @elastic/appex-qa
/test/functional/services/data_grid.ts @elastic/appex-qa
/test/functional/services/combo_box.ts @elastic/appex-qa
/test/functional/page_objects/unified_field_list.ts @elastic/appex-qa
/test/functional/page_objects/time_picker.ts @elastic/appex-qa
/test/functional/page_objects/index.ts @elastic/appex-qa
/test/functional/page_objects/header_page.ts @elastic/appex-qa
/test/functional/page_objects/error_page.ts @elastic/appex-qa
/test/functional/page_objects/common_page.ts @elastic/appex-qa
/test/functional/jest.config.js @elastic/appex-qa
/test/functional/ftr_provider_context.ts @elastic/appex-qa
/test/functional/fixtures/es_archiver/README.md @elastic/appex-qa
/test/functional/firefox/config.base.ts @elastic/appex-qa
/test/functional/config.* @elastic/appex-qa
/test/functional/README.md @elastic/appex-qa
/test/examples/config.js @elastic/appex-qa
/test/examples/README.md @elastic/appex-qa
/test/common/services/index.ts @elastic/appex-qa
/test/common/fixtures/plugins/coverage/*.ts @elastic/appex-qa
/test/common/config.js @elastic/appex-qa
/test/api_integration/services/index.ts @elastic/appex-qa
/test/api_integration/jest.config.js @elastic/appex-qa
/test/api_integration/ftr_provider_context.d.ts @elastic/appex-qa
/test/api_integration/config.js @elastic/appex-qa
/test/api_integration/apis/index.ts @elastic/appex-qa
/test/accessibility/services/index.ts @elastic/appex-qa
/test/accessibility/services/a11y @elastic/appex-qa
/test/accessibility/page_objects.ts @elastic/appex-qa
/test/accessibility/ftr_provider_context.ts @elastic/appex-qa
/test/accessibility/config.ts @elastic/appex-qa
/test/accessibility/apps/index.ts @elastic/appex-qa
/x-pack/test/scalability @elastic/appex-qa
/src/dev/performance @elastic/appex-qa
/x-pack/test/functional/config.*.* @elastic/appex-qa
Expand Down
9 changes: 9 additions & 0 deletions packages/kbn-expect/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,11 @@ function i (obj, showHidden, depth) {
return stylize('null', 'null');
}

// format sets like arrays
if (value instanceof Set) {
value = Array.from(value)
}

if (isDOMElement(value)) {
return getOuterHTML(value);
}
Expand Down Expand Up @@ -930,6 +935,10 @@ expect.eql = function eql(actual, expected) {
// to determine equivalence.
} else if (isRegExp(actual) && isRegExp(expected)) {
return regExpEquiv(actual, expected);
// If both are Sets, they should be treated equal if they have the same
// entries, independent of the ordering
} else if (actual instanceof Set && expected instanceof Set) {
return actual.size === expected.size && actual.difference(expected).size === 0;
// 7.4. For all other Object pairs, including Array objects, equivalence is
// determined by having the same number of owned properties (as verified
// with Object.prototype.hasOwnProperty.call), the same set of keys
Expand Down
47 changes: 47 additions & 0 deletions packages/kbn-expect/expect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

// importing this package's expect as `kbnExpect` to not conflict with Jest's expect
import kbnExpect from './expect';

it('asserts that sets with same entries but different ordering are equal', async () => {
const setA = new Set(['a', 'b', 'c']);
const setB = new Set(['c', 'b', 'a']);

expect(() => {
kbnExpect(setA).to.eql(setB);
}).not.toThrow();
expect(() => {
kbnExpect(setB).to.eql(setA);
}).not.toThrow();
});

it('asserts that sets with same size but different entries are not equal', async () => {
const setA = new Set(['a', 'b', 'c']);
const setB = new Set(['x', 'y', 'z']);

expect(() => {
kbnExpect(setA).to.eql(setB);
}).toThrow();
expect(() => {
kbnExpect(setB).to.eql(setA);
}).toThrow();
});

it('asserts that sets with different size but overlapping items are not equal', async () => {
const setA = new Set(['a', 'b', 'c']);
const setB = new Set(['a', 'b']);

expect(() => {
kbnExpect(setA).to.eql(setB);
}).toThrow();
expect(() => {
kbnExpect(setB).to.eql(setA);
}).toThrow();
});
14 changes: 14 additions & 0 deletions packages/kbn-expect/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-expect'],
};
8 changes: 6 additions & 2 deletions packages/kbn-expect/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types"
"outDir": "target/types",
"types": [
"jest",
],
},
"include": [
"expect.d.ts"
"expect.d.ts",
"**/*.ts"
],
"exclude": [
"target/**/*",
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/field_formats/common/converters/url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ describe('UrlFormat', () => {
);
});

test('outputs a mailto: link when URL starts with mailto:', () => {
const url = new UrlFormat({});

expect(url.convert('mailto:test@example.com', HTML_CONTEXT_TYPE)).toBe(
'<a href="mailto:test@example.com" target="_blank" rel="noopener noreferrer">mailto:test@example.com</a>'
);
});

test('outputs an <audio> if type === "audio"', () => {
const url = new UrlFormat({ type: 'audio' });

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/field_formats/common/converters/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '../types';

const templateMatchRE = /{{([\s\S]+?)}}/g;
const allowedUrlSchemes = ['http://', 'https://'];
const allowedUrlSchemes = ['http://', 'https://', 'mailto:'];

const URL_TYPES = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const createClientMock = (): jest.Mocked<AgentClient> => ({
getAgentStatusForAgentPolicy: jest.fn(),
listAgents: jest.fn(),
getLatestAgentAvailableVersion: jest.fn(),
getLatestAgentAvailableBaseVersion: jest.fn(),
getLatestAgentAvailableDockerImageVersion: jest.fn(),
getByIds: jest.fn(async (..._) => []),
});

Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/fleet/server/services/agents/agent_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,28 @@ function expectApisToCallServicesSuccessfully(
);
expect(mockgetLatestAvailableAgentVersion).toHaveBeenCalledTimes(1);
});

test('client.getLatestAgentAvailableBaseVersion strips away IAR suffix', async () => {
mockgetLatestAvailableAgentVersion.mockResolvedValue('1.2.3+build12345678987654321');
await expect(agentClient.getLatestAgentAvailableBaseVersion()).resolves.toEqual('1.2.3');
});

test('client.getLatestAgentAvailableBaseVersion does not break on usual version numbers', async () => {
mockgetLatestAvailableAgentVersion.mockResolvedValue('8.17.0');
await expect(agentClient.getLatestAgentAvailableBaseVersion()).resolves.toEqual('8.17.0');
});

test('client.getLatestAgentAvailableDockerImageVersion transforms IAR suffix', async () => {
mockgetLatestAvailableAgentVersion.mockResolvedValue('1.2.3+build12345678987654321');
await expect(agentClient.getLatestAgentAvailableDockerImageVersion()).resolves.toEqual(
'1.2.3.build12345678987654321'
);
});

test('client.getLatestAgentAvailableDockerImageVersion does not break on usual version numbers', async () => {
mockgetLatestAvailableAgentVersion.mockResolvedValue('8.17.0');
await expect(agentClient.getLatestAgentAvailableDockerImageVersion()).resolves.toEqual(
'8.17.0'
);
});
}
18 changes: 18 additions & 0 deletions x-pack/plugins/fleet/server/services/agents/agent_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ export interface AgentClient {
* Return the latest agent available version
*/
getLatestAgentAvailableVersion(includeCurrentVersion?: boolean): Promise<string>;
/**
* Return the latest agent available version, not taking into account IAR versions
*/
getLatestAgentAvailableBaseVersion(includeCurrentVersion?: boolean): Promise<string>;
/**
* Return the latest agent available version formatted for the docker image
*/
getLatestAgentAvailableDockerImageVersion(includeCurrentVersion?: boolean): Promise<string>;
}

/**
Expand Down Expand Up @@ -163,6 +171,16 @@ class AgentClientImpl implements AgentClient {
);
}

public async getLatestAgentAvailableBaseVersion(includeCurrentVersion?: boolean) {
const fullVersion = await this.getLatestAgentAvailableVersion(includeCurrentVersion);
return fullVersion.split('+')[0];
}

public async getLatestAgentAvailableDockerImageVersion(includeCurrentVersion?: boolean) {
const fullVersion = await this.getLatestAgentAvailableVersion(includeCurrentVersion);
return fullVersion.replace('+', '.');
}

public async getLatestAgentAvailableVersion(includeCurrentVersion?: boolean) {
await this.#runPreflight();
return getLatestAvailableAgentVersion({ includeCurrentVersion });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export interface ElasticAgentVersionInfo {
agentVersion: string;
agentBaseVersion: string;
agentDockerImageVersion: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getAutoDetectCommand(
--kibana-url=${options.kibanaUrl}
--install-key=${options.installApiKey}
--ingest-key=${options.ingestApiKey}
--ea-version=${options.elasticAgentVersion}
--ea-version=${options.elasticAgentVersionInfo.agentVersion}
`;
}
function oneLine(parts: TemplateStringsArray, ...args: string[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export function InstallElasticAgent() {
apiKeyEncoded,
apiEndpoint: setup?.apiEndpoint,
scriptDownloadUrl: setup?.scriptDownloadUrl,
elasticAgentVersion: setup?.elasticAgentVersion,
elasticAgentVersion: setup?.elasticAgentVersionInfo.agentVersion,
autoDownloadConfig,
onboardingId,
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* 2.0.
*/

import { ElasticAgentVersionInfo } from '../../../../common/types';

interface Params {
encodedApiKey: string;
onboardingId: string;
elasticsearchUrl: string;
elasticAgentVersion: string;
elasticAgentVersionInfo: ElasticAgentVersionInfo;
}

const KUSTOMIZE_TEMPLATE_URL =
Expand All @@ -19,16 +21,16 @@ export function buildKubectlCommand({
encodedApiKey,
onboardingId,
elasticsearchUrl,
elasticAgentVersion,
elasticAgentVersionInfo,
}: Params) {
const escapedElasticsearchUrl = elasticsearchUrl.replace(/\//g, '\\/');

return `
kubectl kustomize ${KUSTOMIZE_TEMPLATE_URL}\\?ref\\=v${elasticAgentVersion}
kubectl kustomize ${KUSTOMIZE_TEMPLATE_URL}\\?ref\\=v${elasticAgentVersionInfo.agentBaseVersion}
| sed -e 's/JUFQSV9LRVkl/${encodedApiKey}/g'
-e "s/%ES_HOST%/${escapedElasticsearchUrl}/g"
-e "s/%ONBOARDING_ID%/${onboardingId}/g"
-e "s/\\(docker.elastic.co\\/beats\\/elastic-agent\:\\).*$/\\1${elasticAgentVersion}/g"
-e "s/\\(docker.elastic.co\\/beats\\/elastic-agent\:\\).*$/\\1${elasticAgentVersionInfo.agentDockerImageVersion}/g"
-e "/{CA_TRUSTED}/c\\ "
| kubectl apply -f-
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ import React from 'react';
import { EuiCodeBlock, EuiLink, EuiSpacer, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { ElasticAgentVersionInfo } from '../../../../common/types';
import { buildKubectlCommand } from './build_kubectl_command';
import { CopyToClipboardButton } from '../shared/copy_to_clipboard_button';

interface Props {
encodedApiKey: string;
onboardingId: string;
elasticsearchUrl: string;
elasticAgentVersion: string;
elasticAgentVersionInfo: ElasticAgentVersionInfo;
isCopyPrimaryAction: boolean;
}

export function CommandSnippet({
encodedApiKey,
onboardingId,
elasticsearchUrl,
elasticAgentVersion,
elasticAgentVersionInfo,
isCopyPrimaryAction,
}: Props) {
const command = buildKubectlCommand({
encodedApiKey,
onboardingId,
elasticsearchUrl,
elasticAgentVersion,
elasticAgentVersionInfo,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const KubernetesPanel: React.FC = () => {
encodedApiKey={data.apiKeyEncoded}
onboardingId={data.onboardingId}
elasticsearchUrl={data.elasticsearchUrl}
elasticAgentVersion={data.elasticAgentVersion}
elasticAgentVersionInfo={data.elasticAgentVersionInfo}
isCopyPrimaryAction={!isMonitoringStepActive}
/>
)}
Expand Down
Loading

0 comments on commit 98c9646

Please sign in to comment.