Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EPM] Use Dataset interface to generate template #52255

Merged
merged 3 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/epm/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export interface Dataset {
ingeset_pipeline: string;
vars: object[];
type: string;
// This is for convenience and not in the output from the registry. When creating a dataset, this info should be added.
package: string;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const isFields = (path: string) => {
* The template is currently loaded with the pkgey-package-dataset
*/
export async function installTemplates(pkg: RegistryPackage, callCluster: CallESAsCurrentUser) {
// If no datasets exist in this package, no templates have to be installed.
if (!pkg.datasets) return;

const promises = pkg.datasets.map(async dataset => {
return pkg.datasets.map(async dataset => {
// Fetch all assset entries for this dataset
const assetEntries = await getAssetsData(pkg, isFields, dataset.name);

Expand All @@ -38,25 +39,21 @@ export async function installTemplates(pkg: RegistryPackage, callCluster: CallES
}
}

return installTemplate({ callCluster, fields, pkg, dataset });
return installTemplate({ callCluster, fields, dataset });
});

return Promise.all(promises);
}

async function installTemplate({
callCluster,
fields,
pkg,
dataset,
}: {
callCluster: CallESAsCurrentUser;
fields: Field[];
pkg: RegistryPackage;
dataset: Dataset;
}): Promise<AssetReference> {
const mappings = generateMappings(fields);
const templateName = generateTemplateName(pkg.name, dataset.name, dataset.type);
const templateName = generateTemplateName(dataset);
const template = getTemplate(templateName + '-*', mappings);
// TODO: Check return values for errors
await callCluster('indices.putTemplate', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

import { Field } from '../../fields/field';
import { Dataset } from '../../../../common/types';
import { getDatasetAssetBaseName } from '../index';

export interface Template {
order: number;
Expand Down Expand Up @@ -58,13 +60,8 @@ export function generateMappings(fields: Field[]): Mappings {
/**
* Generates the template name out of the given information
*/
export function generateTemplateName(
packageName: string,
datasetName: string,
type: string
): string {
// TODO: This is only a temporary name. More info like dataset type is needed to create full name
return type + '-' + packageName + '-' + datasetName;
export function generateTemplateName(dataset: Dataset): string {
return getDatasetAssetBaseName(dataset);
}

function getBaseTemplate(mappings: Mappings): Template {
Expand Down Expand Up @@ -118,16 +115,6 @@ function getBaseTemplate(mappings: Mappings): Template {
match_mapping_type: 'string',
},
},
// Example of a dynamic template
{
labels: {
path_match: 'labels.*',
mapping: {
type: 'keyword',
},
match_mapping_type: 'string',
},
},
],
// As we define fields ahead, we don't need any automatic field detection
// This makes sure all the fields are mapped to keyword by default to prevent mapping conflicts
Expand Down