Skip to content

Commit 1f3b686

Browse files
authored
K8SPSMDB-297 support persistent logs (#1936)
1 parent 9efc64b commit 1f3b686

38 files changed

+1782
-40
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/db/logs/logrotate.status /opt/percona/logcollector/logrotate/logrotate.conf;"
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/default.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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[SERVICE]
2+
Flush 1
3+
Log_Level error
4+
Daemon off
5+
6+
[INPUT]
7+
Name tail
8+
Path ${LOG_DATA_DIR}/mongod.log
9+
Tag ${POD_NAMESPACE}.${POD_NAME}.mongod.log
10+
Refresh_Interval 5
11+
DB /tmp/flb_kube.db
12+
read_from_head true
13+
Path_Key file
14+
15+
[OUTPUT]
16+
Name stdout
17+
Match *
18+
Format json_lines
19+
json_date_key false
20+
21+
[OUTPUT]
22+
Name file
23+
Match ${POD_NAMESPACE}.${POD_NAME}.mongod.log
24+
File mongod.full.log
25+
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/data/db/logs/*.log {
2+
daily
3+
minsize 10M
4+
maxsize 100M
5+
rotate 10
6+
missingok
7+
nocompress
8+
notifempty
9+
sharedscripts
10+
postrotate
11+
mongosh "mongodb://${MONGODB_USER}:${MONGODB_PASSWORD}@${MONGODB_HOST}:${MONGODB_PORT}/admin" \
12+
--eval 'db.adminCommand({ logRotate: 1 })'
13+
find /data/db/logs/ -type f -name 'mongod.log.*' -mtime +7 -delete
14+
find /data/db/logs/ -type f -name 'mongod.full.log' -mtime +7 -delete
15+
endscript
16+
}

build/ps-entry.sh

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

483+
if [[ $originalArgOne == "mongod" && ${LOGCOLLECTOR_ENABLED:-} == "true" ]]; then
484+
mkdir -p /data/db/logs/
485+
_mongod_hack_ensure_arg_val --logpath "/data/db/logs/mongod.log" "${mongodHackedArgs[@]}"
486+
# https://www.mongodb.com/docs/manual/reference/program/mongod/#std-option-mongod.--logRotate
487+
# the operator is using logrotate as part of the logcollector feature.
488+
# using the rename option because logrotate performs db.adminCommand({ logRotate: 1 })
489+
_mongod_hack_ensure_arg_val --logRotate rename "${mongodHackedArgs[@]}"
490+
_mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
491+
fi
492+
483493
set -- "${mongodHackedArgs[@]}"
484494

485495
# 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:

0 commit comments

Comments
 (0)