Skip to content

Commit

Permalink
Add support for allow_routing data stream option
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Oct 11, 2022
1 parent 782e5de commit d67bef4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from './policy_template';

type PackagePolicyStream = RegistryStream & { release?: 'beta' | 'experimental' | 'ga' } & {
data_stream: { type: string; dataset: string };
data_stream: { type: string; dataset: string; allow_routing?: boolean };
};

export const getStreamsForInputType = (
Expand All @@ -47,6 +47,7 @@ export const getStreamsForInputType = (
data_stream: {
type: dataStream.type,
dataset: dataStream.dataset,
allow_routing: dataStream.allow_routing,
},
release: dataStream.release,
});
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/data_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface DataStream {
dataset: string;
namespace: string;
type: string;
allow_routing: boolean;
package: string;
package_version: string;
last_activity_ms: number;
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@ export enum RegistryDataStreamKeys {
ingest_pipeline = 'ingest_pipeline',
elasticsearch = 'elasticsearch',
dataset_is_prefix = 'dataset_is_prefix',
allow_routing = 'allow_routing',
}

export interface RegistryDataStream {
[key: string]: any;
[key: string]: unknown;
[RegistryDataStreamKeys.type]: string;
[RegistryDataStreamKeys.ilm_policy]?: string;
[RegistryDataStreamKeys.hidden]?: boolean;
Expand All @@ -344,6 +345,7 @@ export interface RegistryDataStream {
[RegistryDataStreamKeys.ingest_pipeline]?: string;
[RegistryDataStreamKeys.elasticsearch]?: RegistryElasticsearch;
[RegistryDataStreamKeys.dataset_is_prefix]?: boolean;
[RegistryDataStreamKeys.allow_routing]?: boolean;
}

export interface RegistryElasticsearch {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface NewPackagePolicyInputStream {
data_stream: {
dataset: string;
type: string;
allow_routing?: boolean;
elasticsearch?: {
privileges?: {
indices?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export async function storedPackagePoliciesToAgentPermissions(
type: stream.data_stream.type,
dataset:
stream.compiled_stream?.data_stream?.dataset ?? stream.data_stream.dataset,
allow_routing: stream.data_stream.allow_routing,
};

if (stream.data_stream.elasticsearch) {
Expand Down Expand Up @@ -140,6 +141,7 @@ interface DataStreamMeta {
dataset: string;
dataset_is_prefix?: boolean;
hidden?: boolean;
allow_routing?: boolean;
elasticsearch?: {
privileges?: RegistryDataStreamPrivileges;
};
Expand All @@ -158,6 +160,10 @@ export function getDataStreamPrivileges(dataStream: DataStreamMeta, namespace: s

index += `-${namespace}`;

if (dataStream.allow_routing) {
index = `${dataStream.type}-*-*`;
}

const privileges = dataStream?.elasticsearch?.privileges?.indices?.length
? dataStream.elasticsearch.privileges.indices
: PACKAGE_POLICY_DEFAULT_INDEX_PRIVILEGES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ title: Test Dataset

type: logs

allow_routing: true

elasticsearch:
index_template.mappings:
dynamic: true
Expand Down

0 comments on commit d67bef4

Please sign in to comment.