Skip to content
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

Undefined external #2

Open
wants to merge 38 commits into
base: undefined_external
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
18d4c7e
LOG-372 - rsyslog - support improved undefined field handling
nhosoi Jul 8, 2019
0a3fb1e
no parentheses in if test
richm Jul 12, 2019
a5192bd
Merge branch 'master' into undefined_external
richm Jul 12, 2019
38bce2b
undefined_field output should be quiet unless undefined_debug
richm Jul 13, 2019
0e1ba63
Wait until "use_undefined:" appears in rsyslog.log.
nhosoi Jul 13, 2019
fdba78f
Trying boolean value in rsyslog "set".
nhosoi Jul 14, 2019
1ea5eef
Use parse_json to generate test data.
nhosoi Jul 15, 2019
13c407d
Following the suggestion: https://github.com/openshift/origin-aggrega…
nhosoi Jul 16, 2019
60c9672
Removing "noaction" from undefined_field.go
nhosoi Jul 16, 2019
6f6458c
Try making boolean a string...
nhosoi Jul 15, 2019
5a6aae1
fix errors in undefined field handling
richm Jul 16, 2019
a30d76b
revert back to using boolean
richm Jul 16, 2019
db36556
fix test formatting
richm Jul 16, 2019
4dff863
works with rsyslog test program
richm Jul 16, 2019
cfa37cb
reset paths to default
richm Jul 16, 2019
6653996
remove noaction; check for empty maps, arrays
richm Jul 17, 2019
83bf757
check for empty before adding to array
richm Jul 17, 2019
51fcdb8
add UNDEFINED_CONFIG env. var. for testing
richm Jul 17, 2019
de06199
use False boolean not string
richm Jul 17, 2019
e3f99ea
check keepEmpty for recursive deletes; only count field if used
richm Jul 17, 2019
95c9a44
unset stream to make test happy
richm Jul 17, 2019
51a8d97
first pass at test for undefined_field
richm Jul 18, 2019
98804ba
fix some go lint errors
richm Jul 18, 2019
8ec9e0a
start_rsyslog; make rsyslog read from tail
richm Jul 18, 2019
eb0af39
start rsyslog clean
richm Jul 18, 2019
5c24341
RSYSLOG_USE_IMPSTATS_FILE
richm Jul 18, 2019
8c66ac7
only delete empty keys at top level
richm Jul 19, 2019
5ae8fcf
only check top level keys for being empty
richm Jul 19, 2019
6bd960c
additional fudge factor for rsyslog logrotation checking
richm Jul 19, 2019
c7ba670
test improvements
richm Jul 19, 2019
4837a16
add go test to beginning of rsyslog test
richm Jul 19, 2019
362d91f
add rsyslog source to ci test image for devs
richm Jul 19, 2019
9cd2098
fix keep or delete empty recursion
richm Jul 19, 2019
1c4f21e
working with new implementation
richm Jul 20, 2019
2672400
fix logic when deleting/keeping array elements
richm Jul 22, 2019
9e49aef
fix test logic
richm Jul 22, 2019
d3f2320
fix max num field test
richm Jul 22, 2019
d85034c
fix undefined to string handling
richm Jul 22, 2019
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
41 changes: 36 additions & 5 deletions hack/testing/test-viaq-data-model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def empty(thing):
"undefined23": False
},
"undefined4": "undefined4",
"undefined5": "undefined5"
"undefined5": "undefined5",
"undefined.6": "undefined6"
},
"test2": {"undefined":
{"undefined1": "undefined1",
Expand All @@ -53,7 +54,8 @@ def empty(thing):
"undefined23": False
},
"undefined4": "undefined4",
"undefined5": "undefined5"
"undefined5": "undefined5",
"undefined.6": "undefined6"
}
},
"test3": {"undefined":
Expand All @@ -64,7 +66,8 @@ def empty(thing):
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
}
},
"undefined.6": "undefined6"
},
"undefined4": "undefined4",
"undefined5": "undefined5"
Expand All @@ -77,7 +80,8 @@ def empty(thing):
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
}
},
"undefined.6": "undefined6"
},
"undefined4": "undefined4",
"undefined5": "undefined5"
Expand All @@ -90,7 +94,34 @@ def empty(thing):
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
}
},
"undefined.6": "undefined6"
},
"undefined4": "undefined4",
"undefined5": "undefined5",
"empty1": "",
"undefined3": {"emptyvalue": ""}
},
"test6": {"myname":
{"undefined1": "undefined1",
"undefined11": 1111,
"undefined12": True,
"undefined2": {
"undefined2": "undefined2",
"undefined22": 2222,
"undefined23": False
},
"undefined_6": "undefined6"
},
"undefined4": "undefined4",
"undefined5": "undefined5",
"empty1": "",
"undefined3": {"emptyvalue": ""}
},
"test7": {"myname":
{"undefined1": "undefined1",
"undefined11": 1111,
"undefined12": True,
},
"undefined4": "undefined4",
"undefined5": "undefined5",
Expand Down
72 changes: 55 additions & 17 deletions hack/testing/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ function flush_fluentd_pos_files() {
os::cmd::expect_success "oal_sudo rm -f /var/log/journal.pos /var/log/journal_pos.json"
}

function flush_rsyslog_pos_files() {
os::cmd::expect_success "oal_sudo rm -f /var/lib/rsyslog.pod/imfile-state* /var/lib/rsyslog.pod/imjournal.state"
}

# return 0 if given file has size ge given size, otherwise, return 1
function file_has_size() {
local f=$1
Expand Down Expand Up @@ -709,25 +713,29 @@ get_fluentd_pod_log() {
fi
}

# rsyslog may have pod logs and logs in the file
get_rsyslog_pod_log() {
local pod=${1:-$( get_running_pod rsyslog )}
local container=${2:-rsyslog}
oc logs -c $container $pod 2>&1
if [ $container = rsyslog ] ; then
oc exec -c $container $pod -- logs 2>&1 || oal_sudo cat /var/log/rsyslog/rsyslog.log.* /var/log/rsyslog/rsyslog.log || :
else
oal_sudo cat /var/lib/rsyslog.pod/logrotate.log /var/log/rsyslog/logrotate.log || :
fi
}

get_mux_pod_log() {
local pod=${1:-$( get_running_pod mux )}
local logfile=${2:-/var/log/fluentd/fluentd.log}
oc logs $pod 2>&1
oc exec $pod -- cat $logfile 2> /dev/null || :
}

# rsyslog may have pod logs and logs in the file
get_rsyslog_pod_log() {
local pod=${1:-$( get_running_pod rsyslog )}
local logfile=${2:-/var/log/rsyslog/rsyslog.log}
oc logs $pod -c rsyslog 2>&1
if oc exec $pod -c rsyslog -- logs --all 2>&1 ; then
: # done
elif oal_sudo test -f $logfile ; then
# can't read from the pod directly - see if we can get the log file
oal_sudo cat ${logfile}.log-* $logfile 2> /dev/null || :
oal_sudo cat /var/log/rsyslog/rsyslog_debug.log-* /var/log/rsyslog/rsyslog_debug.log 2> /dev/null || :
oal_sudo cat /var/log/rsyslog/logrotate.log-* /var/log/rsyslog/logrotate.log 2> /dev/null || :
oal_sudo cat /var/lib/rsyslog.pod/logrotate.log-* /var/lib/rsyslog.pod/logrotate.log 2> /dev/null || :
fi
}

# writes all pod logs to the given outdir or $ARTIFACT_DIR in the form
# pod_name.container_name.log
# it will get both the oc logs output and any log files produced by
Expand All @@ -745,17 +753,18 @@ get_all_logging_pod_logs() {
continue
fi
if [ $container = logrotate ] ; then
get_rsyslog_pod_log $p $container > $ARTIFACT_DIR/$p.$container.log 2>&1
# we got the logs from the rsyslog container already
continue
fi
case "$p" in
logging-fluentd-*|fluentd-*) get_fluentd_pod_log $p > $ARTIFACT_DIR/$p.$container.log 2>&1 ;;
logging-mux-*) get_mux_pod_log $p > $ARTIFACT_DIR/$p.$container.log 2>&1 ;;
*) oc logs -n ${LOGGING_NS} -c $container $p > $ARTIFACT_DIR/$p.$container.log 2>&1
oc exec -n ${LOGGING_NS} -c $container $p -- logs >> $ARTIFACT_DIR/$p.$container.log 2>&1 || :
;;
logging-es-*|elasticsearch-*) oc logs -n ${LOGGING_NS} -c $container $p > $ARTIFACT_DIR/$p.$container.log 2>&1
oc exec -c elasticsearch -n ${LOGGING_NS} $p -- logs >> $ARTIFACT_DIR/$p.$container.log 2>&1
;;
*) oc logs -n ${LOGGING_NS} -c $container $p > $ARTIFACT_DIR/$p.$container.log 2>&1 ;;
esac
done
done
done
}

Expand Down Expand Up @@ -786,6 +795,32 @@ start_fluentd() {
os::cmd::try_until_text "oc get pods -l component=fluentd" "^(logging-)*fluentd-.* Running " $wait_time
}

stop_rsyslog() {
local rpod=${1:-$( get_running_pod rsyslog )}
local wait_time=${2:-$(( 2 * minute ))}

oc label node -l logging-infra-rsyslog=true --overwrite logging-infra-rsyslog=false
os::cmd::try_until_text "oc get $rsyslog_ds -o jsonpath='{ .status.numberReady }'" "0" $wait_time
# not sure if it is a bug or a flake, but sometimes .status.numberReady is 0, the rsyslog pod hangs around
# in the Terminating state for many seconds, which seems to cause problems with subsequent tests
# so, we have to wait for the pod to completely disappear - we cannot rely on .status.numberReady == 0
if [ -n "${rpod:-}" ] ; then
os::cmd::try_until_failure "oc get pod $rpod > /dev/null 2>&1" $wait_time
fi
}

start_rsyslog() {
local cleanfirst=${1:-false}
local wait_time=${2:-$(( 2 * minute ))}

if [ "$cleanfirst" != false ] ; then
flush_rsyslog_pos_files
oal_sudo rm -f /var/log/rsyslog/* /var/lib/rsyslog.pod/*
fi
oc label node -l logging-infra-rsyslog=false --overwrite logging-infra-rsyslog=true
os::cmd::try_until_text "oc get pods -l component=rsyslog" "^(logging-)*rsyslog-.* Running " $wait_time
}

get_fluentd_ds_name() {
if oc -n ${LOGGING_NS} get daemonset fluentd -o name > /dev/null 2>&1 ; then
echo daemonset/fluentd
Expand All @@ -806,6 +841,9 @@ get_fluentd_cm_name() {

fluentd_cm=${fluentd_cm:-$(get_fluentd_cm_name)}

# Hardcode daemonset/rsyslog for the case the rsyslog pod does not exist.
rsyslog_ds=${rsyslog_ds:-daemonset/rsyslog}

enable_cluster_logging_operator() {
if oc -n ${LOGGING_NS} get deploy cluster-logging-operator > /dev/null 2>&1 ; then
oc patch -n ${LOGGING_NS} clusterlogging instance --type=json --patch '[
Expand Down
1 change: 1 addition & 0 deletions openshift/ci-operator/build-image/Dockerfile.full
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ ADD openshift/ /go/src/github.com/openshift/origin-aggregated-logging/openshift/
ADD hack/ /go/src/github.com/openshift/origin-aggregated-logging/hack/
ADD test/ /go/src/github.com/openshift/origin-aggregated-logging/test/
ADD fluentd/ /go/src/github.com/openshift/origin-aggregated-logging/fluentd/
ADD rsyslog/ /go/src/github.com/openshift/origin-aggregated-logging/rsyslog/
9 changes: 9 additions & 0 deletions rsyslog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Following are the environment variables that can be modified to adjust the confi
| `LOGGING_FILE_PATH` | The log file absolute path where Rsyslog is writting its logs. If you want rsyslog to output its logs as Rsyslog does by default (`STDOUT`) set this variable to `console` value. Default value is `/var/log/rsyslog/rsyslog.log`. | `LOGGING_FILE_PATH=console` |
| `LOGGING_FILE_AGE` | Number of log files that Rsyslog keeps before deleting the oldest file. Default value is `10`. | `LOGGING_FILE_AGE=30` |
| `LOGGING_FILE_SIZE` | Maximum size of a rsyslog log file in bytes. If the size of the log file is bigger, the log file gets rotated. Default is 1MB | `LOGGING_FILE_SIZE=1024000`
| `CDM_USE_UNDEFINED` | Parameter to switch whether undefined fields are moved to the undefined property or not. default to "false". | `CDM_USE_UNDEFINED=true`
| `CDM_DEFAULT_KEEP_FIELDS` | Default set of fields to be kept in the top level of json. default to "CEE,time,@timestamp,aushape,ci_job,collectd,docker,fedora-ci,file,foreman,geoip,hostname,ipaddr4,ipaddr6,kubernetes,level,message,namespace_name,namespace_uuid,offset,openstack,ovirt,pid,pipeline_metadata,rsyslog,service,systemd,tags,testcase,tlog,viaq_msg_id", | -
| `CDM_EXTRA_KEEP_FIELDS` | Extra set of fields to be kept in the top level of json. A field not included in ${CDM_DEFAULT_KEEP_FIELDS} nor ${CDM_EXTRA_KEEP_FIELDS} are moved to ${CDM_UNDEFINED_NAME} if CDM_USE_UNDEFINED is "true". default to "" | `CDM_EXTRA_KEEP_FIELDS="broker"`
| `CDM_UNDEFINED_NAME` | Undefined property name used when CDM_USE_UNDEFINED is set to "true". default to "undefined". | `CDM_UNDEFINED_NAME="undef"`
| `CDM_KEEP_EMPTY_FIELDS` | Empty fields are dropped except the fields which names are set to CDM_KEEP_EMPTY_FIELDS in the CSV format. default to "". | `CDM_KEEP_EMPTY_FIELDS="offset"`
| `CDM_UNDEFINED_TO_STRING` | If set to "true", when CDM_USE_UNDEFINED is "true" and undefined property with ${CDM_UNDEFINED_NAME} is created, the value is converted to the json string. default to "false". | `CDM_UNDEFINED_TO_STRING=true
| `CDM_UNDEFINED_DOT_REPLACE_CHAR` | A dot character '.' in a property name (key) is replaced with the specified character unless the value is not "UNUSED". default to "UNUSED". Effective when MERGE_JSON_LOG is true. | `CDM_UNDEFINED_DOT_REPLACE_CHAR="_"`
| `CDM_UNDEFINED_MAX_NUM_FIELDS` | If a positive value is set, undefined fields are dropped once the number of fields has reached the value. default to "-1". | `CDM_UNDEFINED_MAX_NUM_FIELDS=4`
| `UNDEFINED_DEBUG` | Debug flag used in undefined_field as well as the config file calling the plugin. A debug file /var/log/rsyslog/rsyslog_debug.log is generated. default to "false". | `UNDEFINED_DEBUG=true`

## Rsyslog logging to file
Rsyslog by default writes its logs into a file given by `LOGGING_FILE_PATH` environment variable. You can change the maximum size of a single log file or number of log files to keep(age), by setting `LOGGING_FILE_SIZE` and `LOGGING_FILE_AGE` environment variables accordingly.
Expand Down
Loading