Skip to content

Commit 535245f

Browse files
committed
K8SPSMDB-297 support persistent logs
1 parent 03f78e5 commit 535245f

File tree

22 files changed

+851
-7
lines changed

22 files changed

+851
-7
lines changed

build/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ COPY build/init-entrypoint.sh /init-entrypoint.sh
5353
COPY build/ps-entry.sh /ps-entry.sh
5454
COPY build/physical-restore-ps-entry.sh /physical-restore-ps-entry.sh
5555
COPY build/pbm-entry.sh /pbm-entry.sh
56+
COPY build/logcollector /logcollector
5657

5758
USER 2

build/init-entrypoint.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ set -o xtrace
66
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /ps-entry.sh /opt/percona/ps-entry.sh
77
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /physical-restore-ps-entry.sh /opt/percona/physical-restore-ps-entry.sh
88
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /mongodb-healthcheck /opt/percona/mongodb-healthcheck
9-
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /pbm-entry.sh /opt/percona/pbm-entry.sh
9+
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /pbm-entry.sh /opt/percona/pbm-entry.sh
10+
cp -a /logcollector /opt/percona/
11+
chown -R "$(id -u)":"$(id -g)" /opt/percona/logcollector
12+
chmod -R 0755 /opt/percona/logcollector

build/logcollector/entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
set -e
3+
set -o xtrace
4+
5+
export PATH=$PATH:/opt/fluent-bit/bin
6+
7+
if [ "$1" = 'logrotate' ]; then
8+
if [[ $EUID != 1001 ]]; then
9+
# logrotate requires UID in /etc/passwd
10+
sed -e "s^x:1001:^x:$EUID:^" /etc/passwd >/tmp/passwd
11+
cat /tmp/passwd >/etc/passwd
12+
rm -rf /tmp/passwd
13+
fi
14+
exec go-cron "0 0 * * *" sh -c "logrotate -s /data/logs/logrotate.status /opt/percona/logcollector/logrotate/logrotate.conf;/usr/bin/find /data/logs/ -mtime +7 ! -name logrotate.status -delete"
15+
else
16+
if [ "$1" = 'fluent-bit' ]; then
17+
fluentbit_opt+='-c /opt/percona/logcollector/fluentbit/fluentbit.conf'
18+
fi
19+
20+
exec "$@" $fluentbit_opt
21+
fi

build/logcollector/fluentbit/custom/defaul.conf

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@INCLUDE fluentbit_*.conf
2+
@INCLUDE custom/*.conf
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[SERVICE]
2+
Flush 1
3+
Log_Level info
4+
Daemon off
5+
parsers_file parsers_multiline.conf
6+
7+
[INPUT]
8+
Name tail
9+
Path ${LOG_DATA_DIR}/mongod.log
10+
Tag ${POD_NAMESPACE}.${POD_NAME}.mongod.log
11+
Refresh_Interval 5
12+
DB /tmp/flb_kube.db
13+
multiline.parser multiline-regex-test
14+
read_from_head true
15+
Path_Key file
16+
17+
[OUTPUT]
18+
Name stdout
19+
Match *
20+
Format json_lines
21+
json_date_key false
22+
23+
[OUTPUT]
24+
Name file
25+
Match ${POD_NAMESPACE}.${POD_NAME}.mongod.log
26+
File mongod.full.log
27+
Path ${LOG_DATA_DIR}/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[MULTILINE_PARSER]
2+
name multiline-regex-test
3+
type regex
4+
flush_timeout 1000
5+
#
6+
# Regex rules for multiline parsing
7+
# ---------------------------------
8+
#
9+
# configuration hints:
10+
#
11+
# - first state always has the name: start_state
12+
# - every field in the rule must be inside double quotes
13+
#
14+
# rules | state name | regex pattern | next state
15+
# ------|---------------|--------------------------------------------
16+
rule "start_state" "/\d{2,4}\-\d{2,4}\-\d{2,4}T\d{2,4}\:\d{2,4}\:\d{2,4}\.\d{1,6}Z(.*)|\d{2,6} \d{2,4}\:\d{2,4}\:\d{2,4}(.*)/" "cont"
17+
rule "cont" "/^\D/" "cont"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/data/logs/*.log {
2+
daily
3+
minsize 10M
4+
maxsize 100M
5+
rotate 10
6+
missingok
7+
nocompress
8+
notifempty
9+
sharedscripts
10+
}

build/ps-entry.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ if [[ $originalArgOne == mongo* ]]; then
480480
_mongod_hack_rename_arg_save_val --sslDisabledProtocols --tlsDisabledProtocols "${mongodHackedArgs[@]}"
481481
fi
482482

483+
if [[ $originalArgOne == "mongod" ]]; then
484+
_mongod_hack_ensure_arg_val --logpath "/data/logs/mongod.log" "${mongodHackedArgs[@]}"
485+
_mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
486+
fi
487+
483488
set -- "${mongodHackedArgs[@]}"
484489

485490
# MongoDB 3.6+ defaults to localhost-only binding

config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,122 @@ spec:
534534
type: object
535535
initImage:
536536
type: string
537+
logcollector:
538+
properties:
539+
configuration:
540+
type: string
541+
containerSecurityContext:
542+
properties:
543+
allowPrivilegeEscalation:
544+
type: boolean
545+
appArmorProfile:
546+
properties:
547+
localhostProfile:
548+
type: string
549+
type:
550+
type: string
551+
required:
552+
- type
553+
type: object
554+
capabilities:
555+
properties:
556+
add:
557+
items:
558+
type: string
559+
type: array
560+
x-kubernetes-list-type: atomic
561+
drop:
562+
items:
563+
type: string
564+
type: array
565+
x-kubernetes-list-type: atomic
566+
type: object
567+
privileged:
568+
type: boolean
569+
procMount:
570+
type: string
571+
readOnlyRootFilesystem:
572+
type: boolean
573+
runAsGroup:
574+
format: int64
575+
type: integer
576+
runAsNonRoot:
577+
type: boolean
578+
runAsUser:
579+
format: int64
580+
type: integer
581+
seLinuxOptions:
582+
properties:
583+
level:
584+
type: string
585+
role:
586+
type: string
587+
type:
588+
type: string
589+
user:
590+
type: string
591+
type: object
592+
seccompProfile:
593+
properties:
594+
localhostProfile:
595+
type: string
596+
type:
597+
type: string
598+
required:
599+
- type
600+
type: object
601+
windowsOptions:
602+
properties:
603+
gmsaCredentialSpec:
604+
type: string
605+
gmsaCredentialSpecName:
606+
type: string
607+
hostProcess:
608+
type: boolean
609+
runAsUserName:
610+
type: string
611+
type: object
612+
type: object
613+
enabled:
614+
type: boolean
615+
image:
616+
type: string
617+
imagePullPolicy:
618+
type: string
619+
resources:
620+
properties:
621+
claims:
622+
items:
623+
properties:
624+
name:
625+
type: string
626+
request:
627+
type: string
628+
required:
629+
- name
630+
type: object
631+
type: array
632+
x-kubernetes-list-map-keys:
633+
- name
634+
x-kubernetes-list-type: map
635+
limits:
636+
additionalProperties:
637+
anyOf:
638+
- type: integer
639+
- type: string
640+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
641+
x-kubernetes-int-or-string: true
642+
type: object
643+
requests:
644+
additionalProperties:
645+
anyOf:
646+
- type: integer
647+
- type: string
648+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
649+
x-kubernetes-int-or-string: true
650+
type: object
651+
type: object
652+
type: object
537653
multiCluster:
538654
properties:
539655
DNSSuffix:

deploy/bundle.yaml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,122 @@ spec:
12321232
type: object
12331233
initImage:
12341234
type: string
1235+
logcollector:
1236+
properties:
1237+
configuration:
1238+
type: string
1239+
containerSecurityContext:
1240+
properties:
1241+
allowPrivilegeEscalation:
1242+
type: boolean
1243+
appArmorProfile:
1244+
properties:
1245+
localhostProfile:
1246+
type: string
1247+
type:
1248+
type: string
1249+
required:
1250+
- type
1251+
type: object
1252+
capabilities:
1253+
properties:
1254+
add:
1255+
items:
1256+
type: string
1257+
type: array
1258+
x-kubernetes-list-type: atomic
1259+
drop:
1260+
items:
1261+
type: string
1262+
type: array
1263+
x-kubernetes-list-type: atomic
1264+
type: object
1265+
privileged:
1266+
type: boolean
1267+
procMount:
1268+
type: string
1269+
readOnlyRootFilesystem:
1270+
type: boolean
1271+
runAsGroup:
1272+
format: int64
1273+
type: integer
1274+
runAsNonRoot:
1275+
type: boolean
1276+
runAsUser:
1277+
format: int64
1278+
type: integer
1279+
seLinuxOptions:
1280+
properties:
1281+
level:
1282+
type: string
1283+
role:
1284+
type: string
1285+
type:
1286+
type: string
1287+
user:
1288+
type: string
1289+
type: object
1290+
seccompProfile:
1291+
properties:
1292+
localhostProfile:
1293+
type: string
1294+
type:
1295+
type: string
1296+
required:
1297+
- type
1298+
type: object
1299+
windowsOptions:
1300+
properties:
1301+
gmsaCredentialSpec:
1302+
type: string
1303+
gmsaCredentialSpecName:
1304+
type: string
1305+
hostProcess:
1306+
type: boolean
1307+
runAsUserName:
1308+
type: string
1309+
type: object
1310+
type: object
1311+
enabled:
1312+
type: boolean
1313+
image:
1314+
type: string
1315+
imagePullPolicy:
1316+
type: string
1317+
resources:
1318+
properties:
1319+
claims:
1320+
items:
1321+
properties:
1322+
name:
1323+
type: string
1324+
request:
1325+
type: string
1326+
required:
1327+
- name
1328+
type: object
1329+
type: array
1330+
x-kubernetes-list-map-keys:
1331+
- name
1332+
x-kubernetes-list-type: map
1333+
limits:
1334+
additionalProperties:
1335+
anyOf:
1336+
- type: integer
1337+
- type: string
1338+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1339+
x-kubernetes-int-or-string: true
1340+
type: object
1341+
requests:
1342+
additionalProperties:
1343+
anyOf:
1344+
- type: integer
1345+
- type: string
1346+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
1347+
x-kubernetes-int-or-string: true
1348+
type: object
1349+
type: object
1350+
type: object
12351351
multiCluster:
12361352
properties:
12371353
DNSSuffix:

deploy/cr.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,3 +743,10 @@ spec:
743743
# storageName: s3-us-west
744744
# compressionType: gzip
745745
# compressionLevel: 6
746+
logcollector:
747+
enabled: true
748+
image: perconalab/percona-xtradb-cluster-operator:main-logcollector
749+
resources:
750+
requests:
751+
memory: 100M
752+
cpu: 200m

0 commit comments

Comments
 (0)