Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions dockers/docker-database/database_config.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
"instance" : "redis"
}
{% endif %}
,
"EVENT_DB" : {
"id" : 19,
"separator": "|",
"instance" : "redis"
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This a new redis DB instance addition. Have few queries:

  1. is there a max limit of redis DB instances that can be spawned and maintained on a given SONiC instance?
  2. If so, was it ensured that its within limits and no impact to the overall system bring-up and working in steady state?
  3. Is this a global database i.e. only a single instance of it would be spawned on the system in global namespace? or would it be one per ASIC/NPU namespace? Where is that determined/specified in this changeset?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. Currently the max limit is set at 100 logical instances. /etc/redis/redis.conf
  2. This is within the global database. (redis instance.)

},
"VERSION" : "1.0"
}
10 changes: 10 additions & 0 deletions dockers/docker-eventd/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=start:exited

[program:eventdb]
command=/usr/bin/eventdb
priority=3
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
dependent_startup=true
dependent_startup_wait_for=start:exited

13 changes: 10 additions & 3 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,16 @@ function preStartAction()
# Load redis content from /host/warmboot/dump.rdb
docker cp $WARM_DIR/dump.rdb database$DEV:/var/lib/redis/dump.rdb
else
# Create an emtpy file and overwrite any RDB if already there
echo -n > /tmp/dump.rdb
docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/
COLD_DIR=/host/coldboot
#In case of cold reboot, load redis content from /host/coldboot/dump.rdb
if [[ -f $COLD_DIR/dump.rdb ]]; then
#Load redis content from /host/coldboot/dump.rdb
docker cp $COLD_DIR/dump.rdb database$DEV:/var/lib/redis/dump.rdb
else
# Create an emtpy file and overwrite any RDB if already there
echo -n > /tmp/dump.rdb
docker cp /tmp/dump.rdb database$DEV:/var/lib/redis/
fi
fi
fi
{%- elif docker_container_name == "pde" %}
Expand Down
107 changes: 107 additions & 0 deletions src/eventdb_ut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include<string>
#include "gtest/gtest.h"
#include "events_common.h"
#include "events.h"
#include "../src/eventd.h"
#include "../src/eventconsume.h"

using namespace std;
using namespace swss;

typedef struct {
int key;
string type-id;
string resource;
string action;
string text;
} event_data_t;

static const event_data_t events[] = {
{1, "SYSTEM_STATE", "System", "", "System Ready"},
{2, "USER_LOGIN", "ssh", "", "user testuser logged in"},
};

static const event_data_t alarms[] = {
{1, "TEMP_THRESHOLD_HIGH", "CPU_SENSOR", "RAISE", "Temperature cross threshold 50C"},
{2, "INTERFACE_OPER_STATE", "eth1", "RAISE", "Operational Down"},
{3, "INTERFACE_OPER_STATE", "eth1", "CLEAR", "Operational Down"},
{4, "TEMP_THRESHOLD_HIGH", "CPU_SENSOR", "CLEAR", "Temperature cross threshold 50C"},

};

const string event_profile = "default_event.json";
const string event_db_profile = "event_db.json";

//typedef unordered_map<string, string> params;

//params events_lst[] = [("id":" 1", "type-id": SYSTEM_STATE, "resource": "System", "text": "System Ready", "severity" : "INFORMATIONAL"},
// {"id":"2", "type-id": USER_LOGIN, "resource": "SSH", "text": "User login", "severity": "WARNING"}];
/*
1) "time-created"
2) "1706507049241598976"
3) "type-id"
4) "SYSTEM_STATUS"
5) "text"
6) "System is ready"
7) "resource"
8) "system_status"
9) "severity"
10) "INFORMATIONAL"
11) "id"
12) "4"
*/

class EventDbFixture : public ::testing::Environment {
protected:
void SetUp() override {
zctx = zmq_ctx_new();
EXPECT_TRUE(NULL != zctx);

/* Run proxy to enable receive as capture test needs to receive */
eventd_proxy *pxy = new eventd_proxy(zctx);
EXPECT_TRUE(NULL != pxy);

/* Starting proxy */
EXPECT_EQ(0, pxy->init());

/* Start Eventdb in a separate thread*/
swss::DBConnector eventDb("EVENT_DB", 0);

EventConsume evtd(&eventDb, event_profile, event_db_profile);
thread thr(&EventConsume::run, &evtd);
}

void TearDown() override {

}
void *zctx;
}

void *init_publish(void *zctx)
{
void *mock_pub = zmq_socket (zctx, ZMQ_PUB);
EXPECT_TRUE(NULL != mock_pub);
EXPECT_EQ(0, zmq_connect(mock_pub, get_config(XSUB_END_KEY).c_str()));

/* Provide time for async connect to complete */
this_thread::sleep_for(chrono::milliseconds(200));

return mock_pub;
}


TEST_F(EventDbFixture, validate_events)
{
DBConnector db("EVENT_DB", 0, true);
void* pub_handle = init_publish(zctx);
// pub_handle = events_init_publisher("test_db");
for(int i = 0; i < ARRAY_SIZE(events); i++) {
string tag = string("test_db_tag_") + to_string(i);
const event_params_t params = {{"type-id", events[i].type-id},
{ "resource", events[i].resource},
{ "action", events[i].action},
{ "text", events[i].text}};

event_publish(pub_handle, tag, &params);
}
}
12 changes: 10 additions & 2 deletions src/sonic-eventd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ RSYSLOG-PLUGIN_TARGET := rsyslog_plugin/rsyslog_plugin
RSYSLOG-PLUGIN_TEST := rsyslog_plugin_tests/tests
EVENTD_MONIT := tools/events_monit_test.py
EVENTD_MONIT_CONF := tools/monit_events
EVENTDB_TARGET := eventdb
EVENTDB_DEFAULT_PROFILE := var/evprofile/default.json
EVENTDB_PROF := etc/eventd.json

CP := cp
MKDIR := mkdir
Expand All @@ -19,7 +22,7 @@ PWD := $(shell pwd)

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS) $(OBJS)
-include $(C_DEPS) $(OBJS) $(EVENTDB_OBJS)
endif
endif

Expand All @@ -31,10 +34,11 @@ endif

all: sonic-eventd eventd-tool rsyslog-plugin

sonic-eventd: $(OBJS)
sonic-eventd: $(OBJS) $(EVENTDB_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: G++ Linker'
$(CC) $(LDFLAGS) -o $(EVENTD_TARGET) $(OBJS) $(LIBS)
$(CC) $(LDFLAGS) -o $(EVENTDB_TARGET) $(EVENTDB_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '

Expand Down Expand Up @@ -73,12 +77,16 @@ rsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS)
install:
$(MKDIR) -p $(DESTDIR)/usr/bin
$(MKDIR) -p $(DESTDIR)/etc/monit/conf.d
$(MKDIR) -p $(DESTDIR)/etc/evprofile
$(CP) $(EVENTD_TARGET) $(DESTDIR)/usr/bin
$(CP) $(EVENTD_TOOL) $(DESTDIR)/usr/bin
$(CP) $(EVENTD_PUBLISH_TOOL) $(DESTDIR)/usr/bin
$(CP) $(RSYSLOG-PLUGIN_TARGET) $(DESTDIR)/usr/bin
$(CP) $(EVENTD_MONIT) $(DESTDIR)/usr/bin
$(CP) $(EVENTD_MONIT_CONF) $(DESTDIR)/etc/monit/conf.d
$(CP) $(EVENTDB_TARGET) $(DESTDIR)/usr/bin
$(CP) $(EVENTDB_PROF) $(DESTDIR)/etc/eventd.json
$(CP) $(EVENTDB_DEFAULT_PROFILE) $(DESTDIR)/etc/evprofile/default.json

deinstall:
$(RM) -rf $(DESTDIR)/usr
Expand Down
3 changes: 3 additions & 0 deletions src/sonic-eventd/debian/sonic-eventd.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
usr/bin/eventd
usr/bin/eventdb
usr/bin/events_tool
usr/bin/events_publish_tool.py
etc/evprofile/default.json
etc/eventd.json
5 changes: 5 additions & 0 deletions src/sonic-eventd/etc/eventd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"__README__": "Specify size of event history table. Whichever limit is hit first, eventd wraps event history table around and deletes older records.",
"max-records": 40000,
"max-days": 30
}
Loading