Skip to content

Commit

Permalink
[EPM] Use Dataset interface to generate template (#52255)
Browse files Browse the repository at this point in the history
This will make sure we have to pass much feature params and can fully rely on the datasource object to create names for assets.
  • Loading branch information
ruflin authored Dec 11, 2019
1 parent 00b36c4 commit 189d375
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
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

0 comments on commit 189d375

Please sign in to comment.