Skip to content

Commit 55006a7

Browse files
authored
Merge branch 'main' into main
2 parents 5bdcaaf + bf4b538 commit 55006a7

File tree

15 files changed

+393
-24
lines changed

15 files changed

+393
-24
lines changed
175 KB
Loading
143 KB
Loading
67.4 KB
Loading
237 KB
Loading
266 KB
Loading
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Single Cluster Open Source Observability - Container Logs Collection
2+
3+
## Objective
4+
5+
Following the [announcement](https://aws.amazon.com/about-aws/whats-new/2023/11/logs-support-aws-distro-opentelemetry/) of logs support in AWS Distro for OpenTelemetry, this pattern demonstrates how to use the _New EKS Cluster Open Source Observability Accelerator_ to forward container logs to cloud watch using ADOT containers log collector.
6+
7+
## Prerequisites
8+
9+
Ensure that you have installed the following tools on your machine.
10+
11+
1. [aws cli](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
12+
2. [kubectl](https://Kubernetes.io/docs/tasks/tools/)
13+
3. [cdk](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_install)
14+
4. [npm](https://docs.npmjs.com/cli/v8/commands/npm-install)
15+
16+
## Deploying
17+
18+
Please follow the _Deploying_ instructions of the [New EKS Cluster Open Source Observability Accelerator](./single-new-eks-opensource-observability.md) pattern, except for step 7, where you need to replace "context" in `~/.cdk.json` with the following:
19+
20+
```typescript
21+
"context": {
22+
"fluxRepository": {
23+
"name": "grafana-dashboards",
24+
"namespace": "grafana-operator",
25+
"repository": {
26+
"repoUrl": "https://github.com/aws-observability/aws-observability-accelerator",
27+
"name": "grafana-dashboards",
28+
"targetRevision": "main",
29+
"path": "./artifacts/grafana-operator-manifests/eks/infrastructure"
30+
},
31+
"values": {
32+
"GRAFANA_CLUSTER_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/cluster.json",
33+
"GRAFANA_KUBELET_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/kubelet.json",
34+
"GRAFANA_NSWRKLDS_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/namespace-workloads.json",
35+
"GRAFANA_NODEEXP_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/nodeexporter-nodes.json",
36+
"GRAFANA_NODES_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/nodes.json",
37+
"GRAFANA_WORKLOADS_DASH_URL" : "https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/main/artifacts/grafana-dashboards/eks/infrastructure/workloads.json"
38+
},
39+
"kustomizations": [
40+
{
41+
"kustomizationPath": "./artifacts/grafana-operator-manifests/eks/infrastructure"
42+
}
43+
]
44+
},
45+
"adotcontainerlogs.pattern.enabled": true
46+
}
47+
```
48+
49+
!! warning This scenario might need larger worker node for the pod.
50+
51+
52+
Once completed the rest of the _Deploying_ steps, you can move on with the deployment of the Nginx workload.
53+
54+
## Viewing Logs in CloudWatch Log Groups and Logs Insights
55+
56+
Navigate to CloudWatch, then go to "Log groups"
57+
58+
Search for log group with the name "/aws/eks/single-new-eks-mixed-observability-accelerator" and open it
59+
60+
You will see log streams created using the node name
61+
62+
![ADOT_container_logs_group](../images/ADOT_container_logs_group.png)
63+
64+
Open the log stream and you view the logs forwarded by the container logs collector to CloudWatch
65+
66+
![ADOT_container_logs](../images/ADOT_container_logs.png)
67+
68+
Navigate to CloudWatch, then go to "Logs Insights"
69+
70+
In the dropdown, select log group with name "/aws/eks/single-new-eks-mixed-observability-accelerator" and run a query.
71+
72+
![ADOT_container_logs_insights](../images/ADOT_container_logs_insights.png)
73+
74+
Then you can view the results of your query:
75+
76+
![ADOT_container_logs_insights](../images/ADOT_container_logs_insights_results.png)
77+
78+
## Teardown
79+
80+
You can teardown the whole CDK stack with the following command:
81+
82+
```bash
83+
make pattern single-new-eks-opensource-observability destroy
84+
```

docs/patterns/single-new-eks-observability-accelerators/single-new-eks-fargate-opensource-observability.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ You should now see a new dashboard named `Java/JMX`, under `Observability Accele
194194

195195
## Viewing Logs
196196

197-
By default, we deploy a FluentBit daemon set in the cluster to collect worker logs for all namespaces. Logs are collected and exported to Amazon CloudWatch Logs, which enables you to centralize the logs from all of your systems, applications,
198-
and AWS services that you use, in a single, highly scalable service.
197+
Amazon EKS on Fargate offers a built-in log router based on Fluent Bit. This means that you don't explicitly run a Fluent Bit container as a sidecar, but Amazon runs it for you. All that you have to do is configure the log router. The configuration happens through a dedicated [`ConfigMap`](../../../lib/common/resources/fluent-bit/fluent-bit-fargate-config.ytpl). Logs are collected and exported to Amazon CloudWatch Logs, which enables you to centralize the logs from all of your systems, applications,
198+
and AWS services that you use, in a single, highly scalable service. By default, the logs are exported to us-east-1 region but you can modify the `ConfigMap` for your region of choice. At least one supported `OUTPUT` plugin has to be provided in the `ConfigMap` to enable logging. You can also modify the destination from cloudwatch to Cloudwatch (default), Amazon OpenSearch Service or Kinesis Data Firehose. Read more about [EKS Fargate logging](https://docs.aws.amazon.com/eks/latest/userguide/fargate-logging.html).
199+
200+
![fargate-fluentbit](../images/logs-fargate-fluentbit.png)
199201

200202
## Teardown
201203

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
kind: Namespace
2+
apiVersion: v1
3+
metadata:
4+
name: aws-observability
5+
labels:
6+
aws-observability: enabled
7+
---
8+
kind: ConfigMap
9+
apiVersion: v1
10+
metadata:
11+
name: aws-logging
12+
namespace: aws-observability
13+
data:
14+
flb_log_cw: "{{enableFlbProcessLogs}}" # Set to true to ship Fluent Bit process logs to CloudWatch.
15+
filters.conf: |
16+
[FILTER]
17+
Name parser
18+
Match *
19+
Key_name log
20+
Parser crio
21+
[FILTER]
22+
Name kubernetes
23+
Match kube.*
24+
Merge_Log On
25+
Keep_Log Off
26+
Buffer_Size 0
27+
Kube_Meta_Cache_TTL 300s
28+
output.conf: |
29+
[OUTPUT]
30+
Name cloudwatch_logs
31+
Match kube.*
32+
region {{awsRegion}}
33+
log_group_name {{logGroupName}}
34+
log_stream_prefix {{log_stream_prefix}}
35+
auto_create_group true
36+
parsers.conf: |
37+
[PARSER]
38+
Name crio
39+
Format Regex
40+
Regex ^(?<time>[^ ]+) (?<stream>stdout|stderr) (?<logtag>P|F) (?<log>.*)$
41+
Time_Key time
42+
Time_Format %Y-%m-%dT%H:%M:%S.%L%z

lib/common/resources/otel-collector-config.yml

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ metadata:
99
namespace: "{{namespace}}"
1010
spec:
1111
mode: "{{deploymentMode}}"
12-
image: public.ecr.aws/aws-observability/aws-otel-collector:v0.33.1
12+
image: public.ecr.aws/aws-observability/aws-otel-collector:v0.37.0
1313
resources:
1414
limits:
1515
cpu: "1"
@@ -18,6 +18,22 @@ spec:
1818
cpu: "1"
1919
memory: "2Gi"
2020
serviceAccount: adot-collector
21+
podSecurityContext:
22+
runAsGroup: 0
23+
runAsUser: 0
24+
volumeMounts:
25+
- name: varlogpods
26+
mountPath: /var/log/pods
27+
readOnly: true
28+
volumes:
29+
- name: varlogpods
30+
hostPath:
31+
path: /var/log/pods
32+
env:
33+
- name: NODE_NAME
34+
valueFrom:
35+
fieldRef:
36+
fieldPath: spec.nodeName
2137
config: |
2238
receivers:
2339
prometheus:
@@ -1740,13 +1756,101 @@ spec:
17401756
source_labels:
17411757
- __meta_kubernetes_pod_phase
17421758
{{ stop enableIstioMonJob }}
1759+
{{ start enableAdotContainerLogsReceiver }}
1760+
filelog:
1761+
include: [ /var/log/pods/*/*/*.log ]
1762+
include_file_name: false
1763+
include_file_path: true
1764+
start_at: end
1765+
operators:
1766+
# Find out which format is used by kubernetes
1767+
- type: router
1768+
id: get-format
1769+
routes:
1770+
- output: parser-docker
1771+
expr: 'body matches "^\\{"'
1772+
- output: parser-crio
1773+
expr: 'body matches "^[^ Z]+ "'
1774+
- output: parser-containerd
1775+
expr: 'body matches "^[^ Z]+Z"'
1776+
# Parse CRI-O format
1777+
- type: regex_parser
1778+
id: parser-crio
1779+
regex:
1780+
'^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*)
1781+
?(?P<log>.*)$'
1782+
output: extract_metadata_from_filepath
1783+
timestamp:
1784+
parse_from: attributes.time
1785+
layout_type: gotime
1786+
layout: '2006-01-02T15:04:05.999999999Z07:00'
1787+
# Parse CRI-Containerd format
1788+
- type: regex_parser
1789+
id: parser-containerd
1790+
regex:
1791+
'^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*)
1792+
?(?P<log>.*)$'
1793+
output: extract_metadata_from_filepath
1794+
timestamp:
1795+
parse_from: attributes.time
1796+
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
1797+
# Parse Docker format
1798+
- type: json_parser
1799+
id: parser-docker
1800+
output: extract_metadata_from_filepath
1801+
timestamp:
1802+
parse_from: attributes.time
1803+
layout: '%Y-%m-%dT%H:%M:%S.%LZ'
1804+
- type: move
1805+
from: attributes.log
1806+
to: body
1807+
# Extract metadata from file path
1808+
- type: regex_parser
1809+
id: extract_metadata_from_filepath
1810+
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
1811+
parse_from: attributes["log.file.path"]
1812+
cache:
1813+
size: 128 # default maximum amount of Pods per Node is 110
1814+
# Rename attributes
1815+
- type: move
1816+
from: attributes.stream
1817+
to: attributes["log.iostream"]
1818+
- type: move
1819+
from: attributes.container_name
1820+
to: resource["k8s.container.name"]
1821+
- type: move
1822+
from: attributes.namespace
1823+
to: resource["k8s.namespace.name"]
1824+
- type: move
1825+
from: attributes.pod_name
1826+
to: resource["k8s.pod.name"]
1827+
- type: move
1828+
from: attributes.restart_count
1829+
to: resource["k8s.container.restart_count"]
1830+
- type: move
1831+
from: attributes.uid
1832+
to: resource["k8s.pod.uid"]
1833+
{{ stop enableAdotContainerLogsReceiver }}
1834+
1835+
processors:
1836+
k8sattributes:
1837+
batch:
1838+
17431839
exporters:
17441840
prometheusremotewrite:
17451841
endpoint: "{{remoteWriteEndpoint}}"
17461842
auth:
17471843
authenticator: sigv4auth
17481844
logging:
17491845
loglevel: info
1846+
{{ start enableAdotContainerLogsExporter }}
1847+
awscloudwatchlogs:
1848+
log_group_name: "{{logGroupName}}"
1849+
log_stream_name: "{{logStreamName}}"
1850+
region: "{{awsRegion}}"
1851+
log_retention: {{logRetentionDays}}
1852+
raw_log: false
1853+
{{ stop enableAdotContainerLogsExporter }}
17501854
extensions:
17511855
sigv4auth:
17521856
region: "{{awsRegion}}"
@@ -1762,6 +1866,10 @@ spec:
17621866
metrics:
17631867
receivers: [prometheus]
17641868
exporters: [logging, prometheusremotewrite]
1869+
logs:
1870+
receivers: [filelog]
1871+
processors: [batch,k8sattributes]
1872+
exporters: [awscloudwatchlogs]
17651873
{{ start enableAdotMetricsCollectionTelemetry }}
17661874
telemetry:
17671875
metrics:

lib/single-new-eks-awsnative-fargate-observability-construct/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class SingleNewEksAWSNativeFargateobservabilityConstruct {
3939
// Define fargate cluster provider and pass the profile options
4040
const fargateClusterProvider : blueprints.FargateClusterProvider = new blueprints.FargateClusterProvider({
4141
fargateProfiles,
42-
version: eks.KubernetesVersion.of("1.27")
42+
version: eks.KubernetesVersion.of("1.28")
4343
});
4444

4545
const certManagerAddOnProps : blueprints.CertManagerAddOnProps = {
@@ -50,7 +50,7 @@ export default class SingleNewEksAWSNativeFargateobservabilityConstruct {
5050
};
5151

5252
const coreDnsAddOnProps : blueprints.CoreDnsAddOnProps = {
53-
version:"v1.10.1-eksbuild.1",
53+
version:"v1.10.1-eksbuild.6",
5454
configurationValues:{
5555
computeType: "Fargate"
5656
}
@@ -64,7 +64,6 @@ export default class SingleNewEksAWSNativeFargateobservabilityConstruct {
6464
.withCertManagerProps(certManagerAddOnProps)
6565
.withCoreDnsProps(coreDnsAddOnProps)
6666
.enableFargatePatternAddOns()
67-
.enableControlPlaneLogging()
6867
.clusterProvider(fargateClusterProvider)
6968
.addOns(...addOns)
7069
.build(scope, stackId);

0 commit comments

Comments
 (0)