Skip to content

Commit

Permalink
Merge branch 'main' into find-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lcawl authored Nov 14, 2022
2 parents a5907b5 + 53bab70 commit 2141495
Show file tree
Hide file tree
Showing 115 changed files with 2,556 additions and 1,375 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
/test/functional/apps/discover/ @elastic/kibana-data-discovery
/test/functional/apps/context/ @elastic/kibana-data-discovery
/test/api_integration/apis/unified_field_list/ @elastic/kibana-data-discovery
/x-pack/plugins/graph/ @elastic/kibana-data-discovery
/x-pack/test/functional/apps/graph @elastic/kibana-data-discovery
/src/plugins/unified_field_list/ @elastic/kibana-data-discovery
/src/plugins/unified_histogram/ @elastic/kibana-data-discovery
/src/plugins/saved_objects_finder/ @elastic/kibana-data-discovery
Expand Down Expand Up @@ -49,6 +47,8 @@
/test/functional/apps/visualize/ @elastic/kibana-visualizations
/src/plugins/expressions/ @elastic/kibana-visualizations
/src/plugins/unified_search/ @elastic/kibana-visualizations
/x-pack/plugins/graph/ @elastic/kibana-visualizations
/x-pack/test/functional/apps/graph @elastic/kibana-visualizations

# Application Services
/examples/dashboard_embeddable_examples/ @elastic/kibana-app-services
Expand Down
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.

7 changes: 4 additions & 3 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ export class APMPlugin

if (plugins.alerting) {
registerApmRuleTypes({
ruleDataClient,
alerting: plugins.alerting,
ml: plugins.ml,
basePath: core.http.basePath,
config$,
logger: this.logger!.get('rule'),
basePath: core.http.basePath,
ml: plugins.ml,
observability: plugins.observability,
ruleDataClient,
});
}

Expand Down
Loading

0 comments on commit 2141495

Please sign in to comment.