Skip to content

Commit

Permalink
Merge branch 'main' into 142435-add-is-one-of-operstor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristof-Pierre Cummings committed Nov 14, 2022
2 parents 3837184 + 19c4e19 commit aee9d98
Show file tree
Hide file tree
Showing 84 changed files with 1,897 additions and 1,100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,9 @@ const mockedResponse: StatusResponse = {
},
},
elasticsearch_client: {
protocol: 'https',
connectedNodes: 3,
nodesWithActiveSockets: 3,
nodesWithIdleSockets: 1,
totalActiveSockets: 25,
totalIdleSockets: 2,
totalQueuedRequests: 0,
mostActiveNodeSockets: 15,
averageActiveSocketsPerNode: 8,
mostIdleNodeSockets: 2,
averageIdleSocketsPerNode: 0.5,
},
process: {
pid: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('getAgentsSocketsStats()', () => {
},
});

const agent2 = getHttpAgentMock({
const agent2 = getHttpsAgentMock({
sockets: {
node1: [mockSocket, mockSocket, mockSocket],
node4: [mockSocket],
Expand All @@ -47,101 +47,9 @@ describe('getAgentsSocketsStats()', () => {

const stats = getAgentsSocketsStats(new Set<Agent>([agent1, agent2]));
expect(stats).toEqual({
averageActiveSocketsPerNode: 2.6666666666666665,
averageIdleSocketsPerNode: 4.5,
connectedNodes: 4,
mostActiveNodeSockets: 6,
mostIdleNodeSockets: 8,
nodesWithActiveSockets: 3,
nodesWithIdleSockets: 2,
protocol: 'http',
totalActiveSockets: 8,
totalIdleSockets: 9,
totalQueuedRequests: 6,
});
});

it('takes into account Agent types to determine the `protocol`', () => {
const httpAgent = getHttpAgentMock({
sockets: { node1: [mockSocket] },
freeSockets: {},
requests: {},
});

const httpsAgent = getHttpsAgentMock({
sockets: { node1: [mockSocket] },
freeSockets: {},
requests: {},
});

const noAgents = new Set<Agent>();
const httpAgents = new Set<Agent>([httpAgent, httpAgent]);
const httpsAgents = new Set<Agent>([httpsAgent, httpsAgent]);
const mixedAgents = new Set<Agent>([httpAgent, httpsAgent]);

expect(getAgentsSocketsStats(noAgents).protocol).toEqual('none');
expect(getAgentsSocketsStats(httpAgents).protocol).toEqual('http');
expect(getAgentsSocketsStats(httpsAgents).protocol).toEqual('https');
expect(getAgentsSocketsStats(mixedAgents).protocol).toEqual('mixed');
});

it('does not take into account those Agents that have not had any connection to any node', () => {
const pristineAgentProps = {
sockets: {},
freeSockets: {},
requests: {},
};
const agent1 = getHttpAgentMock(pristineAgentProps);
const agent2 = getHttpAgentMock(pristineAgentProps);
const agent3 = getHttpAgentMock(pristineAgentProps);

const stats = getAgentsSocketsStats(new Set<Agent>([agent1, agent2, agent3]));

expect(stats).toEqual({
averageActiveSocketsPerNode: 0,
averageIdleSocketsPerNode: 0,
connectedNodes: 0,
mostActiveNodeSockets: 0,
mostIdleNodeSockets: 0,
nodesWithActiveSockets: 0,
nodesWithIdleSockets: 0,
protocol: 'none',
totalActiveSockets: 0,
totalIdleSockets: 0,
totalQueuedRequests: 0,
});
});

it('takes into account those Agents that have hold mappings to one or more nodes, but that do not currently have any pending requests, active connections or idle connections', () => {
const emptyAgentProps = {
sockets: {
node1: [],
},
freeSockets: {
node2: [],
},
requests: {
node3: [],
},
};

const agent1 = getHttpAgentMock(emptyAgentProps);
const agent2 = getHttpAgentMock(emptyAgentProps);

const stats = getAgentsSocketsStats(new Set<Agent>([agent1, agent2]));

expect(stats).toEqual({
averageActiveSocketsPerNode: 0,
averageIdleSocketsPerNode: 0,
connectedNodes: 3,
mostActiveNodeSockets: 0,
mostIdleNodeSockets: 0,
nodesWithActiveSockets: 0,
nodesWithIdleSockets: 0,
protocol: 'http',
totalActiveSockets: 0,
totalIdleSockets: 0,
totalQueuedRequests: 0,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,20 @@
*/

import { NetworkAgent } from '@kbn/core-elasticsearch-client-server-internal';
import { Agent as HttpsAgent } from 'https';
import { mean } from 'lodash';
import type {
ElasticsearchClientProtocol,
ElasticsearchClientsMetrics,
} from '@kbn/core-metrics-server';
import type { ElasticsearchClientsMetrics } from '@kbn/core-metrics-server';

export const getAgentsSocketsStats = (agents: Set<NetworkAgent>): ElasticsearchClientsMetrics => {
const nodes = new Set<string>();
let totalActiveSockets = 0;
let totalIdleSockets = 0;
let totalQueuedRequests = 0;
let http: boolean = false;
let https: boolean = false;

const nodesWithActiveSockets: Record<string, number> = {};
const nodesWithIdleSockets: Record<string, number> = {};

agents.forEach((agent) => {
const agentRequests = Object.entries(agent.requests) ?? [];
const agentSockets = Object.entries(agent.sockets) ?? [];
const agentFreeSockets = Object.entries(agent.freeSockets) ?? [];

if (agentRequests.length || agentSockets.length || agentFreeSockets.length) {
if (agent instanceof HttpsAgent) https = true;
else http = true;

agentRequests.forEach(([node, queue]) => {
nodes.add(node);
totalQueuedRequests += queue?.length ?? 0;
Expand All @@ -43,39 +30,19 @@ export const getAgentsSocketsStats = (agents: Set<NetworkAgent>): ElasticsearchC
nodes.add(node);
const activeSockets = sockets?.length ?? 0;
totalActiveSockets += activeSockets;
nodesWithActiveSockets[node] = (nodesWithActiveSockets[node] ?? 0) + activeSockets;
});

agentFreeSockets.forEach(([node, freeSockets]) => {
nodes.add(node);
const idleSockets = freeSockets?.length ?? 0;
totalIdleSockets += idleSockets;
nodesWithIdleSockets[node] = (nodesWithIdleSockets[node] ?? 0) + idleSockets;
});
}
});

const activeSocketCounters = Object.values(nodesWithActiveSockets);
const idleSocketCounters = Object.values(nodesWithIdleSockets);
const protocol: ElasticsearchClientProtocol = http
? https
? 'mixed'
: 'http'
: https
? 'https'
: 'none';

return {
protocol,
connectedNodes: nodes.size,
nodesWithActiveSockets: activeSocketCounters.filter(Boolean).length,
nodesWithIdleSockets: idleSocketCounters.filter(Boolean).length,
totalActiveSockets,
totalIdleSockets,
totalQueuedRequests,
mostActiveNodeSockets: activeSocketCounters.length ? Math.max(...activeSocketCounters) : 0,
averageActiveSocketsPerNode: activeSocketCounters.length ? mean(activeSocketCounters) : 0,
mostIdleNodeSockets: idleSocketCounters.length ? Math.max(...idleSocketCounters) : 0,
averageIdleSocketsPerNode: idleSocketCounters.length ? mean(idleSocketCounters) : 0,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ import type {
} from '@kbn/core-metrics-server';

export const sampleEsClientMetrics: ElasticsearchClientsMetrics = {
protocol: 'https',
connectedNodes: 3,
nodesWithActiveSockets: 3,
nodesWithIdleSockets: 1,
totalActiveSockets: 25,
totalIdleSockets: 2,
totalQueuedRequests: 0,
mostActiveNodeSockets: 15,
averageActiveSocketsPerNode: 8,
mostIdleNodeSockets: 2,
averageIdleSocketsPerNode: 0.5,
};

const createInternalSetupContractMock = () => {
Expand Down
18 changes: 0 additions & 18 deletions packages/core/metrics/core-metrics-server/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,12 @@ export type ElasticsearchClientProtocol = 'none' | 'http' | 'https' | 'mixed';
* @public
*/
export interface ElasticsearchClientsMetrics {
/** The protocol (or protocols) that these Agents are using */
protocol: ElasticsearchClientProtocol;
/** Number of ES nodes that ES-js client is connecting to */
connectedNodes: number;
/** Number of nodes with active connections */
nodesWithActiveSockets: number;
/** Number of nodes with available connections (alive but idle).
* Note that a node can have both active and idle connections at the same time
*/
nodesWithIdleSockets: number;
/** Total number of active sockets (all nodes, all connections) */
totalActiveSockets: number;
/** Total number of available sockets (alive but idle, all nodes, all connections) */
totalIdleSockets: number;
/** Total number of queued requests (all nodes, all connections) */
totalQueuedRequests: number;
/** Number of active connections of the node with most active connections */
mostActiveNodeSockets: number;
/** Average of active sockets per node (all connections) */
averageActiveSocketsPerNode: number;
/** Number of idle connections of the node with most idle connections */
mostIdleNodeSockets: number;
/** Average of available (idle) sockets per node (all connections) */
averageIdleSocketsPerNode: number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"siem-ui-timeline-pinned-event": "e2697b38751506c7fce6e8b7207a830483dc4283",
"space": "c4a0acce1bd4b9cce85154f2a350624a53111c59",
"spaces-usage-stats": "922d3235bbf519e3fb3b260e27248b1df8249b79",
"synthetics-monitor": "30f1cd04016a37095de60554cbf7fff89aaad177",
"synthetics-monitor": "111811218f7e34f40980665a4eb99976f457bb23",
"synthetics-privates-locations": "dd00385f4a27ef062c3e57312eeb3799872fa4af",
"tag": "39413f4578cc2128c9a0fda97d0acd1c8862c47a",
"task": "ef53d0f070bd54957b8fe22fae3b1ff208913f76",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion x-pack/plugins/cloud_security_posture/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const INTERNAL_FEATURE_FLAGS = {
showManageRulesMock: false,
showFindingFlyoutEvidence: false,
showFindingsGroupBy: true,
showNewDashboard: false,
} as const;

export const CSP_RULE_SAVED_OBJECT_TYPE = 'csp_rule';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export const useCisKubernetesIntegration = () => {
const { http } = useKibana().services;

return useQuery<GetInfoResponse, DefaultPackagesInstallationError>(['integrations'], () =>
http.get<GetInfoResponse>(epmRouteService.getInfoPath(CLOUD_SECURITY_POSTURE_PACKAGE_NAME), {
query: { experimental: true },
})
http.get<GetInfoResponse>(epmRouteService.getInfoPath(CLOUD_SECURITY_POSTURE_PACKAGE_NAME))
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const ChartPanel: React.FC<ChartPanelProps> = ({

return (
<EuiPanel hasBorder={hasBorder} hasShadow={false} data-test-subj="chart-panel">
<EuiFlexGroup direction="column" gutterSize="none" style={{ height: '100%' }}>
<EuiFlexGroup direction="column" gutterSize="m" style={{ height: '100%' }}>
<EuiFlexItem grow={false}>
{title && (
<EuiTitle size="xs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ const getBenchmarkIdIconType = (props: Props): string => {

export const CISBenchmarkIcon = (props: Props) => (
<EuiToolTip content={props.name}>
<EuiIcon type={getBenchmarkIdIconType(props)} size="xxl" css={props.style} />
<EuiIcon type={getBenchmarkIdIconType(props)} size="xl" css={props.style} />
</EuiToolTip>
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,31 @@
* 2.0.
*/

import React from 'react';
import React, { MouseEventHandler } from 'react';
import { css } from '@emotion/react';
import { EuiCard, EuiIcon, EuiText, EuiTitle, useEuiTheme } from '@elastic/eui';
import type { EuiTextProps, EuiCardProps } from '@elastic/eui';
import { EuiIcon, EuiPanel, EuiStat, useEuiTheme } from '@elastic/eui';
import type { EuiStatProps } from '@elastic/eui';

export type CspCounterCardProps = Pick<EuiCardProps, 'onClick' | 'id' | 'title' | 'description'> & {
descriptionColor?: EuiTextProps['color'];
};
export interface CspCounterCardProps {
id: string;
onClick?: MouseEventHandler<HTMLButtonElement>;
title: EuiStatProps['title'];
titleColor?: EuiStatProps['titleColor'];
description: EuiStatProps['description'];
}

export const CspCounterCard = (counter: CspCounterCardProps) => {
const { euiTheme } = useEuiTheme();

return (
<EuiCard
title={
<EuiTitle size="xxxs">
<h6>{counter.title}</h6>
</EuiTitle>
}
<EuiPanel
hasBorder
onClick={counter.onClick}
paddingSize="m"
textAlign="left"
layout="vertical"
css={css`
position: relative;
display: flex;
align-items: center;
:hover .euiIcon {
color: ${euiTheme.colors.primary};
Expand All @@ -39,21 +38,29 @@ export const CspCounterCard = (counter: CspCounterCardProps) => {
`}
data-test-subj={counter.id}
>
<EuiText color={counter.descriptionColor}>
<EuiTitle size="xs">
<h3>{counter.description}</h3>
</EuiTitle>
</EuiText>
<EuiStat
css={{
height: '100%',
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-around',
}}
titleSize="s"
title={counter.title}
titleColor={counter.titleColor}
descriptionElement="h6"
description={counter.description}
/>
{counter.onClick && (
<EuiIcon
type="link"
css={css`
position: absolute;
top: ${euiTheme.size.m};
right: ${euiTheme.size.m};
top: ${euiTheme.size.s};
right: ${euiTheme.size.s};
`}
/>
)}
</EuiCard>
</EuiPanel>
);
};
Loading

0 comments on commit aee9d98

Please sign in to comment.