Skip to content

Commit

Permalink
Merge branch 'main' into home-plugin/add-kibana-theme-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Nov 22, 2021
2 parents b16a9ee + 562384f commit 17d7e7d
Show file tree
Hide file tree
Showing 103 changed files with 2,413 additions and 1,495 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"deep-freeze-strict": "^1.1.1",
"deepmerge": "^4.2.2",
"del": "^5.1.0",
"elastic-apm-node": "3.24.0",
"elastic-apm-node": "^3.24.0",
"execa": "^4.0.2",
"exit-hook": "^2.2.0",
"expiry-js": "0.1.7",
Expand Down
8 changes: 8 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
"labels": ["release_note:skip", "Team:Operations", "Team:Core", "backport:skip"],
"enabled": true
},
{
"groupName": "APM",
"matchPackageNames": ["elastic-apm-node", "@elastic/apm-rum", "@elastic/apm-rum-react"],
"reviewers": ["team:kibana-core"],
"matchBaseBranches": ["main"],
"labels": ["release_note:skip", "Team:Core", "backport:skip"],
"enabled": true
},
{
"groupName": "babel",
"matchPackageNames": ["@types/babel__core"],
Expand Down
1 change: 1 addition & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export class DocLinksService {
mappingTermVector: `${ELASTICSEARCH_DOCS}term-vector.html`,
mappingTypesRemoval: `${ELASTICSEARCH_DOCS}removal-of-types.html`,
migrateIndexAllocationFilters: `${ELASTICSEARCH_DOCS}migrate-index-allocation-filters.html`,
migrationApiDeprecation: `${ELASTICSEARCH_DOCS}migration-api-deprecation.html`,
nodeRoles: `${ELASTICSEARCH_DOCS}modules-node.html#node-roles`,
releaseHighlights: `${ELASTICSEARCH_DOCS}release-highlights.html`,
remoteClusters: `${ELASTICSEARCH_DOCS}remote-clusters.html`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface Props {
isLoading: boolean;
hasPrivileges: boolean;
privilegesMissing: MissingPrivileges;
}) => JSX.Element;
}) => JSX.Element | null;
}

type Privilege = [string, string];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class InstructionSetUi extends React.Component {
return {
id: variant.id,
name: getDisplayText(variant.id),
initialSelected: variant.initialSelected,
};
});

Expand All @@ -45,7 +46,8 @@ class InstructionSetUi extends React.Component {
};

if (this.tabs.length > 0) {
this.state.selectedTabId = this.tabs[0].id;
this.state.selectedTabId =
this.tabs.find(({ initialSelected }) => initialSelected)?.id ?? this.tabs[0].id;
}
}

Expand Down Expand Up @@ -298,6 +300,7 @@ const instructionShape = PropTypes.shape({
const instructionVariantShape = PropTypes.shape({
id: PropTypes.string.isRequired,
instructions: PropTypes.arrayOf(instructionShape).isRequired,
initialSelected: PropTypes.bool,
});

const statusCheckConfigShape = PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type Instruction = TypeOf<typeof instructionSchema>;
const instructionVariantSchema = schema.object({
id: schema.string(),
instructions: schema.arrayOf(instructionSchema),
initialSelected: schema.maybe(schema.boolean()),
});

export type InstructionVariant = TypeOf<typeof instructionVariantSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

import { i18n } from '@kbn/i18n';
import type { KibanaExecutionContext } from 'kibana/public';
import { DataView } from 'src/plugins/data/common';
import { KibanaContext, TimeRange, Filter, esQuery, Query } from '../../../../data/public';
import { TimelionVisDependencies } from '../plugin';
import { getTimezone } from './get_timezone';
import { TimelionVisParams } from '../timelion_vis_fn';
import { getDataSearch } from '../helpers/plugin_services';
import { getDataSearch, getIndexPatterns } from '../helpers/plugin_services';
import { VisSeries } from '../../common/vis_data';

interface Stats {
Expand Down Expand Up @@ -81,6 +82,14 @@ export function getTimelionRequestHandler({
);
}

let dataView: DataView | undefined;
const firstFilterIndex = filters[0]?.meta.index;
if (firstFilterIndex) {
dataView = await getIndexPatterns()
.get(firstFilterIndex)
.catch(() => undefined);
}

const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings);

// parse the time range client side to make sure it behaves like other charts
Expand All @@ -100,7 +109,7 @@ export function getTimelionRequestHandler({
sheet: [expression],
extended: {
es: {
filter: esQuery.buildEsQuery(undefined, query, filters, esQueryConfigs),
filter: esQuery.buildEsQuery(dataView, query, filters, esQueryConfigs),
},
},
time: {
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/vis_types/vega/public/vega_request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import type { KibanaExecutionContext } from 'src/core/public';
import { DataView } from 'src/plugins/data/common';
import { Filter, esQuery, TimeRange, Query } from '../../../data/public';

import { SearchAPI } from './data_model/search_api';
Expand All @@ -18,7 +19,7 @@ import { VegaInspectorAdapters } from './vega_inspector';

interface VegaRequestHandlerParams {
query: Query;
filters: Filter;
filters: Filter[];
timeRange: TimeRange;
visParams: VisParams;
searchSessionId?: string;
Expand Down Expand Up @@ -46,14 +47,14 @@ export function createVegaRequestHandler(
searchSessionId,
executionContext,
}: VegaRequestHandlerParams) {
if (!searchAPI) {
const { search, indexPatterns } = getData();
const { dataViews, search } = getData();

if (!searchAPI) {
searchAPI = new SearchAPI(
{
uiSettings,
search,
indexPatterns,
indexPatterns: dataViews,
injectedMetadata: getInjectedMetadata(),
},
context.abortSignal,
Expand All @@ -65,8 +66,14 @@ export function createVegaRequestHandler(

timeCache.setTimeRange(timeRange);

let dataView: DataView;
const firstFilterIndex = filters[0]?.meta.index;
if (firstFilterIndex) {
dataView = await dataViews.get(firstFilterIndex).catch(() => undefined);
}

const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings);
const filtersDsl = esQuery.buildEsQuery(undefined, query, filters, esQueryConfigs);
const filtersDsl = esQuery.buildEsQuery(dataView, query, filters, esQueryConfigs);
const { VegaParser } = await import('./data_model/vega_parser');
const vp = new VegaParser(visParams.spec, searchAPI, timeCache, filtersDsl, getServiceSettings);

Expand Down
3 changes: 2 additions & 1 deletion test/api_integration/apis/stats/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export default function ({ getService }) {
);
});

describe('basic', () => {
// FLAKY: https://github.com/elastic/kibana/issues/116725
describe.skip('basic', () => {
it('should return the stats without cluster_uuid with no query string params', () => {
return supertest
.get('/api/stats')
Expand Down
5 changes: 5 additions & 0 deletions test/functional/apps/discover/_search_on_page_load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await testSubjects.exists('refreshDataButton')).to.be(true);
await retry.waitFor('number of fetches to be 0', waitForFetches(0));

/**
* We should wait for debounce timeout expired 100 ms,
* otherwise click event will be skipped. See getFetch$ implementation.
*/
await PageObjects.common.sleep(100);
await testSubjects.click('refreshDataButton');

await retry.waitFor('number of fetches to be 1', waitForFetches(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const CentralizedContainer = styled.div`
align-items: center;
`;

type APIResponseType = APIReturnType<'GET /internal/apm/fleet/has_data'>;
type APIResponseType = APIReturnType<'GET /internal/apm/fleet/migration_check'>;

function TutorialFleetInstructions({ http, basePath, isDarkTheme }: Props) {
const [data, setData] = useState<APIResponseType | undefined>();
Expand All @@ -44,7 +44,7 @@ function TutorialFleetInstructions({ http, basePath, isDarkTheme }: Props) {
async function fetchData() {
setIsLoading(true);
try {
const response = await http.get('/internal/apm/fleet/has_data');
const response = await http.get('/internal/apm/fleet/migration_check');
setData(response as APIResponseType);
} catch (e) {
setIsLoading(false);
Expand All @@ -55,6 +55,22 @@ function TutorialFleetInstructions({ http, basePath, isDarkTheme }: Props) {
fetchData();
}, [http]);

const hasApmIntegrations = !!data?.has_apm_integrations;
const cloudApmMigrationEnabled = !!data?.cloud_apm_migration_enabled;
const hasCloudAgentPolicy = !!data?.has_cloud_agent_policy;
const cloudApmPackagePolicy = data?.cloud_apm_package_policy;
const hasCloudApmPackagePolicy = !!cloudApmPackagePolicy;
const hasRequiredRole = !!data?.has_required_role;
const shouldLinkToMigration =
cloudApmMigrationEnabled &&
hasCloudAgentPolicy &&
!hasCloudApmPackagePolicy &&
hasRequiredRole;

const apmIntegrationHref = shouldLinkToMigration
? `${basePath}/app/apm/settings/schema`
: `${basePath}/app/integrations/detail/apm-${SUPPORTED_APM_PACKAGE_VERSION}/overview`;

if (isLoading) {
return (
<CentralizedContainer>
Expand All @@ -64,9 +80,13 @@ function TutorialFleetInstructions({ http, basePath, isDarkTheme }: Props) {
}

// When APM integration is enable in Fleet
if (data?.hasData) {
if (hasApmIntegrations) {
return (
<EuiButton iconType="gear" fill href={`${basePath}/app/fleet#/policies`}>
<EuiButton
iconType="gear"
fill
href={`${basePath}/app/integrations/detail/apm-${SUPPORTED_APM_PACKAGE_VERSION}/policies`}
>
{i18n.translate(
'xpack.apm.tutorial.apmServer.fleet.manageApmIntegration.button',
{
Expand Down Expand Up @@ -99,7 +119,7 @@ function TutorialFleetInstructions({ http, basePath, isDarkTheme }: Props) {
<EuiButton
iconType="analyzeEvent"
color="success"
href={`${basePath}/app/integrations#/detail/apm-${SUPPORTED_APM_PACKAGE_VERSION}/overview`}
href={apmIntegrationHref}
>
{i18n.translate(
'xpack.apm.tutorial.apmServer.fleet.apmIntegration.button',
Expand Down
13 changes: 10 additions & 3 deletions x-pack/plugins/apm/server/routes/fleet/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,16 @@ const getMigrationCheckRoute = createApmServerRoute({
endpoint: 'GET /internal/apm/fleet/migration_check',
options: { tags: ['access:apm'] },
handler: async (resources) => {
const { plugins, context, config, request } = resources;
const { core, plugins, context, config, request } = resources;
const cloudApmMigrationEnabled = config.agent.migrations.enabled;
if (!plugins.fleet || !plugins.security) {
throw Boom.internal(FLEET_SECURITY_REQUIRED_MESSAGE);
}
const savedObjectsClient = context.core.savedObjects.client;
const fleetPluginStart = await plugins.fleet.start();
const securityPluginStart = await plugins.security.start();
const [fleetPluginStart, securityPluginStart] = await Promise.all([
plugins.fleet.start(),
plugins.security.start(),
]);
const hasRequiredRole = isSuperuser({ securityPluginStart, request });
const cloudAgentPolicy = hasRequiredRole
? await getCloudAgentPolicy({
Expand All @@ -144,12 +146,17 @@ const getMigrationCheckRoute = createApmServerRoute({
})
: undefined;
const apmPackagePolicy = getApmPackagePolicy(cloudAgentPolicy);
const packagePolicies = await getApmPackgePolicies({
core,
fleetPluginStart,
});
return {
has_cloud_agent_policy: !!cloudAgentPolicy,
has_cloud_apm_package_policy: !!apmPackagePolicy,
cloud_apm_migration_enabled: cloudApmMigrationEnabled,
has_required_role: hasRequiredRole,
cloud_apm_package_policy: apmPackagePolicy,
has_apm_integrations: packagePolicies.total > 0,
};
},
});
Expand Down
17 changes: 14 additions & 3 deletions x-pack/plugins/apm/server/tutorial/envs/elastic_cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,28 @@ import {
createPhpAgentInstructions,
} from '../../../common/tutorial/instructions/apm_agent_instructions';
import { CloudSetup } from '../../../../cloud/server';
import { APMConfig } from '../..';
import { getOnPremApmServerInstructionSet } from './on_prem_apm_server_instruction_set';

export function createElasticCloudInstructions(
cloudSetup?: CloudSetup
): TutorialSchema['elasticCloud'] {
export function createElasticCloudInstructions({
cloudSetup,
apmConfig,
isFleetPluginEnabled,
}: {
cloudSetup?: CloudSetup;
apmConfig: APMConfig;
isFleetPluginEnabled: boolean;
}): TutorialSchema['elasticCloud'] {
const apmServerUrl = cloudSetup?.apm.url;
const instructionSets = [];

if (!apmServerUrl) {
instructionSets.push(getApmServerInstructionSet(cloudSetup));
}

instructionSets.push(
getOnPremApmServerInstructionSet({ apmConfig, isFleetPluginEnabled })
);
instructionSets.push(getApmAgentInstructionSet(cloudSetup));

return {
Expand Down
Loading

0 comments on commit 17d7e7d

Please sign in to comment.