Skip to content

K8SPSMDB-297 support persistent logs #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ COPY build/init-entrypoint.sh /init-entrypoint.sh
COPY build/ps-entry.sh /ps-entry.sh
COPY build/physical-restore-ps-entry.sh /physical-restore-ps-entry.sh
COPY build/pbm-entry.sh /pbm-entry.sh
COPY build/logcollector /logcollector

USER 2
5 changes: 4 additions & 1 deletion build/init-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ set -o xtrace
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /ps-entry.sh /opt/percona/ps-entry.sh
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /physical-restore-ps-entry.sh /opt/percona/physical-restore-ps-entry.sh
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /mongodb-healthcheck /opt/percona/mongodb-healthcheck
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /pbm-entry.sh /opt/percona/pbm-entry.sh
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /pbm-entry.sh /opt/percona/pbm-entry.sh
cp -a /logcollector /opt/percona/
chown -R "$(id -u)":"$(id -g)" /opt/percona/logcollector
chmod -R 0755 /opt/percona/logcollector
21 changes: 21 additions & 0 deletions build/logcollector/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -e
set -o xtrace

export PATH="$PATH":/opt/fluent-bit/bin

if [ "$1" = 'logrotate' ]; then
if [[ $EUID != 1001 ]]; then

Check warning on line 8 in build/logcollector/entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/logcollector/entrypoint.sh#L8 <ShellCheck.SC3010>

In POSIX sh, [[ ]] is undefined.
Raw output
./build/logcollector/entrypoint.sh:8:5: warning: In POSIX sh, [[ ]] is undefined. (ShellCheck.SC3010)

Check warning on line 8 in build/logcollector/entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/logcollector/entrypoint.sh#L8 <ShellCheck.SC3028>

In POSIX sh, EUID is undefined.
Raw output
./build/logcollector/entrypoint.sh:8:8: warning: In POSIX sh, EUID is undefined. (ShellCheck.SC3028)
# logrotate requires UID in /etc/passwd
sed -e "s^x:1001:^x:$EUID:^" /etc/passwd >/tmp/passwd

Check warning on line 10 in build/logcollector/entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/logcollector/entrypoint.sh#L10 <ShellCheck.SC3028>

In POSIX sh, EUID is undefined.
Raw output
./build/logcollector/entrypoint.sh:10:23: warning: In POSIX sh, EUID is undefined. (ShellCheck.SC3028)
cat /tmp/passwd >/etc/passwd
rm -rf /tmp/passwd
fi
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"
else
if [ "$1" = 'fluent-bit' ]; then
fluentbit_opt+='-c /opt/percona/logcollector/fluentbit/fluentbit.conf'

Check warning on line 17 in build/logcollector/entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/logcollector/entrypoint.sh#L17 <ShellCheck.SC3024>

In POSIX sh, += is undefined.
Raw output
./build/logcollector/entrypoint.sh:17:3: warning: In POSIX sh, += is undefined. (ShellCheck.SC3024)
fi

exec "$@" $fluentbit_opt

Check notice on line 20 in build/logcollector/entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/logcollector/entrypoint.sh#L20 <ShellCheck.SC2086>

Double quote to prevent globbing and word splitting.
Raw output
./build/logcollector/entrypoint.sh:20:12: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
exec "$@" $fluentbit_opt
exec "$@" "$fluentbit_opt"

fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this? if yes, we need to fix the typo in the file name

Empty file.
2 changes: 2 additions & 0 deletions build/logcollector/fluentbit/fluentbit.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@INCLUDE fluentbit_*.conf
@INCLUDE custom/*.conf
25 changes: 25 additions & 0 deletions build/logcollector/fluentbit/fluentbit_mongo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[SERVICE]
Flush 1
Log_Level error
Daemon off

[INPUT]
Name tail
Path ${LOG_DATA_DIR}/mongod.log
Tag ${POD_NAMESPACE}.${POD_NAME}.mongod.log
Refresh_Interval 5
DB /tmp/flb_kube.db
read_from_head true
Path_Key file

[OUTPUT]
Name stdout
Match *
Format json_lines
json_date_key false

[OUTPUT]
Name file
Match ${POD_NAMESPACE}.${POD_NAME}.mongod.log
File mongod.full.log
Path ${LOG_DATA_DIR}/
17 changes: 17 additions & 0 deletions build/logcollector/fluentbit/parsers_multiline.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[MULTILINE_PARSER]
name multiline-regex-test
type regex
flush_timeout 1000
#
# Regex rules for multiline parsing
# ---------------------------------
#
# configuration hints:
#
# - first state always has the name: start_state
# - every field in the rule must be inside double quotes
#
# rules | state name | regex pattern | next state
# ------|---------------|--------------------------------------------
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"
rule "cont" "/^\D/" "cont"
10 changes: 10 additions & 0 deletions build/logcollector/logrotate/logrotate.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/data/logs/*.log {
daily
minsize 10M
maxsize 100M
rotate 10
missingok
nocompress
notifempty
sharedscripts
}
5 changes: 5 additions & 0 deletions build/ps-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ if [[ $originalArgOne == mongo* ]]; then
_mongod_hack_rename_arg_save_val --sslDisabledProtocols --tlsDisabledProtocols "${mongodHackedArgs[@]}"
fi

if [[ $originalArgOne == "mongod" && "${LOGCOLLECTOR_ENABLED:-}" == "true" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
if [[ $originalArgOne == "mongod" && "${LOGCOLLECTOR_ENABLED:-}" == "true" ]]; then
if [[ $originalArgOne == "mongod" && ${LOGCOLLECTOR_ENABLED:-} == "true" ]]; then

_mongod_hack_ensure_arg_val --logpath "/data/logs/mongod.log" "${mongodHackedArgs[@]}"
_mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
fi

set -- "${mongodHackedArgs[@]}"

# MongoDB 3.6+ defaults to localhost-only binding
Expand Down
116 changes: 116 additions & 0 deletions config/crd/bases/psmdb.percona.com_perconaservermongodbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,122 @@ spec:
type: object
initImage:
type: string
logcollector:
properties:
configuration:
type: string
containerSecurityContext:
properties:
allowPrivilegeEscalation:
type: boolean
appArmorProfile:
properties:
localhostProfile:
type: string
type:
type: string
required:
- type
type: object
capabilities:
properties:
add:
items:
type: string
type: array
x-kubernetes-list-type: atomic
drop:
items:
type: string
type: array
x-kubernetes-list-type: atomic
type: object
privileged:
type: boolean
procMount:
type: string
readOnlyRootFilesystem:
type: boolean
runAsGroup:
format: int64
type: integer
runAsNonRoot:
type: boolean
runAsUser:
format: int64
type: integer
seLinuxOptions:
properties:
level:
type: string
role:
type: string
type:
type: string
user:
type: string
type: object
seccompProfile:
properties:
localhostProfile:
type: string
type:
type: string
required:
- type
type: object
windowsOptions:
properties:
gmsaCredentialSpec:
type: string
gmsaCredentialSpecName:
type: string
hostProcess:
type: boolean
runAsUserName:
type: string
type: object
type: object
enabled:
type: boolean
image:
type: string
imagePullPolicy:
type: string
resources:
properties:
claims:
items:
properties:
name:
type: string
request:
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: object
type: object
multiCluster:
properties:
DNSSuffix:
Expand Down
116 changes: 116 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,122 @@ spec:
type: object
initImage:
type: string
logcollector:
properties:
configuration:
type: string
containerSecurityContext:
properties:
allowPrivilegeEscalation:
type: boolean
appArmorProfile:
properties:
localhostProfile:
type: string
type:
type: string
required:
- type
type: object
capabilities:
properties:
add:
items:
type: string
type: array
x-kubernetes-list-type: atomic
drop:
items:
type: string
type: array
x-kubernetes-list-type: atomic
type: object
privileged:
type: boolean
procMount:
type: string
readOnlyRootFilesystem:
type: boolean
runAsGroup:
format: int64
type: integer
runAsNonRoot:
type: boolean
runAsUser:
format: int64
type: integer
seLinuxOptions:
properties:
level:
type: string
role:
type: string
type:
type: string
user:
type: string
type: object
seccompProfile:
properties:
localhostProfile:
type: string
type:
type: string
required:
- type
type: object
windowsOptions:
properties:
gmsaCredentialSpec:
type: string
gmsaCredentialSpecName:
type: string
hostProcess:
type: boolean
runAsUserName:
type: string
type: object
type: object
enabled:
type: boolean
image:
type: string
imagePullPolicy:
type: string
resources:
properties:
claims:
items:
properties:
name:
type: string
request:
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
type: object
type: object
multiCluster:
properties:
DNSSuffix:
Expand Down
7 changes: 7 additions & 0 deletions deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,10 @@ spec:
# storageName: s3-us-west
# compressionType: gzip
# compressionLevel: 6
logcollector:
enabled: true
image: perconalab/percona-xtradb-cluster-operator:main-logcollector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to fix this image, is this temporary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until the new images for Fluentbit are ready, I think we should keep this as is. We can change it with a new PR once these new images are ready.

resources:
requests:
memory: 100M
cpu: 200m
Loading
Loading