Skip to content

Commit

Permalink
[Onboarding][Firehose] Switch to the latest CloudFormation template (e…
Browse files Browse the repository at this point in the history
…lastic#204185)

Closes elastic#203563

Updates the CF template to the latest available version and adjust the
code to use a single Firehose stream created by the new template.

You can use `Elastic Observability` AWS account (available through Okta)
and the latest Kibana deployment from this PR to test the flow.

![CleanShot 2024-12-17 at 11 42
33@2x](https://github.com/user-attachments/assets/ac9ba9eb-1c9f-48fb-9fca-ed518970ac9b)
  • Loading branch information
mykolaharmash authored Jan 2, 2025
1 parent e5cf28b commit db083d1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
* 2.0.
*/

export const FIREHOSE_CLOUDFORMATION_STACK_NAME = 'Elastic-CloudwatchLogsAndMetricsToFirehose';
export const FIREHOSE_LOGS_STREAM_NAME = 'Elastic-CloudwatchLogs';
export const FIREHOSE_METRICS_STREAM_NAME = 'Elastic-CloudwatchMetrics';
export const FIREHOSE_CLOUDFORMATION_STACK_NAME = 'Elastic-Firehose';
export const FIREHOSE_STREAM_NAME = 'Elastic-Cloudwatch';

export const FIREHOSE_CLOUDFORMATION_TEMPLATE_URL =
'https://elastic-cloudformation-templates.s3.amazonaws.com/v0.1.0/firehose_default_start.yml';
'https://elastic-cloudformation-templates.s3.amazonaws.com/v0.5.0/firehose_default_start.yml';

export const AWS_INDEX_NAME_LIST = [
// Logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import {
FIREHOSE_CLOUDFORMATION_STACK_NAME,
FIREHOSE_LOGS_STREAM_NAME,
FIREHOSE_METRICS_STREAM_NAME,
FIREHOSE_STREAM_NAME,
} from '../../../../common/aws_firehose';
import { CopyToClipboardButton } from '../shared/copy_to_clipboard_button';
import { DownloadTemplateCallout } from './download_template_callout';
Expand All @@ -42,8 +41,7 @@ export function CreateStackCommandSnippet({
const createStackCommand = buildCreateStackCommand({
templateUrl,
stackName: FIREHOSE_CLOUDFORMATION_STACK_NAME,
logsStreamName: FIREHOSE_LOGS_STREAM_NAME,
metricsStreamName: FIREHOSE_METRICS_STREAM_NAME,
streamName: FIREHOSE_STREAM_NAME,
encodedApiKey,
elasticsearchUrl,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import {
FIREHOSE_CLOUDFORMATION_STACK_NAME,
FIREHOSE_LOGS_STREAM_NAME,
FIREHOSE_METRICS_STREAM_NAME,
FIREHOSE_STREAM_NAME,
} from '../../../../common/aws_firehose';
import { DownloadTemplateCallout } from './download_template_callout';
import { buildCreateStackAWSConsoleURL } from './utils';
Expand All @@ -33,8 +32,7 @@ export function CreateStackInAWSConsole({
const awsConsoleURL = buildCreateStackAWSConsoleURL({
templateUrl,
stackName: FIREHOSE_CLOUDFORMATION_STACK_NAME,
logsStreamName: FIREHOSE_LOGS_STREAM_NAME,
metricsStreamName: FIREHOSE_METRICS_STREAM_NAME,
streamName: FIREHOSE_STREAM_NAME,
elasticsearchUrl,
encodedApiKey,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import { useFetcher } from '../../../hooks/use_fetcher';
import {
FIREHOSE_CLOUDFORMATION_STACK_NAME,
FIREHOSE_LOGS_STREAM_NAME,
FIREHOSE_STREAM_NAME,
} from '../../../../common/aws_firehose';

export function usePopulatedAWSIndexList() {
return useFetcher((callApi) => {
return callApi('GET /internal/observability_onboarding/firehose/has-data', {
params: {
query: {
logsStreamName: FIREHOSE_LOGS_STREAM_NAME,
streamName: FIREHOSE_STREAM_NAME,
stackName: FIREHOSE_CLOUDFORMATION_STACK_NAME,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ export const HAS_DATA_FETCH_INTERVAL = 5000;
export function buildCreateStackCommand({
templateUrl,
stackName,
logsStreamName,
metricsStreamName,
streamName,
encodedApiKey,
elasticsearchUrl,
}: {
templateUrl: string;
stackName: string;
logsStreamName: string;
metricsStreamName: string;
streamName: string;
encodedApiKey: string;
elasticsearchUrl: string;
}) {
Expand All @@ -29,8 +27,7 @@ export function buildCreateStackCommand({
aws cloudformation create-stack
--stack-name ${stackName}
--template-url ${escapedTemplateUrl}
--parameters ParameterKey=FirehoseStreamNameForLogs,ParameterValue=${logsStreamName}
ParameterKey=FirehoseStreamNameForMetrics,ParameterValue=${metricsStreamName}
--parameters ParameterKey=FirehoseStreamName,ParameterValue=${streamName}
ParameterKey=ElasticEndpointURL,ParameterValue=${escapedElasticsearchUrl}
ParameterKey=ElasticAPIKey,ParameterValue=${encodedApiKey}
--capabilities CAPABILITY_IAM
Expand All @@ -54,15 +51,13 @@ export function buildStackStatusCommand({ stackName }: { stackName: string }) {
export function buildCreateStackAWSConsoleURL({
templateUrl,
stackName,
logsStreamName,
metricsStreamName,
streamName,
elasticsearchUrl,
encodedApiKey,
}: {
templateUrl: string;
stackName: string;
logsStreamName: string;
metricsStreamName: string;
streamName: string;
elasticsearchUrl: string;
encodedApiKey: string;
}): string {
Expand All @@ -76,8 +71,7 @@ export function buildCreateStackAWSConsoleURL({
* which triggers the eslint rule.
*/
/* eslint-disable @typescript-eslint/naming-convention */
param_FirehoseStreamNameForLogs: logsStreamName,
param_FirehoseStreamNameForMetrics: metricsStreamName,
param_FirehoseStreamName: streamName,
param_ElasticEndpointURL: elasticsearchUrl,
param_ElasticAPIKey: encodedApiKey,
/* eslint-enable @typescript-eslint/naming-convention */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ const hasFirehoseDataRoute = createObservabilityOnboardingServerRoute({
endpoint: 'GET /internal/observability_onboarding/firehose/has-data',
params: t.type({
query: t.type({
logsStreamName: t.string,
streamName: t.string,
stackName: t.string,
}),
}),
options: { tags: [] },
async handler(resources): Promise<HasFirehoseDataRouteResponse> {
const { logsStreamName, stackName } = resources.params.query;
const { streamName, stackName } = resources.params.query;
const { elasticsearch } = await resources.context.core;
const indexPatternList = AWS_INDEX_NAME_LIST.map((index) => `${index}-*`);

Expand All @@ -115,7 +115,7 @@ const hasFirehoseDataRoute = createObservabilityOnboardingServerRoute({
query: {
bool: {
should: [
...termQuery('aws.kinesis.name', logsStreamName),
...termQuery('aws.kinesis.name', streamName),
...wildcardQuery('aws.exporter.arn', stackName),
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import moment from 'moment';
import { FtrProviderContext } from '../../../ftr_provider_context';

const CF_COMMAND_REGEXP =
/aws cloudformation create-stack --stack-name (\S+) --template-url \S+ --parameters ParameterKey=FirehoseStreamNameForLogs,ParameterValue=(\S+) .+? --capabilities CAPABILITY_IAM/;
/aws cloudformation create-stack --stack-name (\S+) --template-url \S+ --parameters ParameterKey=FirehoseStreamName,ParameterValue=(\S+) .+? --capabilities CAPABILITY_IAM/;

export default function ({ getPageObjects, getService }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'svlCommonPage']);
Expand Down Expand Up @@ -60,9 +60,9 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const AWS_SERVICE_ID = 'vpc-flow';
await testSubjects.clickWhenNotDisabled('observabilityOnboardingCopyToClipboardButton');
const copiedCommand = await browser.getClipboardValue();
const [, _stackName, logsStreamName] = copiedCommand.match(CF_COMMAND_REGEXP) ?? [];
const [, _stackName, streamName] = copiedCommand.match(CF_COMMAND_REGEXP) ?? [];

expect(logsStreamName).toBeDefined();
expect(streamName).toBeDefined();

await browser.execute(`window.dispatchEvent(new Event("blur"))`);

Expand All @@ -75,7 +75,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
.rate(1)
.generator((timestamp) => {
return log.create().dataset(DATASET).timestamp(timestamp).defaults({
'aws.kinesis.name': logsStreamName,
'aws.kinesis.name': streamName,
});
})
);
Expand All @@ -89,11 +89,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const AWS_SERVICE_ID = 'vpc-flow';
await testSubjects.clickWhenNotDisabled('observabilityOnboardingCopyToClipboardButton');
const copiedCommand = await browser.getClipboardValue();
const [, _stackName, logsStreamName] = copiedCommand.match(CF_COMMAND_REGEXP) ?? [];
const [, _stackName, streamName] = copiedCommand.match(CF_COMMAND_REGEXP) ?? [];

await testSubjects.missingOrFail('observabilityOnboardingFirehosePanelExistingDataCallout');

expect(logsStreamName).toBeDefined();
expect(streamName).toBeDefined();

// Simulate Firehose stream ingesting log files
const to = new Date().toISOString();
Expand All @@ -104,7 +104,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
.rate(1)
.generator((timestamp) => {
return log.create().dataset(DATASET).timestamp(timestamp).defaults({
'aws.kinesis.name': logsStreamName,
'aws.kinesis.name': streamName,
});
})
);
Expand Down

0 comments on commit db083d1

Please sign in to comment.