-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Install a default ingest pipeline for datastreams without pip…
…eline
- Loading branch information
Showing
6 changed files
with
140 additions
and
75 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ElasticsearchAssetType } from '../../../../types'; | ||
import type { RegistryDataStream } from '../../../../types'; | ||
import { getPathParts } from '../../archive'; | ||
|
||
export const isTopLevelPipeline = (path: string) => { | ||
const pathParts = getPathParts(path); | ||
return ( | ||
pathParts.type === ElasticsearchAssetType.ingestPipeline && pathParts.dataset === undefined | ||
); | ||
}; | ||
|
||
export const getPipelineNameForInstallation = ({ | ||
pipelineName, | ||
dataStream, | ||
packageVersion, | ||
}: { | ||
pipelineName: string; | ||
dataStream?: RegistryDataStream; | ||
packageVersion: string; | ||
}): string => { | ||
if (dataStream !== undefined) { | ||
const isPipelineEntry = pipelineName === dataStream.ingest_pipeline; | ||
const suffix = isPipelineEntry ? '' : `-${pipelineName}`; | ||
// if this is the pipeline entry, don't add a suffix | ||
return `${getPipelineNameForDatastream({ dataStream, packageVersion })}${suffix}`; | ||
} | ||
// It's a top-level pipeline | ||
return `${packageVersion}-${pipelineName}`; | ||
}; | ||
|
||
export const getPipelineNameForDatastream = ({ | ||
dataStream, | ||
packageVersion, | ||
}: { | ||
dataStream: RegistryDataStream; | ||
packageVersion: string; | ||
}): string => { | ||
return `${dataStream.type}-${dataStream.dataset}-${packageVersion}`; | ||
}; | ||
|
||
export interface RewriteSubstitution { | ||
source: string; | ||
target: string; | ||
templateFunction: string; | ||
} | ||
|
||
export function rewriteIngestPipeline( | ||
pipeline: string, | ||
substitutions: RewriteSubstitution[] | ||
): string { | ||
substitutions.forEach((sub) => { | ||
const { source, target, templateFunction } = sub; | ||
// This fakes the use of the golang text/template expression {{SomeTemplateFunction 'some-param'}} | ||
// cf. https://github.com/elastic/beats/blob/master/filebeat/fileset/fileset.go#L294 | ||
|
||
// "Standard style" uses '{{' and '}}' as delimiters | ||
const matchStandardStyle = `{{\\s?${templateFunction}\\s+['"]${source}['"]\\s?}}`; | ||
// "Beats style" uses '{<' and '>}' as delimiters because this is current practice in the beats project | ||
const matchBeatsStyle = `{<\\s?${templateFunction}\\s+['"]${source}['"]\\s?>}`; | ||
|
||
const regexStandardStyle = new RegExp(matchStandardStyle); | ||
const regexBeatsStyle = new RegExp(matchBeatsStyle); | ||
pipeline = pipeline.replace(regexStandardStyle, target).replace(regexBeatsStyle, target); | ||
}); | ||
return pipeline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters