Skip to content

Commit

Permalink
Merge branch 'elastic:main' into alerts/saved_query_ux_validation
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliidm authored Oct 4, 2022
2 parents a24362e + 7e01603 commit a5bb487
Show file tree
Hide file tree
Showing 330 changed files with 5,948 additions and 2,915 deletions.
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/storybooks/build_and_upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const STORYBOOKS = [
'apm',
'canvas',
'ci_composite',
'cloud',
'cloud_chat',
'coloring',
'chart_icons',
'controls',
Expand Down
9 changes: 9 additions & 0 deletions docs/api/saved-objects/find.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ experimental[] Retrieve a paginated set of {kib} saved objects by various condit
`has_reference`::
(Optional, object) Filters to objects that have a relationship with the type and ID combination.

`has_reference_operator`::
(Optional, string) The operator to use for the `has_reference` parameter. Either `OR` or `AND`. Defaults to `OR`.

`has_no_reference`::
(Optional, object) Filters to objects that do not have a relationship with the type and ID combination.

`has_no_reference_operator`::
(Optional, string) The operator to use for the `has_no_reference` parameter. Either `OR` or `AND`. Defaults to `OR`.

`filter`::
(Optional, string) The filter is a KQL string with the caveat that if you filter with an attribute from your saved object type,
it should look like that: `savedObjectType.attributes.title: "myTitle"`. However, If you use a root attribute of a saved
Expand Down
12 changes: 12 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,22 @@ The plugin exposes the static DefaultEditorController class to consume.
|The cloud plugin adds Cloud-specific features to Kibana.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_chat/README.md[cloudChat]
|Integrates with DriftChat in order to provide live support to our Elastic Cloud users. This plugin should only run on Elastic Cloud.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_experiments/README.mdx[cloudExperiments]
|The Cloud Experiments Service provides the necessary APIs to implement A/B testing scenarios, fetching the variations in configuration and reporting back metrics to track conversion rates of the experiments.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_full_story/README.md[cloudFullStory]
|Integrates with FullStory in order to provide better product analytics, so we can understand how our users make use of Kibana. This plugin should only run on Elastic Cloud.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_integrations/cloud_links/README.md[cloudLinks]
|Adds all the links to the Elastic Cloud console.
|{kib-repo}blob/{branch}/x-pack/plugins/cloud_security_posture/README.md[cloudSecurityPosture]
|Cloud Posture automates the identification and remediation of risks across cloud infrastructures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ const mockedResponse: StatusResponse = {
'15m': 0.1,
},
},
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,
memory: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
export { ScopedClusterClient } from './src/scoped_cluster_client';
export { ClusterClient } from './src/cluster_client';
export { configureClient } from './src/configure_client';
export { AgentManager } from './src/agent_manager';
export { type AgentStore, AgentManager } from './src/agent_manager';
export { getRequestDebugMeta, getErrorMessage } from './src/log_query_and_deprecation';
export {
PRODUCT_RESPONSE_HEADER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ describe('AgentManager', () => {
const agentFactory = agentManager.getAgentFactory();
const agent = agentFactory({ url: new URL('http://elastic-node-1:9200') });
// eslint-disable-next-line dot-notation
expect(agentManager['httpStore'].has(agent)).toEqual(true);
expect(agentManager['agents'].has(agent)).toEqual(true);
agent.destroy();
// eslint-disable-next-line dot-notation
expect(agentManager['httpStore'].has(agent)).toEqual(false);
expect(agentManager['agents'].has(agent)).toEqual(false);
});
});

Expand All @@ -122,4 +122,21 @@ describe('AgentManager', () => {
});
});
});

describe('#getAgents()', () => {
it('returns the created HTTP and HTTPs Agent instances', () => {
const agentManager = new AgentManager();
const agentFactory1 = agentManager.getAgentFactory();
const agentFactory2 = agentManager.getAgentFactory();
const agent1 = agentFactory1({ url: new URL('http://elastic-node-1:9200') });
const agent2 = agentFactory2({ url: new URL('http://elastic-node-1:9200') });
const agent3 = agentFactory1({ url: new URL('https://elastic-node-1:9200') });
const agent4 = agentFactory2({ url: new URL('https://elastic-node-1:9200') });

const agents = agentManager.getAgents();

expect(agents.size).toEqual(4);
expect([...agents]).toEqual(expect.arrayContaining([agent1, agent2, agent3, agent4]));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { Agent as HttpAgent } from 'http';
import { Agent as HttpsAgent } from 'https';
import { ConnectionOptions, HttpAgentOptions } from '@elastic/elasticsearch';
import type { ConnectionOptions, HttpAgentOptions } from '@elastic/elasticsearch';

const HTTPS = 'https:';
const DEFAULT_CONFIG: HttpAgentOptions = {
Expand All @@ -22,6 +22,14 @@ const DEFAULT_CONFIG: HttpAgentOptions = {
export type NetworkAgent = HttpAgent | HttpsAgent;
export type AgentFactory = (connectionOpts: ConnectionOptions) => NetworkAgent;

export interface AgentFactoryProvider {
getAgentFactory(agentOptions?: HttpAgentOptions): AgentFactory;
}

export interface AgentStore {
getAgents(): Set<NetworkAgent>;
}

/**
* Allows obtaining Agent factories, which can then be fed into elasticsearch-js's Client class.
* Ideally, we should obtain one Agent factory for each ES Client class.
Expand All @@ -33,15 +41,11 @@ export type AgentFactory = (connectionOpts: ConnectionOptions) => NetworkAgent;
* exposes methods that can modify the underlying pools, effectively impacting the connections of other Clients.
* @internal
**/
export class AgentManager {
// Stores Https Agent instances
private httpsStore: Set<HttpsAgent>;
// Stores Http Agent instances
private httpStore: Set<HttpAgent>;
export class AgentManager implements AgentFactoryProvider, AgentStore {
private agents: Set<HttpAgent>;

constructor(private agentOptions: HttpAgentOptions = DEFAULT_CONFIG) {
this.httpsStore = new Set();
this.httpStore = new Set();
this.agents = new Set();
}

public getAgentFactory(agentOptions?: HttpAgentOptions): AgentFactory {
Expand All @@ -61,8 +65,8 @@ export class AgentManager {
connectionOpts.tls
);
httpsAgent = new HttpsAgent(config);
this.httpsStore.add(httpsAgent);
dereferenceOnDestroy(this.httpsStore, httpsAgent);
this.agents.add(httpsAgent);
dereferenceOnDestroy(this.agents, httpsAgent);
}

return httpsAgent;
Expand All @@ -71,19 +75,23 @@ export class AgentManager {
if (!httpAgent) {
const config = Object.assign({}, DEFAULT_CONFIG, this.agentOptions, agentOptions);
httpAgent = new HttpAgent(config);
this.httpStore.add(httpAgent);
dereferenceOnDestroy(this.httpStore, httpAgent);
this.agents.add(httpAgent);
dereferenceOnDestroy(this.agents, httpAgent);
}

return httpAgent;
};
}

public getAgents(): Set<NetworkAgent> {
return this.agents;
}
}

const dereferenceOnDestroy = (protocolStore: Set<NetworkAgent>, agent: NetworkAgent) => {
const dereferenceOnDestroy = (store: Set<NetworkAgent>, agent: NetworkAgent) => {
const doDestroy = agent.destroy.bind(agent);
agent.destroy = () => {
protocolStore.delete(agent);
store.delete(agent);
doDestroy();
};
};
Loading

0 comments on commit a5bb487

Please sign in to comment.