Skip to content

Commit

Permalink
Merge branch 'task/#22605-publish_event_on_oom_process_termination' i…
Browse files Browse the repository at this point in the history
…nto 'integration'

Task #22605 : plugin for oom killer invoked event added

See merge request elektrobit/base-os/elos!93
  • Loading branch information
gehwolf committed Jun 14, 2024
2 parents 02ec7ca + 66da237 commit 09436bb
Show file tree
Hide file tree
Showing 17 changed files with 537 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmake/project.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: MIT
set(ELOS_VERSION 0.58.11)
set(ELOS_VERSION 0.58.12)

# Attention: Aside from the version, as many things as possible in this file
# should be put into functions, as this solves potential issues with commands
Expand Down
2 changes: 2 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
'./src/libelosplugin/interface',
'./src/libelosplugin/private',
'./src/libelosplugin/public',
'./src/plugins/scanners/oomkiller/interface/',
'./src/plugins/scanners/oomkiller/private/',
'./src/plugins/scanners/kmsg/interface/',
'./src/plugins/scanners/kmsg/private/',
'./src/plugins/scanners/syslog/interface/',
Expand Down
13 changes: 13 additions & 0 deletions debian.native/control
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ Description: Event logging and management with normalized output-format (Dummy p
.
Dummy scanner plugin.

Package: elos-plugin-scanner-oomkiller
Architecture: any
Depends:
${misc:Depends},
${shlibs:Depends},
Description: Event logging and management with normalized output-format (kmsg scanner plugin)
elos is a tool to collect, store and publish various system events (i.e.
syslogs, core dumps, measurements obtained from proc- and sys-fs, ...)
while providing easy access to the collected data.
.
Oomkiller scanner plugin.

Package: elos-plugin-scanner-kmsg
Section: libs
Architecture: any
Expand Down Expand Up @@ -264,6 +276,7 @@ Recommends:
elos-plugin-backend-nosql (= ${binary:Version}),
elos-plugin-backend-sql (= ${binary:Version}),
elos-plugin-client-dummy (= ${binary:Version}),
elos-plugin-scanner-oomkiller (= ${binary:Version}),
elos-plugin-scanner-kmsg (= ${binary:Version}),
elos-plugin-scanner-shmem (= ${binary:Version}),
elos-plugin-scanner-syslog (= ${binary:Version}),
Expand Down
1 change: 1 addition & 0 deletions debian.native/elos-plugin-scanner-oomkiller.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/*/elos/scanner/scanner_oomkiller.so
8 changes: 8 additions & 0 deletions doc/Architecture_Design_Records/OOM_killer.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,11 @@ separate event for OOM

Having taken into account all pros and cons of all the provided solutions given above it is decided that a separate
scanner that subscribes to `Kmsg Scanner` events for oom-killer invocation will be implemented.


## Open Points

When parsing a Kernel log event for oom killer invocation, it is possible to retrieve the process name and its pid,
but it is not possible to retrieve the path. This is because the `proc` interface with the pid is not available after
the process is killed by the oom killer. To predetermine which process will be killed by oom killer is too much of an
overhead. The oom killer process path will therefore be set to empty "".
12 changes: 11 additions & 1 deletion src/components/config/elosd.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@
}
},
"Scanner": {
"Path": "/usr/local/lib/elos/scanner",
"PluginSearchPath": "/usr/local/lib/elos/scanner",
"Plugins": {
"ScannerDummy": {
"File": "scanner_dummy.so",
"Run": "always"
},
"OomKiller": {
"File": "scanner_oomkiller.so",
"Run": "always"
}
},
"KmsgScanner": {
"KmsgFile": "/dev/kmsg"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef enum elosEventMessageCodeE {
ELOS_MSG_CODE_SIGFPE = 5004,
ELOS_MSG_CODE_CORE_DUMPED = 5005,
ELOS_MSG_CODE_EXIT_FAILURE = 5006,
ELOS_MSG_CODE_OOM_KILLER_INVOKED = 5020,
ELOS_MSG_CODE_CORE_DUMP_CREATED = 5100,
ELOS_MSG_CODE_CORE_DUMP_DELETED = 5101,
ELOS_MSG_CODE_CORE_DUMP_DISCARDED = 5102,
Expand Down
2 changes: 1 addition & 1 deletion src/components/rpnfilter/private/rpnfilter_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ static elosRpnFilterResultE_t _stepRegExOperation(elosRpnFilterExecute_t *ctx, U
elosRpnFilterResultE_t result = RPNFILTER_RESULT_ERROR;

if ((_STACK_SUB1.type != RPNFILTER_VALUE_REGEX) || (_STACK_SUB2.type != RPNFILTER_VALUE_STRING)) {
safuLogErr("Step RPNFILTER_STEP_REGEX expects a regex string as first and a string as second value!");
safuLogErr("RPN filter string should be as follows : 'hello123' r'[0-9]' REGEX");
} else if (_STACK_SUB1.bytes < 1) {
result = RPNFILTER_RESULT_MATCH;
ctx->stackIdx -= 2;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Plugins
.. toctree::
:maxdepth: 2
:caption: Contents:

scanners/index
scanners/kmsg/index
scanners/oomkiller/index
scanners/syslog/index
scanners/shmem/index
storagebackends/dlt/index
Expand Down
1 change: 1 addition & 0 deletions src/plugins/scanners/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ add_subdirectory(dummy)
add_subdirectory(kmsg)
add_subdirectory(shmem)
add_subdirectory(syslog)
add_subdirectory(oomkiller)
41 changes: 41 additions & 0 deletions src/plugins/scanners/oomkiller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-License-Identifier: MIT
find_package(safu 0.50.1 REQUIRED)
find_package(samconf 0.50.1 REQUIRED)

add_library(
scanner_oomkiller SHARED
private/OomKillerScanner.c
private/OomKillerScannerPlugin.c
)

create_interface_library(
FROM
scanner_oomkiller
LIBRARIES
safu::safu_interface
samconf::samconf_interface
)

set_target_properties(scanner_oomkiller PROPERTIES PREFIX "")

target_link_libraries(
scanner_oomkiller
PUBLIC
scanner_oomkiller_interface
elos_common_interface
eventlogging_interface
libelosplugin
eventfilter_static
samconf::samconf
safu::safu
)

target_include_directories(
scanner_oomkiller
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

if (INSTALL_ELOS_PLUGINS)
install(TARGETS scanner_oomkiller DESTINATION ${ELOSD_SCANNER_PATH})
endif()
6 changes: 6 additions & 0 deletions src/plugins/scanners/oomkiller/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Oom killer invoked event scanner
================================

This scanner runs a subscription filter every `10ms` on kernel message events via a regex filter that filters
the `kmsg` events for `oom killer invocation`. When an event matches the scanner then the scanner publishes a
new event with `messageCode 5020`, `appName` the application terminated and its corresponding `pid`.
84 changes: 84 additions & 0 deletions src/plugins/scanners/oomkiller/interface/OomKillerScanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: MIT

#pragma once

#include <safu/log.h>
#include <stdlib.h>

#include "elos/libelosplugin/libelosplugin.h"
#include "safu/common.h"

/*******************************************************************
* Members:
* oomEventSubscriber : the event subscriber structure
* oomEventPublisher : the event publisher structure
* oomEventSubscription : the subscription structure
******************************************************************/
typedef struct elosOomKillerScanner {
struct elosSubscriber *oomEventSubscriber;
struct elosPublisher *oomEventPublisher;
const elosSubscription_t *oomEventSubscription;
} elosOomKillerScanner_t;

/*************************************************************************
* Allocate a new `elosOomKillerScanner`. It shall be safe to call
* `elosOomKillerScannerStop` event when a `SAFU_RESULT_FAILED` is returned
*
* Parameters:
* oomKillerScanner : pointer to a `elosOomKillerScanner` pointer to
* be set to the new OomKillerScanner. In case of
* an error it is unchanged.
* plugin : pointer to plugin context to which scanner members
* are bound to
*
* Returns:
* - `SAFU_RESULT_OK` on success
* - `SAFU_RESULT_FAILED` on failure
***************************************************************************/
safuResultE_t elosOomKillerScannerNew(elosOomKillerScanner_t **oomKillerScanner, elosPlugin_t *plugin);

/*******************************************************************
* Start scanning ksmg log events for oom killer invocation. Publish
* matched events.
*
* Parameters:
* oomKillerScanner : pointer to `elosOomKillerScanner` with subscriber
* and subscription to match a oom killer invoked event
* and a publisher to publish matched events
* plugin : pointer to plugin context to which scanner members
* are bound to
*
* Returns:
* - `SAFU_RESULT_OK` on success
* - `SAFU_RESULT_FAILED` on failure
********************************************************************/
safuResultE_t elosOomKillerScannerStart(elosOomKillerScanner_t *oomKillerScanner, elosPlugin_t *plugin);

/*******************************************************************
* Delete a `elosOomKillerScannerDelete`. It delete the `elosOomKillerScanner`
*
* Parameters:
* oomKillerScanner : pointer to a `elosOomKillerScanner_t` to be deleted.
* plugin : pointer to plugin context to which scanner members
* are bound to
*
* Returns:
* - `SAFU_RESULT_OK` on success
* - `SAFU_RESULT_FAILED` on failure
******************************************************************/
safuResultE_t elosOomKillerScannerDelete(elosOomKillerScanner_t *oomKillerScanner, elosPlugin_t *plugin);

/*******************************************************************
* Stop the oomKillerScanner plugin to stop scanning ksmg events for
* oom killer ivocation event
*
* Parameters:
* oomKillerScanner : pointer to `elosOomKillerScanner` with subscriber
* and subscription to match a oom killer invoked event
* and a publisher to publish matched events
*
* Returns:
* - `SAFU_RESULT_OK` on success
* - `SAFU_RESULT_FAILED` on failure
********************************************************************/
safuResultE_t elosOomKillerScannerStop(elosOomKillerScanner_t *oomKillerScanner);
Loading

0 comments on commit 09436bb

Please sign in to comment.