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:

0 commit comments

Comments
 (0)