forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Observability Onboarding] Split Agent config into multiple files (el…
…astic#191241) Resolves elastic#191917 ## Summary Splits up the Agent config generated during auto-detect based onboarding into multiple files. This makes it easier for users to make changes following the initial onboarding. The backup feature has also been updated to include files inside `inputs.d` directory. ## Example Before this change the auto-detect script would write all settings to `elastic-agent.yml` file. After this change the script writes one separate config file for each integrations that was detected, for example: 1. `elastic-agent.yml` - Contains global settings 2. `inputs.d/system.yml` - Contains inputs config for System integration 3. `inputs.d/docker.yml` - Contains inputs config for Docker integration ## Screenshot <img width="1039" alt="Screenshot 2024-08-23 at 16 49 34" src="https://github.com/user-attachments/assets/17bb7b01-d40e-4491-8bb5-20daf115938a">
- Loading branch information
1 parent
a0cc891
commit d14432e
Showing
10 changed files
with
434 additions
and
75 deletions.
There are no files selected for viewing
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
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
71 changes: 71 additions & 0 deletions
71
...ugins/observability_solution/observability_onboarding/server/routes/flow/make_tar.test.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,71 @@ | ||
/* | ||
* 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 { makeTar, type Entry } from './make_tar'; | ||
import * as tar from 'tar'; | ||
import expect from 'expect'; | ||
|
||
describe('makeTar', () => { | ||
it('creates a valid tar archive that can be extracted', () => { | ||
const archive = makeTar([ | ||
{ | ||
type: 'Directory', | ||
path: 'inputs.d/', | ||
mode: 0o755, | ||
}, | ||
{ | ||
type: 'File', | ||
path: 'inputs.d/system.yml', | ||
mode: 0o644, | ||
data: 's'.repeat(512), | ||
}, | ||
{ | ||
type: 'File', | ||
path: 'inputs.d/redis.yml', | ||
mode: 0o644, | ||
data: 'r'.repeat(1024), | ||
}, | ||
]); | ||
|
||
const extracted: Entry[] = []; | ||
tar | ||
.extract({ | ||
sync: true, | ||
onReadEntry: (readEntry) => { | ||
const entry: Entry = readEntry; | ||
readEntry.on('data', (buffer) => { | ||
if (!entry.data) { | ||
entry.data = ''; | ||
} | ||
entry.data += buffer.toString(); | ||
}); | ||
extracted.push(entry); | ||
}, | ||
}) | ||
.write(archive); | ||
|
||
expect(extracted).toEqual([ | ||
expect.objectContaining({ | ||
type: 'Directory', | ||
path: 'inputs.d/', | ||
mode: 0o755, | ||
}), | ||
expect.objectContaining({ | ||
type: 'File', | ||
path: 'inputs.d/system.yml', | ||
mode: 0o644, | ||
data: 's'.repeat(512), | ||
}), | ||
expect.objectContaining({ | ||
type: 'File', | ||
path: 'inputs.d/redis.yml', | ||
mode: 0o644, | ||
data: 'r'.repeat(1024), | ||
}), | ||
]); | ||
}); | ||
}); |
69 changes: 69 additions & 0 deletions
69
...ck/plugins/observability_solution/observability_onboarding/server/routes/flow/make_tar.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,69 @@ | ||
/* | ||
* 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 { Header, type HeaderData } from 'tar'; | ||
|
||
const BLOCK_SIZE = 512; // https://www.gnu.org/software/tar/manual/html_node/Standard.html | ||
|
||
export interface Entry extends Omit<HeaderData, 'size'> { | ||
data?: string; | ||
} | ||
|
||
/** | ||
* Creates a tar archive from a list of entries in memory. | ||
* | ||
* Ensure you set the appropriate permissions (`0o755` for directories and `0o644` for files) or the | ||
* extracted files won't be readable. | ||
* | ||
* Example: | ||
* | ||
* ```ts | ||
* const now = new Date(); | ||
* const archive = makeTar([ | ||
* { | ||
* type: 'Directory', | ||
* path: 'inputs.d/', | ||
* mode: 0o755, | ||
* mtime: now, | ||
* }, | ||
* { | ||
* type: 'File', | ||
* path: 'inputs.d/redis.yml', | ||
* mode: 0o644, | ||
* mtime: now, | ||
* data: 'inputs:\n- type: logs', | ||
* }, | ||
* ] | ||
* ``` | ||
*/ | ||
export function makeTar(entries: Entry[]) { | ||
// A tar archive contains a series of blocks. Each block contains 512 bytes. Each file archived is | ||
// represented by a header block which describes the file, followed by zero or more blocks which | ||
// give the contents of the file. | ||
const blocks = entries.map((entry) => { | ||
const size = typeof entry.data === 'string' ? entry.data.length : 0; | ||
const buffer = Buffer.alloc(BLOCK_SIZE * (Math.ceil(size / BLOCK_SIZE) + 1)); | ||
|
||
// Write header into first block | ||
const header = new Header({ ...entry, size }); | ||
header.encode(buffer, 0); | ||
|
||
// Write data into subsequent blocks | ||
if (typeof entry.data === 'string') { | ||
buffer.write(entry.data, BLOCK_SIZE); | ||
} | ||
|
||
return buffer; | ||
}); | ||
|
||
// At the end of the archive file there are two 512-byte blocks filled with binary zeros as an | ||
// end-of-file marker. | ||
const eof = Buffer.alloc(2 * BLOCK_SIZE); | ||
blocks.push(eof); | ||
|
||
return Buffer.concat(blocks); | ||
} |
Oops, something went wrong.