Skip to content

Commit ae8a27c

Browse files
authored
[PFMENG-3093] add custom parser variable (#176)
* [PFMENG-3093] add custom parser variable * [PFMENG-3093] add custom parser variable * [PFMENG-3093] add custom parser variable * [PFMENG-3093] add custom parser variable * [PFMENG-3093] add custom parser variable * [PFMENG-3093] add custom parser variable * [PFMENG-3093] add custom parser variable * [PFMENG-3093] change s3_key_format * [PFMENG-3093] change s3_key_format * [PFMENG-3093] change s3_key_format * [PFMENG-3093] change s3_key_format * [PFMENG-3093] change s3_key_format * [PFMENG-3093] change s3_key_format * [PFMENG-3093] change s3_key_format * [PFMENG-3093] add modify parameter * [PFMENG-3093] add modify parameter * [PFMENG-3093] add modify parameter * [PFMENG-3093] add k8 api endpoint * [PFMENG-3093] remove modify filter * [PFMENG-3093] add k8 api endpoint * [PFMENG-3093] add k8 api endpoint
1 parent 1d0dfb0 commit ae8a27c

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

modules/essentials/fluent_bit.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ locals {
3232
service_account_name = local.service_account_name,
3333
image_repository = var.fluent_bit_image_repository,
3434
image_tag = var.fluent_bit_image_tag,
35+
custom_parser = var.fluent_bit_custom_parser,
3536
liveness_probe = jsonencode(var.fluent_bit_liveness_probe),
3637
readiness_probe = jsonencode(var.fluent_bit_readiness_probe),
3738
resources = jsonencode(var.fluent_bit_resources),
@@ -40,6 +41,7 @@ locals {
4041
excluded_namespaces = var.fluent_bit_excluded_namespaces,
4142
s3_bucket_name = var.fluent_bit_enable_s3_output ? module.fluentbit_s3_bucket[0].s3_bucket_id : null,
4243
cw_enable = var.fluent_bit_enable_cw_output
44+
kube_api_endpoint = var.fluent_bit_kube_api_endpoint
4345
})
4446

4547
fluent_bit_helm_config = merge(

modules/essentials/templates/fluent_bit.yaml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ config:
5656
## Default parsers are from : https://github.com/fluent/fluent-bit/blob/master/conf/parsers.conf
5757
customParsers: |
5858
[PARSER]
59-
Name custom_apache
59+
Name ${custom_parser.name}
6060
Format regex
61-
Regex ^(?<client_ip>[^ ]*) \<(?<x_forwarded_for>[^\"]*)\> (?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<latency>[^\"]*)" "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$
61+
Regex ${custom_parser.regex}
6262
Time_Keep Off
63-
Time_Key time
64-
Time_Format %d/%b/%Y:%H:%M:%S %z
63+
Time_Key ${custom_parser.time_key}
64+
Time_Format ${custom_parser.time_format}
6565
6666
## https://docs.fluentbit.io/manual/pipeline/inputs
6767
inputs: |
@@ -92,18 +92,19 @@ config:
9292
[FILTER]
9393
Name kubernetes
9494
Match kube.*
95-
Kube_URL https://kubernetes.default.svc.cluster.local:443
95+
Kube_URL ${kube_api_endpoint}
9696
Merge_Log On
9797
Keep_Log Off
9898
K8S-Logging.Parser On
9999
K8S-Logging.Exclude On
100100
Buffer_Size 31k
101+
Kube_Tag_Prefix kube.var.log.containers.
101102
102103
[FILTER]
103104
Name parser
104105
Match kube.*
105106
Key_Name log
106-
Parser custom_apache
107+
Parser ${custom_parser.name}
107108
Reserve_Data true
108109
109110
%{if length(excluded_namespaces) > 0}
@@ -119,18 +120,20 @@ config:
119120
[FILTER]
120121
Name kubernetes
121122
Match kube_s3.*
122-
Kube_URL https://kubernetes.default.svc.cluster.local:443
123+
Kube_URL ${kube_api_endpoint}
123124
Merge_Log On
124125
Keep_Log Off
125126
K8S-Logging.Parser On
126127
Buffer_Size 31k
128+
Kube_Tag_Prefix kube_s3.var.log.containers.
127129

128130
[FILTER]
129131
Name parser
130132
Match kube_s3.*
131133
Key_Name log
132-
Parser custom_apache
134+
Parser ${custom_parser.name}
133135
Reserve_Data true
136+
134137
%{ endif }
135138

136139
## https://docs.fluentbit.io/manual/pipeline/outputs
@@ -152,9 +155,9 @@ config:
152155
Match kube_s3.*
153156
region ap-southeast-1
154157
bucket ${s3_bucket_name}
155-
compression gzip
156158
storage_class REDUCED_REDUNDANCY
157159
retry_limit 2
160+
s3_key_format /fluent-bit-logs/%Y/%m/%d/%H/%M/$TAG
158161
%{ endif }
159162

160163
# extraFiles: {}

modules/essentials/variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,24 @@ variable "fluent_bit_log_group_retention" {
14871487
default = 30
14881488
}
14891489

1490+
variable "fluent_bit_custom_parser" {
1491+
description = "Custom parser for Fluent Bit"
1492+
type = object({
1493+
name = string
1494+
format = string
1495+
regex = optional(string)
1496+
time_key = string
1497+
time_format = string
1498+
})
1499+
default = {
1500+
name = "custom_apache"
1501+
format = "regex"
1502+
regex = "^(?<client_ip>[^ ]*) \\<(?<x_forwarded_for>[^\\\"]*)\\> (?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \\[(?<time>[^\\]]*)\\] \"(?<latency>[^\\\"]*)\" \"(?<method>\\S+)(?: +(?<path>[^ ]*) +\\S*)?\" (?<code>[^ ]*) (?<size>[^ ]*)(?: \"(?<referer>[^\\\"]*)\" \"(?<agent>[^\\\"]*)\")?$"
1503+
time_key = "time"
1504+
time_format = "%d/%b/%Y:%H:%M:%S %z"
1505+
}
1506+
}
1507+
14901508
variable "resolve_conflicts_on_update" {
14911509
description = "value for resolve_conflicts_on_update for aws_eks_addon resource"
14921510
type = string
@@ -1553,6 +1571,12 @@ variable "fluent_bit_tolerations" {
15531571
]
15541572
}
15551573

1574+
variable "fluent_bit_kube_api_endpoint" {
1575+
description = "Kube API endpoint for fluent-bit"
1576+
type = string
1577+
default = "https://kubernetes.default.svc.cluster.local:443"
1578+
}
1579+
15561580
variable "ip_dual_stack_enabled" {
15571581
description = "Enable essentials to support EKS dual stack cluster"
15581582
type = bool

0 commit comments

Comments
 (0)