Skip to content

Commit

Permalink
parameterised fluent bit config for fargate oss pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Howlla authored Feb 4, 2024
1 parent e212d4a commit 92f1909
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ metadata:
name: aws-logging
namespace: aws-observability
data:
flb_log_cw: "true" # Set to true to ship Fluent Bit process logs to CloudWatch.
flb_log_cw: "{{enableFlbProcessLogs}}" # Set to true to ship Fluent Bit process logs to CloudWatch.
filters.conf: |
[FILTER]
Name parser
Expand All @@ -29,9 +29,9 @@ data:
[OUTPUT]
Name cloudwatch_logs
Match kube.*
region us-east-1
log_group_name fargate-observability
log_stream_prefix from-fluent-bit-
region {{awsRegion}}
log_group_name {{logGroupName}}
log_stream_prefix {{log_stream_prefix}}
auto_create_group true
parsers.conf: |
[PARSER]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,79 @@
import 'source-map-support/register';
import * as blueprints from '@aws-quickstart/eks-blueprints';
import * as eks from "aws-cdk-lib/aws-eks";
import { Construct } from 'constructs';
import { KubectlProvider, ManifestDeployment } from "@aws-quickstart/eks-blueprints/dist/addons/helm-addon/kubectl-provider";
import { loadYaml, readYamlDocument } from '@aws-quickstart/eks-blueprints/dist/utils';

/**
* Configuration options for the fluentbit configmap
*/
export interface FluentBitConfigMapProps {

/**
* Region to send cloudwatch logs.
*/
awsRegion: string;

/**
* Log Group Name in cloudwatch
*/
logGroupName: string

/**
* Prefix for logs stream
*/
log_stream_prefix: string;

/**
* Enable logs from fluentBit process
*/
enableFlbProcessLogs?: boolean
}

/**
* Default props for the add-on.
*/
const defaultProps: FluentBitConfigMapProps = {
awsRegion: "us-east-1",
logGroupName: "fargate-observability",
log_stream_prefix: "from-fluent-bit-",
enableFlbProcessLogs: false
};

/**
* Creates 'aws-observability' namespace and configurable ConfigMap
* to enable the Fargate built-in log router based on Fluent Bit
* https://docs.aws.amazon.com/eks/latest/userguide/fargate-logging.html
*/
export class FluentBitConfigMap implements blueprints.ClusterAddOn {
id?: string | undefined;
deploy(clusterInfo: blueprints.ClusterInfo): void | Promise<Construct> {
const cluster = clusterInfo.cluster;
readonly props: FluentBitConfigMapProps;

const doc = readYamlDocument(__dirname + '/fluentbitconfig.yml');
constructor(props?: FluentBitConfigMapProps) {
this.props = { ...defaultProps, ...props };
}

deploy(clusterInfo: blueprints.ClusterInfo): void {
const cluster = clusterInfo.cluster;

Check warning on line 56 in lib/single-new-eks-fargate-opensource-observability-pattern/fluentbitconfigmap.ts

View workflow job for this annotation

GitHub Actions / build (18)

'cluster' is assigned a value but never used

const doc = readYamlDocument(__dirname + '/../common/resources/fluent-bit/fluent-bit-fargate-config.ytpl');
const manifest = doc.split("---").map(e => loadYaml(e));

const configMap = new eks.KubernetesManifest(cluster.stack, "aws-observability", {
cluster,
const values: blueprints.Values = {
awsRegion: this.props.awsRegion,
logGroupName: this.props.logGroupName,
log_stream_prefix: this.props.log_stream_prefix,
enableFlbProcessLogs: this.props.enableFlbProcessLogs,
};

const manifestDeployment: ManifestDeployment = {
name: 'aws-logging',
namespace: 'aws-observability',
manifest,
overwrite: true
});

return Promise.resolve(configMap);
values
};

const kubectlProvider = new KubectlProvider(clusterInfo);
kubectlProvider.addManifest(manifestDeployment);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { Construct } from 'constructs';
import { utils } from '@aws-quickstart/eks-blueprints';
import * as blueprints from '@aws-quickstart/eks-blueprints';
import { GrafanaOperatorSecretAddon } from '../single-new-eks-opensource-observability-pattern/grafanaoperatorsecretaddon';
import { FluentBitConfigMap, FluentBitConfigMapProps } from './fluentbitconfigmap';
import * as amp from 'aws-cdk-lib/aws-aps';
import { ObservabilityBuilder } from '@aws-quickstart/eks-blueprints';
import * as eks from 'aws-cdk-lib/aws-eks';
import * as fs from 'fs';
import { ManagedPolicy,Role,ServicePrincipal } from "aws-cdk-lib/aws-iam";
import { FluentBitConfigMap } from './fluentbitconfigmap';


export default class SingleNewEksFargateOpenSourceObservabilityConstruct {
constructor(scope: Construct, id: string) {
Expand Down Expand Up @@ -114,6 +113,12 @@ export default class SingleNewEksFargateOpenSourceObservabilityConstruct {
);
}

const fluentBitConfigMapProps = {
awsRegion: region,
logGroupName: "fargate-observability",
log_stream_prefix: "from-fluent-bit-",
} as FluentBitConfigMapProps;

Reflect.defineMetadata("ordered", true, blueprints.addons.GrafanaOperatorAddon);
const addOns: Array<blueprints.ClusterAddOn> = [
new blueprints.addons.VpcCniAddOn(),
Expand Down Expand Up @@ -141,7 +146,7 @@ export default class SingleNewEksFargateOpenSourceObservabilityConstruct {
new blueprints.addons.AdotCollectorAddOn(),
new blueprints.addons.XrayAdotAddOn(),
new blueprints.addons.AmpAddOn(ampAddOnProps),
new FluentBitConfigMap()
new FluentBitConfigMap(fluentBitConfigMapProps)
];

const nodeRole = new blueprints.CreateRoleProvider("blueprint-fargate-pod-role", new ServicePrincipal("eks-fargate-pods.amazonaws.com"),
Expand Down

0 comments on commit 92f1909

Please sign in to comment.