Skip to content

Commit f09cfb5

Browse files
authored
fix: Remove log. prefix in kibana fluentd logs, add cert-manager servicemonitor (#192)
1 parent 33aa175 commit f09cfb5

5 files changed

Lines changed: 57 additions & 37 deletions

File tree

templates/kubernetes/terraform/environments/prod/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ module "kubernetes" {
7676
# ["Test User 2", "10.10.99.202/32", "h2jMuaXNIlx7Z0a3owWFjPsAA8B+ZpQH3FbZK393+08="],
7777
]
7878

79-
domain_name = local.domain_name
79+
domain_name = local.domain_name
80+
8081
<% if eq (index .Params `userAuth`) "yes" %>user_auth = [
8182
{
8283
name = local.project

templates/kubernetes/terraform/environments/stage/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ module "kubernetes" {
7575
# ["Test User 2", "10.10.199.202/32", "h2jMuaXNIlx7Z0a3owWFjPsAA8B+ZpQH3FbZK393+08="],
7676
]
7777

78-
domain_name = local.domain_name
78+
domain_name = local.domain_name
79+
7980
<% if eq (index .Params `userAuth`) "yes" %>user_auth = [
8081
{
8182
name = local.project

templates/kubernetes/terraform/modules/kubernetes/cert_manager.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ resource "helm_release" "cert_manager" {
9797
name = "installCRDs"
9898
value = true
9999
}
100+
set {
101+
name = "prometheus.enabled"
102+
value = var.metrics_type == "prometheus"
103+
}
104+
set {
105+
name = "prometheus.servicemonitor.enabled"
106+
value = var.metrics_type == "prometheus"
107+
}
108+
set {
109+
name = "prometheus.servicemonitor.labels.app"
110+
value = var.metrics_type == "prometheus" ? "kube-prometheus-stack-prometheus" : ""
111+
}
112+
set {
113+
name = "prometheus.servicemonitor.namespace"
114+
value = "metrics"
115+
}
100116
}
101117

102118
# Manually kubectl apply the cert-manager issuers, as the kubernetes terraform provider

templates/kubernetes/terraform/modules/kubernetes/ingress/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ resource "kubernetes_config_map" "nginx_configuration" {
4949
use-proxy-protocol = "false"
5050
log-format-escape-json = "true"
5151
log-format-upstream = replace(local.log_format, "\n", "")
52+
generate-request-id = "true"
5253
}
5354
}
5455

templates/kubernetes/terraform/modules/kubernetes/logging/kibana/files/fluentd-application.conf

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,36 @@
88
pattern ^nginx
99
tag logs.kubernetes.nginx
1010
</rule>
11-
# Add a tag for your application
12-
<rule>
13-
key $.kubernetes.container_name
14-
pattern ^your-application
15-
tag logs.kubernetes.yourapplication
16-
</rule> # Catch all (have to actually change the tag (add "logs.") otherwise there is an infinite loop)
11+
# # Add a tag for your application - enable this and the blocks below if you want fluentd to manually control the structure of your logs
12+
# # Otherwise it will just parse out the structured json data and send it to elasticsearch
13+
# <rule>
14+
# key $.kubernetes.container_name
15+
# pattern ^your-application
16+
# tag logs.kubernetes.yourapplication
17+
# </rule> # Catch all (have to actually change the tag (add "logs.") otherwise there is an infinite loop)
1718
<rule>
1819
key log
1920
pattern ^(.*)$
2021
tag logs.${tag}
2122
</rule>
2223
</match>
2324

24-
# This allows us to parse log lines that have json separately, but still keep the unstructured ones
25-
<match {logs.kubernetes.yourapplication}>
26-
@type rewrite_tag_filter
27-
# Add a tag for messages that didn't have parseable json
28-
<rule>
29-
key log
30-
pattern /"message" *: *\{/
31-
tag ${tag}.hasJson
32-
</rule>
33-
# Catch all
34-
<rule>
35-
key log
36-
pattern ^(.*)$
37-
tag ${tag}.noJson
38-
</rule>
39-
</match>
25+
# # This allows us to parse log lines that have json separately, but still keep the unstructured ones
26+
# <match {logs.kubernetes.yourapplication}>
27+
# @type rewrite_tag_filter
28+
# # Add a tag for messages that didn't have parseable json
29+
# <rule>
30+
# key log
31+
# pattern /"message" *: *\{/
32+
# tag ${tag}.hasJson
33+
# </rule>
34+
# # Catch all
35+
# <rule>
36+
# key log
37+
# pattern ^(.*)$
38+
# tag ${tag}.noJson
39+
# </rule>
40+
# </match>
4041

4142

4243
# Remove fields here we don't care to log
@@ -45,15 +46,15 @@
4546
remove_keys $.docker.container_id, $.kubernetes.master_url, $.kubernetes.pod_id, $.kubernetes.namespace_id
4647
</filter>
4748

48-
# Separate out messages with json into another key called data
49-
# message":{
50-
<filter logs.kubernetes.*.hasJson>
51-
@type record_transformer
52-
enable_ruby
53-
<record>
54-
log ${record["log"].gsub(/"message" *: *\{/, '"data": {')}
55-
</record>
56-
</filter>
49+
# # Separate out messages with json into another key called data
50+
# # message":{
51+
# <filter logs.kubernetes.*.hasJson>
52+
# @type record_transformer
53+
# enable_ruby
54+
# <record>
55+
# log ${record["log"].gsub(/"message" *: *\{/, '"data": {')}
56+
# </record>
57+
# </filter>
5758

5859
# Parse nested fields as json
5960
<filter logs.kubernetes.**>
@@ -62,7 +63,7 @@
6263
key_name log
6364
reserve_data true
6465
remove_key_name_field true
65-
inject_key_prefix log.
66+
# inject_key_prefix log.
6667

6768
<parse>
6869
@type multi_format
@@ -101,7 +102,7 @@
101102
http.request.bytes ${record["log.request_length"].to_i}
102103
http.response.bytes ${record["log.bytes_sent"].to_i}
103104
http.response.status_code ${record["log.status"].to_i}
104-
trace.id ${record["log.http_x_correlation_id"]}
105+
trace.id ${record["log.request_id"]}
105106
client.ip ${record["log.remote_addr"]}
106107
url.path ${record["log.path"]}
107108
url.query ${record["log.request_query"]}
@@ -110,7 +111,7 @@
110111
</record>
111112
</filter>
112113

113-
# Reformat your application logs into ECS format
114+
# # Reformat your application logs into ECS format
114115
# <filter logs.kubernetes.*.hasJson>
115116
# @id application-to-ecs-format
116117
# @type record_transformer
@@ -122,7 +123,7 @@
122123
# </filter>
123124

124125

125-
# Uncomment these to make debugging easier by printing to stdout in fluentd
126+
# # Uncomment these to make debugging easier by printing to stdout in fluentd
126127
# <match logs.kubernetes.nginx>
127128
# @type stdout
128129
# </match>

0 commit comments

Comments
 (0)