Skip to content

Commit

Permalink
Merge pull request #131 from muflihun/develop
Browse files Browse the repository at this point in the history
2.3.0
  • Loading branch information
abumq authored Mar 23, 2018
2 parents 609edac + a59b20d commit d8719cb
Show file tree
Hide file tree
Showing 40 changed files with 376 additions and 147 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.css linguist-detectable=false
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Change Log

## [2.3.0] - 24-03-2018
### Extensions API
- Added `reset` in `DispatchErrorExtension` which is called when previously failed is no longer failing

### Updates
- Added `stats dyn` and `stats queue`
- Backup keys only visible with `--with-key` parameter
- Max bulk items can be set to 5-500

### Fixes
- Dynamic buffer recovery check fix
- Crash when rotating an invalid file

### Internal Updates
- Abstract server and I/O service
- Use shared pointer to keep reference for the session in the handler

## [2.2.1] - 19-03-2018
### Extensions API
- Added `LogExtension::Level` enum for readability of `LogExtension::Data::level`
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ option (use_boost "Use boost or standalone networking lib" OFF)
option (old_toolchain "Is old toolchain" OFF)

set (RESIDUE_MAJOR "2")
set (RESIDUE_MINOR "2")
set (RESIDUE_PATCH "1")
set (RESIDUE_MINOR "3")
set (RESIDUE_PATCH "0")
set (RESIDUE_VERSION "${RESIDUE_MAJOR}.${RESIDUE_MINOR}.${RESIDUE_PATCH}")
set (RESIDUE_NAME "Residue")

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Some of the notable features are listed below
* Encryption: All the incoming and outgoing data is automatically encrypted. Residue also has several layers and techniques to secure the requests and to prevent unauthorised application from logging without compromising the speed.
* Compression: Residue server and official client libraries provide ability to compress the network packets which makes a big difference in amount of data transferred over the wire.
* Speed is not compromised in any way and there is a lot of testing being done every day to ensure that logging server meets the speed requirements.
* Dynamic buffers allow logs to be queued up in the memory while there is some I/O error (e.g, disk full) and cleared as soon as disk errors are fixed
* Residue extensions allow certain code to be executed in case of specific events (e.g, log dispatch failure) - see [Extensions API](/docs/CONFIGURATION.md#extensions)
* Reliability: We are actively working on making the server much more reliable from restarting from the crash to handling bad traffic.
* Residue comes with various [tools](https://github.com/topics/residue-tools) for devops and [client libraries](https://github.com/topics/residue-client) for easy integration.
* There are many more features available. Please feel free to download your copy of residue binary and give it a try.
Expand Down
24 changes: 23 additions & 1 deletion docs/CLI_COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,31 @@ Only check the schedule for this logger rotation
### `stats`
Displays server stats and number of active sessions

##### `list`
#### `list`
Lists for active sessions (received, sent and how long session has been active for and associated clients if registered)

#### `dyn`
List dynamic buffer status

#### `queue`
List processing queue status

You can also run sampling on the queue by providing `sampling`. Thread will be stalled for the amount of seconds value you provide (valid value from 3 to 10)

For example

```
stats queue sampling 6 --client-id unmanaged
```

It will list the speed of each queue, e.g,

```
Queue For: unmanaged Active: 8376 Backlog: 7442 Speed: 5 items/s (incl. bulk)
```

Sampling is done only on a non-empty _active_ queue

##### `--client-id <client-id>`
Filters stats for specified client. Some of the clients may not be listed as they're only registered when server receives anything from them.

Expand Down
2 changes: 2 additions & 0 deletions samples/extensions/failure-notify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ To install this extension simply add following lines in `extensions` config
"module": "path/to/failure-notify.so",
"description": "Notifies the recipients when log failures have hit the threshold",
"config": {
"script": "send.sh",
"threshold": 20000,
"repeat": false,
"recipients": ["[email protected]"]
}
}
Expand Down
16 changes: 12 additions & 4 deletions samples/extensions/failure-notify/failure-notify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ Extension::Result FailureNotify::execute(const DispatchErrorExtension::Data* con
return {1, true};
}

if (!(conf().get<bool>("repeat", true)) && m_sent) {
return {0, true};
}

m_failureCount++;

if (m_failureCount >= conf().get<unsigned long>("threshold", 200UL)) {
notifyRecipients(data);
m_failureCount = 0UL;
m_sent = true;
}

return {0, true};
Expand All @@ -33,11 +38,14 @@ void FailureNotify::notifyRecipients(const DispatchErrorExtension::Data* const d
JsonDoc recipient(recipientNode);
std::string email = recipient.as<std::string>("");
writeLog("Notifying " + email);

ss << "echo 'Residue dispatch error "
<< std::strerror(data->errorNumber) << ". File: "
<< data->filename << "' | mail -s 'residue err' " << email;
ss << conf().get<std::string>("script", "send.sh") << " '" << std::strerror(data->errorNumber) << "' '" << data->filename << "' " << email;
system(ss.str().c_str());
}
}
}

void FailureNotify::reset()
{
m_failureCount = 0;
m_sent = false;
}
4 changes: 3 additions & 1 deletion samples/extensions/failure-notify/failure-notify.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ using namespace residue;
class FailureNotify : public DispatchErrorExtension {
public:

FailureNotify() : DispatchErrorExtension("failure-notify"), m_failureCount(0UL)
FailureNotify() : DispatchErrorExtension("failure-notify"), m_failureCount(0UL), m_sent(false)
{

}

virtual ~FailureNotify() = default;

virtual Extension::Result execute(const DispatchErrorExtension::Data* const) override;
virtual void reset() override;
private:
unsigned long m_failureCount;
bool m_sent;

void notifyRecipients(const DispatchErrorExtension::Data* const data);
};
Expand Down
3 changes: 3 additions & 0 deletions samples/extensions/failure-notify/send.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Residue dispatch error $1. File: $2" | mail -s 'residue err' $3
51 changes: 0 additions & 51 deletions samples/keys/encrypted-privkey.pem

This file was deleted.

9 changes: 0 additions & 9 deletions samples/keys/encrypted-pubkey.pem

This file was deleted.

30 changes: 30 additions & 0 deletions samples/keys/epri.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,6B8E2DD75947B469A061FC706E612069

hLhpVBm/5npaIhoNDE4m6gLNpwUKd0P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Ew2UqOD8
6EFlkjoyNU76a3bwAVc+ltWx8gBe2Txlu1jTFa1UuZhIyoLPeKG2sh/bew32YfNm
G9AfTezELYdPpta6aMko1u8tVk8ImbwARe83xgMVuF4OKHkA4KxXcq7hZmMZdinV
wDEkLG9KUD7odFaF1wPnpOTeFlCX3MiXpTWLFDquoXFzfiy9XF24J3oEJ6hnZkuv
r0lpjWjVCqEscHVLCqgvWbEqDhlINHyPXWbnCp3m/0ZmT8MkvOABCM5SDy/x6+qo
fYpWv8gKFyb0aU9Kd3tEK2kNQnCJJrRJPbdy0I9A9Kg8BEaTDsbanpXOirPqgm+s
ZI37WUpqyIbr2TRX8SRg3jbBhIcyfjRS5Qn3KA6UIo9SwN+XWChsdVU6xJ2Tlhy+
5BPcqX4YWK+sXAvA6R8qgQ+KajZEi1Zutfpx73WSF0duSROdgNRpQvvP8QYNpRPU
8xlHgRmDXeQ4r5Dzdfjh9RfONek+LYL1R4XMe/O6x8NkG6a40PViJrt3L3VUQPMh
-----END RSA PRIVATE KEY-----
9 changes: 9 additions & 0 deletions samples/keys/epub.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAkVl+xbOQqA8iSXWRNlYu
8Mu1wo9YrGnZUBV52gvR+8QHrYZztDMsgOSjoecvVAPsCbd9h7v2ZJk7sllN/RVs
QQXEjK0zAiASumvL3SWx9mqyFIESWdMNoWvGAQx7qmRv1+AMsgXVK9LrF7QNxXEm
BGZdavRP1MT0E/EvmD5HZvpS329CaBXjTYTYSCH8N4kmh/WAzlVSfwI8Hs/Fh7cJ
/7slaf2aHOi0ulhwXiM+Zt85/pbyAv77Zuysu/U3LJT0kNTTXZWEVWuBGX5Hazf9
dUF9UQNatZjSiHvD7nzXOjvxAoP1cN3MfGhxF0nHBrpy6pJg93jcpsay5HmbdzTP
SwIBEQ==
-----END PUBLIC KEY-----
5 changes: 3 additions & 2 deletions samples/residue.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
{
"client_id": "muflihun00102031",
"public_key": "$RESIDUE_HOME/samples/keys/encrypted-pubkey.pem",
"public_key": "$RESIDUE_HOME/samples/keys/epub.pem",
"loggers": ["residue"]
}
],
Expand All @@ -48,7 +48,8 @@
},
{
"logger_id": "default",
"configuration_file": "$RESIDUE_HOME/samples/configurations/default-Logger.conf"
"configuration_file": "$RESIDUE_HOME/samples/configurations/default-Logger.conf",
"rotation_freq": "hourly"
},
{
"logger_id": "sample-app",
Expand Down
38 changes: 12 additions & 26 deletions src/cli/clients.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@

#include "core/configuration.h"
#include "core/registry.h"
#include "logging/residue-log-dispatcher.h"
#include "tasks/client-integrity-task.h"
#include "utils/utils.h"

using namespace residue;

Clients::Clients(Registry* registry) :
Command("clients",
"List, add or remove clients from the server configuration",
"clients [list] [clean]",
"List clients available on the server (dead or alive)",
"clients [list] [clean] [--with-key] [--with-token]",
registry)
{
}
Expand All @@ -43,7 +42,7 @@ void Clients::execute(std::vector<std::string>&& params, std::ostringstream& res
result << "Clients: " << registry()->clients().size() << std::endl;
}
if (hasParam(params, "list")) {
list(result, hasParam(params, "--with-key"));
list(result, &params);
} else if (hasParam(params, "clean")) {
if (registry()->clientIntegrityTask()->isExecuting()) {
result << "\nAlready running, please try again later" << std::endl;;
Expand All @@ -54,27 +53,10 @@ void Clients::execute(std::vector<std::string>&& params, std::ostringstream& res
registry()->clientIntegrityTask()->kickOff();
result << "\nFinished client integrity task" << std::endl;
}
} else if (hasParam(params, "checkdyn")) {
// check dynamic buffer
ResidueLogDispatcher* dispatcher = el::Helpers::logDispatchCallback<ResidueLogDispatcher>("ResidueLogDispatcher");
if (dispatcher != nullptr) {
if (dispatcher->m_dynamicBuffer.empty()) {
result << "Dynamic buffer is empty";
} else {
result << "Dynamic buffer information:\n";
for (auto& pair : dispatcher->m_dynamicBuffer) {
result << "Logger: " << pair.second.logger->id() << "\t";
result << "Filename: " << pair.first << "\t";
result << "Items: " << pair.second.lines.size() << "\n";
}
}
} else {
result << "Could not extract dispatcher";
}
}
}

void Clients::list(std::ostringstream& result, bool withKey) const
void Clients::list(std::ostringstream& result, const std::vector<std::string>* paramsPtr) const
{
int i = 1;
for (auto& c : registry()->clients()) {
Expand All @@ -83,11 +65,15 @@ void Clients::list(std::ostringstream& result, bool withKey) const
<< ", Age: " << (Utils::now() - c.second.dateCreated()) << "s"
<< ", Status: "
<< (!c.second.isAlive() ? "DEAD" : "ALIVE " + std::to_string(c.second.age() - (Utils::now() - c.second.dateCreated())) + "s");
if (withKey) {
result << ", Key: " << c.second.key();
if (hasParam(*paramsPtr, "--with-token")) {
result << ", Token: " << c.second.token();
}
if (!c.second.backupKey().empty()) {
result << ", Backup Key: " << c.second.backupKey();
if (hasParam(*paramsPtr, "--with-key")) {
result << ", Key: " << c.second.key();

if (!c.second.backupKey().empty()) {
result << ", Backup Key: " << c.second.backupKey();
}
}
result << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/clients.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Clients final : public Command
virtual void execute(std::vector<std::string>&&, std::ostringstream&, bool) const override;

private:
void list(std::ostringstream&, bool withKey) const;
void list(std::ostringstream&, const std::vector<std::string>*) const;
};
}

Expand Down
Loading

0 comments on commit d8719cb

Please sign in to comment.