24#ifndef ETHANLOGCLIENT_H
25#define ETHANLOGCLIENT_H
27#include "ContainerId.h"
38typedef struct sd_event sd_event;
39typedef struct sd_event_source sd_event_source;
46 unsigned allowedLevels,
unsigned rate,
unsigned burstSize,
47 const std::string& memCgroupMountPoint);
59 inline bool closed()
const
61 return (mSource ==
nullptr);
70 static constexpr unsigned LOG_LEVEL_FATAL = (0x1 << 0);
71 static constexpr unsigned LOG_LEVEL_ERROR = (0x1 << 1);
72 static constexpr unsigned LOG_LEVEL_WARNING = (0x1 << 2);
73 static constexpr unsigned LOG_LEVEL_MILESTONE = (0x1 << 3);
74 static constexpr unsigned LOG_LEVEL_INFO = (0x1 << 4);
75 static constexpr unsigned LOG_LEVEL_DEBUG = (0x1 << 5);
79 uint32_t revents,
void *userData);
84 int processLogLevel(
const char *field, ssize_t len,
struct iovec *iov)
const;
85#if (AI_BUILD_TYPE == AI_DEBUG)
86 int processPid(
const char *field, ssize_t len,
struct iovec *iov)
const;
88 int processTimestamp(
const char *field, ssize_t len,
struct iovec *iov)
const;
90 int processCodeFile(
const char *field, ssize_t len,
struct iovec *iov)
const;
92 int processCodeLine(
const char *field, ssize_t len,
struct iovec *iov)
const;
93 int processMessage(
const char *field, ssize_t len,
struct iovec *iov)
const;
97#if (AI_BUILD_TYPE == AI_DEBUG)
103 static constexpr ssize_t MAX_LOG_MSG_LENGTH = 512;
105 static constexpr char RECORD_DELIM =
'\x1e';
106 static constexpr char FIELD_DELIM =
'\x1f';
110 const std::string mName;
112 const unsigned mAllowedLevels;
114 sd_event_source *mSource;
116 std::string mIdentifier;
118 char mMsgBuf[(MAX_LOG_MSG_LENGTH * 2)];
121 bool mRateLimitingEnabled;
125 const unsigned int rate;
126 const unsigned int burstSize;
129 std::chrono::steady_clock::time_point lastFill;
131 TokenBucket(
unsigned int rate_,
unsigned int burstSize_)
133 , burstSize(burstSize_)
135 , lastFill(std::chrono::steady_clock::time_point::min())
140 unsigned int mDropped;
141 std::chrono::steady_clock::time_point mFirstDropped;
142 std::chrono::steady_clock::time_point mLastDropped;
144 std::string mDefaultObjectPid;
145 std::string mDefaultSyslogPid;
147 std::string mCgroupPidsPath;
148 mutable std::map<pid_t, pid_t> mNsToRealPidMapping;
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition ContainerId.h:41
Definition EthanLogClient.h:43
int processPid(const char *field, ssize_t len, struct iovec *iov) const
Process the pid field.
Definition EthanLogClient.cpp:733
void setContainerPid(pid_t pid)
Sets the base pid for the client's container.
Definition EthanLogClient.cpp:128
int processCodeFunction(const char *field, ssize_t len, struct iovec *iov) const
Process the function name field.
Definition EthanLogClient.cpp:844
int processTimestamp(const char *field, ssize_t len, struct iovec *iov) const
Process the timestamp field.
Definition EthanLogClient.cpp:695
std::set< pid_t > getAllContainerPids() const
Reads the set of all pids within the client's container.
Definition EthanLogClient.cpp:964
static int pipeFdHandler(sd_event_source *source, int fd, uint32_t revents, void *userData)
Callback called when data to read on the logging pipe.
Definition EthanLogClient.cpp:150
int processThreadName(const char *field, ssize_t len, struct iovec *iov) const
Process the thread name field.
Definition EthanLogClient.cpp:794
int processMessage(const char *field, ssize_t len, struct iovec *iov) const
Process the message field.
Definition EthanLogClient.cpp:712
pid_t readNsPidFromProc(pid_t pid) const
Given a pid (in global namespace) tries to find what it's namespace pid is.
Definition EthanLogClient.cpp:1009
int processCodeLine(const char *field, ssize_t len, struct iovec *iov) const
Process the line number field.
Definition EthanLogClient.cpp:814
pid_t findRealPid(pid_t nsPid) const
Attempts to find the pid number in the root pid namespace from a pid in the containers namespace.
Definition EthanLogClient.cpp:906
void processLogData()
Process some log data from a client pipe.
Definition EthanLogClient.cpp:389
int processLogLevel(const char *field, ssize_t len, struct iovec *iov) const
Process the log level field.
Definition EthanLogClient.cpp:642
bool shouldDrop()
Returns true if the message should be dropped due to rate limiting.
Definition EthanLogClient.cpp:297
int processCodeFile(const char *field, ssize_t len, struct iovec *iov) const
Process the function name field.
Definition EthanLogClient.cpp:864
Definition EthanLogClient.h:124