Skip to content

Commit

Permalink
Merge branch 'main' into lens/timeshift-previous
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jan 5, 2022
2 parents f4acba6 + d0d50bf commit 7cd85ef
Show file tree
Hide file tree
Showing 26 changed files with 336 additions and 81 deletions.
24 changes: 13 additions & 11 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
import { uniq, omit } from 'lodash';
import uuid from 'uuid/v4';
import uuidv5 from 'uuid/v5';
import { safeDump } from 'js-yaml';
import pMap from 'p-map';
import type {
ElasticsearchClient,
SavedObjectsClientContract,
SavedObjectsBulkUpdateResponse,
} from 'src/core/server';

import { safeDump } from 'js-yaml';

import { SavedObjectsErrorHelpers } from '../../../../../src/core/server';

import type { AuthenticatedUser } from '../../../security/server';
import {
AGENT_POLICY_SAVED_OBJECT_TYPE,
AGENTS_PREFIX,
PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE,
SO_SEARCH_LIMIT,
} from '../constants';
import type {
PackagePolicy,
Expand Down Expand Up @@ -477,6 +478,7 @@ class AgentPolicyService {
fields: ['revision', 'data_output_id', 'monitoring_output_id'],
searchFields: ['data_output_id', 'monitoring_output_id'],
search: escapeSearchQueryPhrase(outputId),
perPage: SO_SEARCH_LIMIT,
});
const bumpedPolicies = currentPolicies.saved_objects.map((policy) => {
policy.attributes = {
Expand All @@ -488,11 +490,10 @@ class AgentPolicyService {
return policy;
});
const res = await soClient.bulkUpdate<AgentPolicySOAttributes>(bumpedPolicies);

await Promise.all(
currentPolicies.saved_objects.map((policy) =>
this.triggerAgentPolicyUpdatedEvent(soClient, esClient, 'updated', policy.id)
)
await pMap(
currentPolicies.saved_objects,
(policy) => this.triggerAgentPolicyUpdatedEvent(soClient, esClient, 'updated', policy.id),
{ concurrency: 50 }
);

return res;
Expand All @@ -506,6 +507,7 @@ class AgentPolicyService {
const currentPolicies = await soClient.find<AgentPolicySOAttributes>({
type: SAVED_OBJECT_TYPE,
fields: ['revision'],
perPage: SO_SEARCH_LIMIT,
});
const bumpedPolicies = currentPolicies.saved_objects.map((policy) => {
policy.attributes = {
Expand All @@ -518,10 +520,10 @@ class AgentPolicyService {
});
const res = await soClient.bulkUpdate<AgentPolicySOAttributes>(bumpedPolicies);

await Promise.all(
currentPolicies.saved_objects.map((policy) =>
this.triggerAgentPolicyUpdatedEvent(soClient, esClient, 'updated', policy.id)
)
await pMap(
currentPolicies.saved_objects,
(policy) => this.triggerAgentPolicyUpdatedEvent(soClient, esClient, 'updated', policy.id),
{ concurrency: 50 }
);

return res;
Expand Down
10 changes: 8 additions & 2 deletions x-pack/plugins/infra/public/metrics_overview_fetchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ describe('Metrics UI Observability Homepage Functions', () => {
const { core, mockedGetStartServices } = setup();
core.http.get.mockResolvedValue({
hasData: true,
configuration: {
metricAlias: 'metric-*',
},
});
const hasData = createMetricsHasData(mockedGetStartServices);
const response = await hasData();
expect(core.http.get).toHaveBeenCalledTimes(1);
expect(response).toBeTruthy();
expect(response.hasData).toBeTruthy();
});
it('should return false when false', async () => {
const { core, mockedGetStartServices } = setup();
core.http.get.mockResolvedValue({
hasData: false,
configuration: {
metricAlias: 'metric-*',
},
});
const hasData = createMetricsHasData(mockedGetStartServices);
const response = await hasData();
expect(core.http.get).toHaveBeenCalledTimes(1);
expect(response).toBeFalsy();
expect(response.hasData).toBeFalsy();
});
});

Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/infra/public/metrics_overview_fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import { FetchDataParams, MetricsFetchDataResponse } from '../../observability/public';
import { TopNodesRequest, TopNodesResponse } from '../common/http_api/overview_api';
import { InfraClientCoreSetup } from './types';
import { InfraStaticSourceConfiguration } from '../common/source_configuration/source_configuration';

export const createMetricsHasData =
(getStartServices: InfraClientCoreSetup['getStartServices']) => async () => {
const [coreServices] = await getStartServices();
const { http } = coreServices;
const results = await http.get<{ hasData: boolean }>('/api/metrics/source/default/hasData');
return results.hasData;
const results = await http.get<{
hasData: boolean;
configuration: InfraStaticSourceConfiguration;
}>('/api/metrics/source/default/hasData');
return { hasData: results.hasData, indices: results.configuration.metricAlias! };
};

export const createMetricsFetchData =
Expand Down
52 changes: 49 additions & 3 deletions x-pack/plugins/infra/public/pages/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n';
import React, { useContext } from 'react';
import { Route, RouteComponentProps, Switch } from 'react-router-dom';

import { EuiErrorBoundary, EuiHeaderLinks, EuiHeaderLink } from '@elastic/eui';
import { EuiErrorBoundary, EuiHeaderLinks, EuiHeaderLink, EuiToolTip } from '@elastic/eui';
import { MetricsSourceConfigurationProperties } from '../../../common/metrics_sources';
import { DocumentTitle } from '../../components/document_title';
import { HelpCenterContent } from '../../components/help_center_content';
Expand All @@ -27,7 +27,7 @@ import { SnapshotPage } from './inventory_view';
import { MetricDetail } from './metric_detail';
import { MetricsSettingsPage } from './settings';
import { SourceLoadingPage } from '../../components/source_loading_page';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
import { RedirectAppLinks, useKibana } from '../../../../../../src/plugins/kibana_react/public';
import { WaffleOptionsProvider } from './inventory_view/hooks/use_waffle_options';
import { WaffleTimeProvider } from './inventory_view/hooks/use_waffle_time';
import { WaffleFiltersProvider } from './inventory_view/hooks/use_waffle_filters';
Expand All @@ -37,7 +37,7 @@ import { SavedViewProvider } from '../../containers/saved_view/saved_view';
import { AlertPrefillProvider } from '../../alerting/use_alert_prefill';
import { InfraMLCapabilitiesProvider } from '../../containers/ml/infra_ml_capabilities';
import { AnomalyDetectionFlyout } from './inventory_view/components/ml/anomaly_detection/anomaly_detection_flyout';
import { HeaderMenuPortal } from '../../../../observability/public';
import { createExploratoryViewUrl, HeaderMenuPortal } from '../../../../observability/public';
import { HeaderActionMenuContext } from '../../utils/header_action_menu_provider';
import { useLinkProps } from '../../hooks/use_link_props';
import { CreateDerivedIndexPattern } from '../../containers/metrics_source';
Expand All @@ -63,6 +63,25 @@ export const InfrastructurePage = ({ match }: RouteComponentProps) => {
pathname: 'settings',
});

const metricsExploratoryViewLink = createExploratoryViewUrl(
{
reportType: 'kpi-over-time',
allSeries: [
{
dataType: 'infra_metrics',
seriesType: 'area',
time: { to: 'now', from: 'now-15m' },
reportDefinitions: {
'agent.hostname': ['ALL_VALUES'],
},
selectedMetricField: 'system.cpu.total.norm.pct',
name: 'Metrics-series',
},
],
},
kibana.services.http?.basePath.get()
);

return (
<EuiErrorBoundary>
<Source.Provider sourceId="default">
Expand All @@ -87,6 +106,24 @@ export const InfrastructurePage = ({ match }: RouteComponentProps) => {
{setHeaderActionMenu && theme$ && (
<HeaderMenuPortal setHeaderActionMenu={setHeaderActionMenu} theme$={theme$}>
<EuiHeaderLinks gutterSize="xs">
<EuiToolTip position="top" content={<p>{EXPLORE_MESSAGE}</p>}>
<RedirectAppLinks application={kibana.services.application!}>
<EuiHeaderLink
aria-label={i18n.translate(
'xpack.infra.metrics.pageHeader.analyzeData.label',
{
defaultMessage:
'Navigate to the "Explore Data" view to visualize infra metrics data',
}
)}
href={metricsExploratoryViewLink}
color="text"
iconType="visBarVerticalStacked"
>
{EXPLORE_DATA}
</EuiHeaderLink>
</RedirectAppLinks>
</EuiToolTip>
<EuiHeaderLink color={'text'} {...settingsLinkProps}>
{settingsTabTitle}
</EuiHeaderLink>
Expand Down Expand Up @@ -158,3 +195,12 @@ const PageContent = (props: {
</SavedViewProvider>
);
};

const EXPLORE_DATA = i18n.translate('xpack.infra.metrics.exploreDataButtonLabel', {
defaultMessage: 'Explore data',
});

const EXPLORE_MESSAGE = i18n.translate('xpack.infra.metrics.exploreDataButtonLabel.message', {
defaultMessage:
'Explore Data allows you to select and filter result data in any dimension and look for the cause or impact of performance problems.',
});
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const initMetricsSourceConfigurationRoutes = (libs: InfraBackendLibs) =>
const results = await hasData(source.configuration.metricAlias, client);

return response.ok({
body: { hasData: results },
body: { hasData: results, configuration: source.configuration },
});
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export enum DataTypes {
SYNTHETICS = 'synthetics',
UX = 'ux',
MOBILE = 'mobile',
METRICS = 'infra_metrics',
}

export const USE_BREAK_DOWN_COLUMN = 'USE_BREAK_DOWN_COLUMN';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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 const SYSTEM_CPU_PERCENTAGE_FIELD = 'system.cpu.total.norm.pct';
export const SYSTEM_MEMORY_PERCENTAGE_FIELD = 'system.memory.used.pct';
export const DOCKER_CPU_PERCENTAGE_FIELD = 'docker.cpu.total.pct';
export const K8S_POD_CPU_PERCENTAGE_FIELD = 'kubernetes.pod.cpu.usage.node.pct';
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,38 @@ export const MOBILE_APP = i18n.translate('xpack.observability.expView.fieldLabel
defaultMessage: 'Mobile App',
});

export const MEMORY_USAGE = i18n.translate(
export const SYSTEM_MEMORY_USAGE = i18n.translate(
'xpack.observability.expView.fieldLabels.mobile.memoryUsage',
{
defaultMessage: 'Memory Usage',
defaultMessage: 'System memory usage',
}
);

export const CPU_USAGE = i18n.translate('xpack.observability.expView.fieldLabels.cpuUsage', {
defaultMessage: 'CPU Usage',
defaultMessage: 'CPU usage',
});

export const SYSTEM_CPU_USAGE = i18n.translate(
'xpack.observability.expView.fieldLabels.cpuUsage.system',
{
defaultMessage: 'System CPU usage',
}
);

export const DOCKER_CPU_USAGE = i18n.translate(
'xpack.observability.expView.fieldLabels.cpuUsage.docker',
{
defaultMessage: 'Docker CPU usage',
}
);

export const K8S_POD_CPU_USAGE = i18n.translate(
'xpack.observability.expView.fieldLabels.cpuUsage.k8sDocker',
{
defaultMessage: 'K8s pod CPU usage',
}
);

export const TRANSACTIONS_PER_MINUTE = i18n.translate(
'xpack.observability.expView.fieldLabels.transactionPerMinute',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ export const getDefaultConfigs = ({
indexPattern,
reportConfigMap,
}: Props): SeriesConfig => {
let configResult: SeriesConfig;
let configResult: SeriesConfig | undefined;

reportConfigMap[dataType].some((fn) => {
reportConfigMap[dataType]?.some((fn) => {
const config = fn({ indexPattern });
if (config.reportType === reportType) {
configResult = config;
}
return config.reportType === reportType;
});

return configResult!;
if (!configResult) {
// not a user facing error, more of a dev focused error
throw new Error(
`No report config provided for dataType: ${dataType} and reportType: ${reportType}`
);
}

return configResult;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.
*/

import { FieldFormat } from '../../types';
import {
SYSTEM_CPU_PERCENTAGE_FIELD,
DOCKER_CPU_PERCENTAGE_FIELD,
K8S_POD_CPU_PERCENTAGE_FIELD,
SYSTEM_MEMORY_PERCENTAGE_FIELD,
} from '../constants/field_names/infra_metrics';

export const infraMetricsFieldFormats: FieldFormat[] = [
{
field: SYSTEM_CPU_PERCENTAGE_FIELD,
format: {
id: 'percent',
params: {},
},
},
{
field: DOCKER_CPU_PERCENTAGE_FIELD,
format: {
id: 'percent',
params: {},
},
},
{
field: K8S_POD_CPU_PERCENTAGE_FIELD,
format: {
id: 'percent',
params: {},
},
},
{
field: SYSTEM_MEMORY_PERCENTAGE_FIELD,
format: {
id: 'percent',
params: {},
},
},
];
Loading

0 comments on commit 7cd85ef

Please sign in to comment.