Skip to content

Commit

Permalink
Merge branch 'main' into gemini-assistant-integration-latest
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jun 11, 2024
2 parents c3ef066 + e35800d commit 46592cd
Show file tree
Hide file tree
Showing 76 changed files with 972 additions and 510 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class AgentManager implements AgentFactoryProvider, AgentStatsProvider {
this.agents = new Set();
// Use DNS caching to avoid too many repetitive (and CPU-blocking) dns.lookup calls
if (options.dnsCacheTtlInSeconds > 0) {
this.logger.info(
`Caching ES host DNS resolutions for up to ${options.dnsCacheTtlInSeconds}s. If this causes problems, change the setting "elasticsearch.dnsCacheTtl: ${options.dnsCacheTtlInSeconds}s".`
);
this.cacheableLookup = new CacheableLookup({
maxTtl: options.dnsCacheTtlInSeconds,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const createConfig = (
sniffInterval: false,
requestHeadersWhitelist: ['authorization'],
hosts: ['http://localhost:80'],
dnsCacheTtlInSeconds: 0,
dnsCacheTtl: duration(0, 'seconds'),
...parts,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const createConfig = (
requestHeadersWhitelist: ['authorization'],
customHeaders: {},
hosts: ['http://localhost'],
dnsCacheTtlInSeconds: 0,
dnsCacheTtl: duration(0, 'seconds'),
...parts,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('set correct defaults', () => {
"apisToRedactInLogs": Array [],
"compression": false,
"customHeaders": Object {},
"dnsCacheTtlInSeconds": 0,
"dnsCacheTtl": "P0D",
"healthCheckDelay": "PT2.5S",
"healthCheckStartupDelay": "PT0.5S",
"hosts": Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const configSchema = schema.object({
}),
{ defaultValue: [] }
),
dnsCacheTtlInSeconds: schema.number({ defaultValue: 0, min: 0, max: Infinity }),
dnsCacheTtl: schema.duration({ defaultValue: 0, min: 0 }),
});

const deprecations: ConfigDeprecationProvider = () => [
Expand Down Expand Up @@ -429,10 +429,10 @@ export class ElasticsearchConfig implements IElasticsearchConfig {
public readonly apisToRedactInLogs: ElasticsearchApiToRedactInLogs[];

/**
* The maximum number of seconds to retain the DNS lookup resolutions.
* The maximum time to retain the DNS lookup resolutions.
* Set to 0 to disable the cache (default Node.js behavior)
*/
public readonly dnsCacheTtlInSeconds: number;
public readonly dnsCacheTtl: Duration;

constructor(rawConfig: ElasticsearchConfigType) {
this.ignoreVersionMismatch = rawConfig.ignoreVersionMismatch;
Expand All @@ -459,7 +459,7 @@ export class ElasticsearchConfig implements IElasticsearchConfig {
this.compression = rawConfig.compression;
this.skipStartupConnectionCheck = rawConfig.skipStartupConnectionCheck;
this.apisToRedactInLogs = rawConfig.apisToRedactInLogs;
this.dnsCacheTtlInSeconds = rawConfig.dnsCacheTtlInSeconds;
this.dnsCacheTtl = rawConfig.dnsCacheTtl;

const { alwaysPresentCertificate, verificationMode } = rawConfig.ssl;
const { key, keyPassphrase, certificate, certificateAuthorities } = readKeyAndCerts(rawConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,11 @@ export class ElasticsearchService
});
}

private getAgentManager({ dnsCacheTtlInSeconds }: ElasticsearchClientConfig): AgentManager {
private getAgentManager({ dnsCacheTtl }: ElasticsearchClientConfig): AgentManager {
if (!this.agentManager) {
this.agentManager = new AgentManager(this.log.get('agent-manager'), { dnsCacheTtlInSeconds });
this.agentManager = new AgentManager(this.log.get('agent-manager'), {
dnsCacheTtlInSeconds: dnsCacheTtl?.asSeconds() ?? 0, // it should always exists, but some test shortcuts and mocks break this assumption
});
}
return this.agentManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface ElasticsearchClientConfig {
caFingerprint?: string;
ssl?: ElasticsearchClientSslConfig;
apisToRedactInLogs?: ElasticsearchApiToRedactInLogs[];
dnsCacheTtlInSeconds: number;
dnsCacheTtl: Duration;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ export interface IElasticsearchConfig {
readonly apisToRedactInLogs: ElasticsearchApiToRedactInLogs[];

/**
* The maximum number of seconds to retain the DNS lookup resolutions.
* The maximum time to retain the DNS lookup resolutions.
* Set to 0 to disable the cache (default Node.js behavior)
*/
readonly dnsCacheTtlInSeconds: number;
readonly dnsCacheTtl: Duration;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/http/core-http-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export type {
RouteValidatorFullConfigRequest,
RouteValidatorFullConfigResponse,
LazyValidator,
RouteAccess,
} from './src/router';
export {
validBodyOutput,
Expand Down
1 change: 1 addition & 0 deletions packages/core/http/core-http-server/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type {
RouteConfigOptionsBody,
RouteContentType,
SafeRouteMethod,
RouteAccess,
} from './route';
export { validBodyOutput } from './route';
export type {
Expand Down
12 changes: 11 additions & 1 deletion packages/core/http/core-http-server/src/router/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ export interface RouteConfigOptionsBody {
parse?: boolean | 'gunzip';
}

/**
* Route access level.
*
* Public routes are stable and intended for external access and are subject to
* stricter change management and have long term maintenance windows.
*
* @remark On serverless access to internal routes is restricted.
*/
export type RouteAccess = 'public' | 'internal';

/**
* Additional route options.
* @public
Expand Down Expand Up @@ -133,7 +143,7 @@ export interface RouteConfigOptions<Method extends RouteMethod> {
*
* Defaults to 'internal' If not declared,
*/
access?: 'public' | 'internal';
access?: RouteAccess;

/**
* Additional metadata tag strings to attach to the route.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '@kbn/config-schema';
import type { RouteAccess } from '@kbn/core-http-server';
import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
Expand All @@ -21,16 +22,21 @@ interface RouteDependencies {
config: SavedObjectConfig;
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
access: RouteAccess;
}

export const registerBulkCreateRoute = (
router: InternalSavedObjectRouter,
{ config, coreUsageData, logger }: RouteDependencies
{ config, coreUsageData, logger, access }: RouteDependencies
) => {
const { allowHttpApiAccess } = config;
router.post(
{
path: '/_bulk_create',
options: {
access,
description: `Create saved objects`,
},
validate: {
query: schema.object({
overwrite: schema.boolean({ defaultValue: false }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '@kbn/config-schema';
import type { RouteAccess } from '@kbn/core-http-server';
import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
Expand All @@ -21,16 +22,21 @@ interface RouteDependencies {
config: SavedObjectConfig;
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
access: RouteAccess;
}

export const registerBulkDeleteRoute = (
router: InternalSavedObjectRouter,
{ config, coreUsageData, logger }: RouteDependencies
{ config, coreUsageData, logger, access }: RouteDependencies
) => {
const { allowHttpApiAccess } = config;
router.post(
{
path: '/_bulk_delete',
options: {
access,
description: `Remove saved objects`,
},
validate: {
body: schema.arrayOf(
schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '@kbn/config-schema';
import type { RouteAccess } from '@kbn/core-http-server';
import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
Expand All @@ -21,16 +22,21 @@ interface RouteDependencies {
config: SavedObjectConfig;
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
access: RouteAccess;
}

export const registerBulkGetRoute = (
router: InternalSavedObjectRouter,
{ config, coreUsageData, logger }: RouteDependencies
{ config, coreUsageData, logger, access }: RouteDependencies
) => {
const { allowHttpApiAccess } = config;
router.post(
{
path: '/_bulk_get',
options: {
access,
description: `Get saved objects`,
},
validate: {
body: schema.arrayOf(
schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '@kbn/config-schema';
import type { RouteAccess } from '@kbn/core-http-server';
import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
Expand All @@ -21,16 +22,21 @@ interface RouteDependencies {
config: SavedObjectConfig;
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
access: RouteAccess;
}

export const registerBulkResolveRoute = (
router: InternalSavedObjectRouter,
{ config, coreUsageData, logger }: RouteDependencies
{ config, coreUsageData, logger, access }: RouteDependencies
) => {
const { allowHttpApiAccess } = config;
router.post(
{
path: '/_bulk_resolve',
options: {
access,
description: `Resolve saved objects`,
},
validate: {
body: schema.arrayOf(
schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '@kbn/config-schema';
import type { RouteAccess } from '@kbn/core-http-server';
import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
Expand All @@ -21,16 +22,21 @@ interface RouteDependencies {
config: SavedObjectConfig;
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
access: RouteAccess;
}

export const registerBulkUpdateRoute = (
router: InternalSavedObjectRouter,
{ config, coreUsageData, logger }: RouteDependencies
{ config, coreUsageData, logger, access }: RouteDependencies
) => {
const { allowHttpApiAccess } = config;
router.put(
{
path: '/_bulk_update',
options: {
access,
description: `Update saved objects`,
},
validate: {
body: schema.arrayOf(
schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '@kbn/config-schema';
import type { RouteAccess } from '@kbn/core-http-server';
import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
Expand All @@ -21,16 +22,21 @@ interface RouteDependencies {
config: SavedObjectConfig;
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
access: RouteAccess;
}

export const registerCreateRoute = (
router: InternalSavedObjectRouter,
{ config, coreUsageData, logger }: RouteDependencies
{ config, coreUsageData, logger, access }: RouteDependencies
) => {
const { allowHttpApiAccess } = config;
router.post(
{
path: '/{type}/{id?}',
options: {
access,
description: `Create a saved object`,
},
validate: {
params: schema.object({
type: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { schema } from '@kbn/config-schema';
import type { RouteAccess } from '@kbn/core-http-server';
import { SavedObjectConfig } from '@kbn/core-saved-objects-base-server-internal';
import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal';
import type { Logger } from '@kbn/logging';
Expand All @@ -21,16 +22,21 @@ interface RouteDependencies {
config: SavedObjectConfig;
coreUsageData: InternalCoreUsageDataSetup;
logger: Logger;
access: RouteAccess;
}

export const registerDeleteRoute = (
router: InternalSavedObjectRouter,
{ config, coreUsageData, logger }: RouteDependencies
{ config, coreUsageData, logger, access }: RouteDependencies
) => {
const { allowHttpApiAccess } = config;
router.delete(
{
path: '/{type}/{id}',
options: {
access,
description: `Delete a saved object`,
},
validate: {
params: schema.object({
type: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export const registerExportRoute = (
router.post(
{
path: '/_export',
options: {
access: 'public',
description: `Export saved objects`,
},
validate: {
body: schema.object({
type: schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())])),
Expand Down
Loading

0 comments on commit 46592cd

Please sign in to comment.