-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Implement getConfig for dataset #53261
Changes from 2 commits
043ff02
bc42121
25e1e42
ac3cd52
ccf1343
d6ce56a
536668a
973aa68
74010ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import { installTemplates } from '../lib/elasticsearch/template/install'; | |
import { getPackageInfo, PackageNotInstalledError } from '../packages'; | ||
import * as Registry from '../registry'; | ||
import { Request } from '../types'; | ||
import { createInput } from '../lib/agent/agent'; | ||
|
||
export async function createDatasource(options: { | ||
savedObjectsClient: SavedObjectsClientContract; | ||
|
@@ -38,6 +39,14 @@ export async function createDatasource(options: { | |
await baseSetup(callCluster); | ||
const pkg = await Registry.fetchInfo(pkgkey); | ||
|
||
// Collect the config for each dataset | ||
const inputs: string[] = []; | ||
if (pkg.datasets) { | ||
for (const dataset of pkg.datasets) { | ||
inputs.push(await getConfig(pkgkey, dataset)); | ||
} | ||
} | ||
|
||
await Promise.all([ | ||
installTemplates(pkg, callCluster), | ||
saveDatasourceReferences({ | ||
|
@@ -47,6 +56,7 @@ export async function createDatasource(options: { | |
datasets, | ||
toSave, | ||
request, | ||
inputs, | ||
}), | ||
]); | ||
|
||
|
@@ -73,8 +83,9 @@ async function saveDatasourceReferences(options: { | |
datasourceName: string; | ||
toSave: AssetReference[]; | ||
request: Request; | ||
inputs: string[]; | ||
}) { | ||
const { savedObjectsClient, pkg, toSave, datasets, datasourceName, request } = options; | ||
const { savedObjectsClient, pkg, toSave, datasets, datasourceName, request, inputs } = options; | ||
const savedDatasource = await getDatasource({ savedObjectsClient, pkg }); | ||
const savedAssets = savedDatasource?.package.assets; | ||
const assetsReducer = (current: Asset[] = [], pending: Asset) => { | ||
|
@@ -90,6 +101,8 @@ async function saveDatasourceReferences(options: { | |
datasets, | ||
assets: toInstall, | ||
}); | ||
|
||
datasource.inputs = inputs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jfsiii I'm adding this here in the hope this also gets stored as part of the datasource which is then available for fleet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ruflin you need to update |
||
// ideally we'd call .create from /x-pack/legacy/plugins/ingest/server/libs/datasources.ts#L22 | ||
// or something similar, but it's a class not an object so many pieces are missing | ||
// we'd still need `user` from the request object, but that's not terrible | ||
|
@@ -184,3 +197,26 @@ async function ingestDatasourceCreate({ | |
}, | ||
}).then(response => response.json()); | ||
} | ||
|
||
async function getConfig(pkgkey: string, dataset: Dataset): Promise<string> { | ||
const vars = dataset.vars; | ||
|
||
// This searches for the /agent/input.yml file | ||
const paths = await Registry.getArchiveInfo(pkgkey, (entry: Registry.ArchiveEntry) => | ||
isDatasetInput(entry, dataset.name) | ||
); | ||
|
||
if (paths.length === 1) { | ||
const buffer = Registry.getAsset(paths[0]); | ||
// Load input template from path | ||
return createInput(vars, buffer.toString()); | ||
} | ||
return ''; | ||
} | ||
|
||
const isDatasetInput = ({ path }: Registry.ArchiveEntry, datasetName: string) => { | ||
const pathParts = Registry.pathParts(path); | ||
return !isDirectory({ path }) && pathParts.type === 'input' && pathParts.dataset === datasetName; | ||
}; | ||
|
||
const isDirectory = ({ path }: Registry.ArchiveEntry) => path.endsWith('/'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ export interface Datasource extends SavedObjectAttributes { | |
package: Package; | ||
read_alias?: string; | ||
streams: Stream[]; | ||
// TODO: These are the input parts of the streams. To be remove again when we have the streams | ||
inputs: string[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nchaulet My temporary hack to get the inputs into the datasource. This is an array of input configs. Each must be completed with the output to become a full stream. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ruflin what about assigning `output_id: 'default', as we only support default output for now so we can have streams directly? |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg.datasets
refers to all the datasets that come with the package whereasdatasets
are the ones the user selected.