Skip to content

Commit

Permalink
[Fleet] Allow to preconfigure alternative ES outputs (on the same clu…
Browse files Browse the repository at this point in the history
…ster) (#111002)
  • Loading branch information
nchaulet authored Sep 21, 2021
1 parent 5408a3e commit 659b295
Show file tree
Hide file tree
Showing 24 changed files with 1,517 additions and 373 deletions.
16 changes: 16 additions & 0 deletions docs/settings/fleet-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Optional properties are:
be changed by updating the {kib} config.
`is_default`:: If `true`, this policy is the default agent policy.
`is_default_fleet_server`:: If `true`, this policy is the default {fleet-server} agent policy.
`data_output_id`:: ID of the output to send data (Need to be identical to `monitoring_output_id`)
`monitoring_output_id`:: ID of the output to send monitoring data. (Need to be identical to `data_output_id`)
`package_policies`:: List of integration policies to add to this policy.
`name`::: (required) Name of the integration policy.
`package`::: (required) Integration that this policy configures
Expand All @@ -96,6 +98,20 @@ Optional properties are:
integration. Follows the same schema as integration inputs, with the
exception that any object in `vars` can be passed `frozen: true` in order to
prevent that specific `var` from being edited by the user.

| `xpack.fleet.outputs`
| List of ouputs that are configured when the {fleet} app starts.
Required properties are:

`id`:: Unique ID for this output. The ID should be a string.
`name`:: Output name.
`type`:: Type of Output. Currently we only support "elasticsearch".
`hosts`:: Array that contains the list of host for that output.
`config`:: Extra config for that output.

Optional properties are:

`is_default`:: If `true`, this output is the default output.
|===

Example configuration:
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/common/constants/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const outputType = {
Elasticsearch: 'elasticsearch',
} as const;

export const DEFAULT_OUTPUT_ID = 'default';

export const DEFAULT_OUTPUT: NewOutput = {
name: 'default',
name: DEFAULT_OUTPUT_ID,
is_default: true,
type: outputType.Elasticsearch,
hosts: [''],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type { PackagePolicy, FullAgentPolicyInput, FullAgentPolicyInputStream }
import { DEFAULT_OUTPUT } from '../constants';

export const storedPackagePoliciesToAgentInputs = (
packagePolicies: PackagePolicy[]
packagePolicies: PackagePolicy[],
outputId: string = DEFAULT_OUTPUT.name
): FullAgentPolicyInput[] => {
const fullInputs: FullAgentPolicyInput[] = [];

Expand All @@ -32,7 +33,7 @@ export const storedPackagePoliciesToAgentInputs = (
data_stream: {
namespace: packagePolicy.namespace || 'default',
},
use_output: DEFAULT_OUTPUT.name,
use_output: outputId,
...(input.compiled_input || {}),
...(input.streams.length
? {
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
export * from './models';
export * from './rest_spec';

import type { PreconfiguredAgentPolicy, PreconfiguredPackage } from './models/preconfiguration';
import type {
PreconfiguredAgentPolicy,
PreconfiguredPackage,
PreconfiguredOutput,
} from './models/preconfiguration';

export interface FleetConfigType {
enabled: boolean;
Expand All @@ -26,6 +30,7 @@ export interface FleetConfigType {
};
agentPolicies?: PreconfiguredAgentPolicy[];
packages?: PreconfiguredPackage[];
outputs?: PreconfiguredOutput[];
agentIdVerificationEnabled?: boolean;
}

Expand Down
10 changes: 7 additions & 3 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface NewAgentPolicy {
monitoring_enabled?: MonitoringType;
unenroll_timeout?: number;
is_preconfigured?: boolean;
data_output_id?: string;
monitoring_output_id?: string;
}

export interface AgentPolicy extends NewAgentPolicy {
Expand Down Expand Up @@ -71,12 +73,14 @@ export interface FullAgentPolicyOutputPermissions {
};
}

export type FullAgentPolicyOutput = Pick<Output, 'type' | 'hosts' | 'ca_sha256' | 'api_key'> & {
[key: string]: any;
};

export interface FullAgentPolicy {
id: string;
outputs: {
[key: string]: Pick<Output, 'type' | 'hosts' | 'ca_sha256' | 'api_key'> & {
[key: string]: any;
};
[key: string]: FullAgentPolicyOutput;
};
output_permissions?: {
[output: string]: FullAgentPolicyOutputPermissions;
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/fleet/common/types/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export interface NewOutput {
hosts?: string[];
ca_sha256?: string;
api_key?: string;
config?: Record<string, any>;
config_yaml?: string;
is_preconfigured?: boolean;
}

export type OutputSOAttributes = NewOutput;
export type OutputSOAttributes = NewOutput & {
output_id?: string;
};

export type Output = NewOutput & {
id: string;
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/fleet/common/types/models/preconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
NewPackagePolicyInput,
} from './package_policy';
import type { NewAgentPolicy } from './agent_policy';
import type { Output } from './output';

export type InputsOverride = Partial<NewPackagePolicyInput> & {
vars?: Array<NewPackagePolicyInput['vars'] & { name: string }>;
Expand All @@ -29,3 +30,7 @@ export interface PreconfiguredAgentPolicy extends Omit<NewAgentPolicy, 'namespac
}

export type PreconfiguredPackage = Omit<PackagePolicyPackage, 'title'>;

export interface PreconfiguredOutput extends Omit<Output, 'config_yaml'> {
config?: Record<string, unknown>;
}
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/errors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export function isESClientError(error: unknown): error is ResponseError {
return error instanceof ResponseError;
}

export const isElasticsearchVersionConflictError = (error: Error): boolean => {
export function isElasticsearchVersionConflictError(error: Error): boolean {
return isESClientError(error) && error.meta.statusCode === 409;
};
}
7 changes: 6 additions & 1 deletion x-pack/plugins/fleet/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { schema } from '@kbn/config-schema';
import type { TypeOf } from '@kbn/config-schema';
import type { PluginConfigDescriptor, PluginInitializerContext } from 'src/core/server';

import { PreconfiguredPackagesSchema, PreconfiguredAgentPoliciesSchema } from './types';
import {
PreconfiguredPackagesSchema,
PreconfiguredAgentPoliciesSchema,
PreconfiguredOutputsSchema,
} from './types';

import { FleetPlugin } from './plugin';

Expand Down Expand Up @@ -113,6 +117,7 @@ export const config: PluginConfigDescriptor = {
}),
packages: PreconfiguredPackagesSchema,
agentPolicies: PreconfiguredAgentPoliciesSchema,
outputs: PreconfiguredOutputsSchema,
agentIdVerificationEnabled: schema.boolean({ defaultValue: true }),
}),
};
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ const getSavedObjectTypes = (
revision: { type: 'integer' },
monitoring_enabled: { type: 'keyword', index: false },
is_preconfigured: { type: 'keyword' },
data_output_id: { type: 'keyword' },
monitoring_output_id: { type: 'keyword' },
},
},
migrations: {
Expand Down Expand Up @@ -196,13 +198,15 @@ const getSavedObjectTypes = (
},
mappings: {
properties: {
output_id: { type: 'keyword', index: false },
name: { type: 'keyword' },
type: { type: 'keyword' },
is_default: { type: 'boolean' },
hosts: { type: 'keyword' },
ca_sha256: { type: 'keyword', index: false },
config: { type: 'flattened' },
config_yaml: { type: 'text' },
is_preconfigured: { type: 'boolean', index: false },
},
},
migrations: {
Expand Down
Loading

0 comments on commit 659b295

Please sign in to comment.