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

[Logs onboarding] Generate elastic-agent.yml file for system logs #162972

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function InstallElasticAgent() {
params: {
body: {
name: datasetName,
type: 'logFiles',
state: {
datasetName,
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export function InstallElasticAgent() {
const [elasticAgentPlatform, setElasticAgentPlatform] =
useState<ElasticAgentPlatform>('linux-tar');

const datasetName = 'elastic-agent';
const namespace = 'default';
const datasetName = 'system-logs';

function onBack() {
navigateToKibanaUrl('/app/observabilityOnboarding');
Expand Down Expand Up @@ -83,10 +82,7 @@ export function InstallElasticAgent() {
params: {
body: {
name: datasetName,
state: {
datasetName,
namespace,
},
type: 'systemLogs',
},
},
});
Expand All @@ -95,26 +91,6 @@ export function InstallElasticAgent() {
[monitoringRole?.hasPrivileges]
);

const { status: saveOnboardingStateDataStatus } = useFetcher((callApi) => {
const { onboardingId } = getState();
if (onboardingId) {
return callApi(
'PUT /internal/observability_onboarding/flow/{onboardingId}',
{
params: {
path: { onboardingId },
body: {
state: {
datasetName,
namespace,
},
},
},
}
);
}
}, []);

const { apiKeyEncoded, onboardingId } = installShipperSetup ?? getState();

const { data: yamlConfig = '', status: yamlConfigStatus } = useFetcher(
Expand All @@ -132,7 +108,7 @@ export function InstallElasticAgent() {
[
apiKeyEncoded,
onboardingId,
saveOnboardingStateDataStatus === FETCH_STATUS.SUCCESS,
installShipperSetupStatus === FETCH_STATUS.SUCCESS,
]
);

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 @@ -6,7 +6,7 @@
*/

import { dump } from 'js-yaml';
import { generateYml } from './generate_yml';
import { generateCustomLogsYml } from './generate_custom_logs_yml';

const baseMockConfig = {
datasetName: 'my-dataset',
Expand All @@ -17,9 +17,9 @@ const baseMockConfig = {
logfileId: 'my-logs-id',
};

describe('generateYml', () => {
describe('generateCustomLogsYml', () => {
it('should return a basic yml configuration', () => {
const result = generateYml(baseMockConfig);
const result = generateCustomLogsYml(baseMockConfig);
expect(result).toMatchSnapshot();
});

Expand All @@ -29,7 +29,7 @@ describe('generateYml', () => {
logFilePaths: ['/my-service-1.logs', '/my-service-2.logs'],
};

const result = generateYml(mockConfig);
const result = generateCustomLogsYml(mockConfig);
expect(result).toMatchSnapshot();
});

Expand All @@ -39,7 +39,7 @@ describe('generateYml', () => {
serviceName: 'my-service',
};

const result = generateYml(mockConfig);
const result = generateCustomLogsYml(mockConfig);
expect(result).toMatchSnapshot();
});

Expand All @@ -57,7 +57,7 @@ describe('generateYml', () => {
}),
};

const result = generateYml(mockConfig);
const result = generateCustomLogsYml(mockConfig);
expect(result).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { dump, load } from 'js-yaml';

export const generateYml = ({
export const generateCustomLogsYml = ({
datasetName = '',
serviceName,
namespace = '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
*/

import * as t from 'io-ts';
import { v4 as uuidv4 } from 'uuid';
import { getAuthenticationAPIKey } from '../../lib/get_authentication_api_key';
import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route';
import { generateYml } from './generate_yml';
import { getFallbackESUrl } from '../../lib/get_fallback_urls';
import { getObservabilityOnboardingFlow } from '../../lib/state';
import { createObservabilityOnboardingServerRoute } from '../create_observability_onboarding_server_route';
import { generateCustomLogsYml } from './custom_logs/generate_custom_logs_yml';
import { generateSystemLogsYml } from './system_logs/generate_system_logs_yml';

const generateConfig = createObservabilityOnboardingServerRoute({
endpoint: 'GET /internal/observability_onboarding/elastic_agent/config',
Expand Down Expand Up @@ -43,18 +45,24 @@ const generateConfig = createObservabilityOnboardingServerRoute({
savedObjectId: onboardingId,
});

const yaml = generateYml({
datasetName: savedState?.state?.datasetName,
customConfigurations: savedState?.state?.customConfigurations,
logFilePaths: savedState?.state?.logFilePaths,
namespace: savedState?.state?.namespace,
apiKey: authApiKey
? `${authApiKey?.apiKeyId}:${authApiKey?.apiKey}`
: '$API_KEY',
esHost: elasticsearchUrl,
logfileId: `custom-logs-${Date.now()}`,
serviceName: savedState?.state?.serviceName,
});
const yaml =
savedState?.type === 'systemLogs'
? generateSystemLogsYml({
...savedState?.state,
apiKey: authApiKey
? `${authApiKey?.apiKeyId}:${authApiKey?.apiKey}`
: '$API_KEY',
esHost: elasticsearchUrl,
uuid: uuidv4(),
})
: generateCustomLogsYml({
...savedState?.state,
apiKey: authApiKey
? `${authApiKey?.apiKeyId}:${authApiKey?.apiKey}`
: '$API_KEY',
esHost: elasticsearchUrl,
logfileId: `custom-logs-${uuidv4()}`,
});

return yaml;
},
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
@@ -0,0 +1,22 @@
/*
* 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 { generateSystemLogsYml } from './generate_system_logs_yml';

const baseMockConfig = {
namespace: 'default',
apiKey: 'elastic:changeme',
esHost: ['http://localhost:9200'],
uuid: '8df0ff52-6f3b-4b5a-a2da-f06c55d111d1',
};

describe('generateSystemLogsYml', () => {
it('should return system logs oriented yml configuration', () => {
const result = generateSystemLogsYml(baseMockConfig);
expect(result).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 { dump } from 'js-yaml';

export const generateSystemLogsYml = ({
namespace = 'default',
apiKey,
esHost,
uuid,
}: {
namespace?: string;
apiKey: string;
esHost: string[];
uuid: string;
}) => {
return dump({
outputs: {
default: {
type: 'elasticsearch',
hosts: esHost,
api_key: apiKey,
},
},
inputs: [
{
id: `system-logs-${uuid}`,
type: 'logfile',
data_stream: {
namespace,
},
streams: [
{
id: `logfile-system.auth-${uuid}`,
data_stream: {
dataset: 'system.auth',
type: 'logs',
},
paths: ['/var/log/auth.log*', '/var/log/secure*'],
exclude_files: ['.gz$'],
multiline: {
pattern: '^s',
match: 'after',
},
tags: ['system-auth'],
processors: [
{
add_locale: null,
},
],
},
{
id: `logfile-system.syslog-${uuid}`,
data_stream: {
dataset: 'system.syslog',
type: 'logs',
},
paths: [
'/var/log/messages*',
'/var/log/syslog*',
'/var/log/system*',
],
exclude_files: ['.gz$'],
multiline: {
pattern: '^s',
match: 'after',
},
processors: [
{
add_locale: null,
},
],
},
],
},
],
});
};
Loading
Loading