Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
df39c67
filesystem: break out RawFile/RawInstance from File/Instance
sesmith177 Jan 30, 2019
62f8086
fix typo
sesmith177 Jan 30, 2019
6ba486c
Merge branch 'master' into filesystem-decorator
sesmith177 Feb 4, 2019
1f291bf
add CREATE + RDWR to spelling dictionary
sesmith177 Feb 4, 2019
43e5665
Merge branch 'master' into filesystem-decorator
sesmith177 Feb 5, 2019
3614b45
Merge branch 'master' into filesystem-decorator
sesmith177 Feb 5, 2019
f50508a
Merge branch 'master' into filesystem-decorator
sesmith177 Feb 5, 2019
779da9c
Address feedback
Feb 5, 2019
1b22c96
add todo
sesmith177 Feb 5, 2019
ac7d4c1
typedef -> using
sesmith177 Feb 6, 2019
a2c8c4f
wip
sesmith177 Feb 6, 2019
443a17a
wip
sesmith177 Feb 6, 2019
8f48f6c
Merge branch 'master' into filesystem-decorator
sesmith177 Feb 6, 2019
5db0857
rename File -> AccessLogFile and RawFile -> File
Feb 7, 2019
7e219e7
Merge branch 'master' into filesystem-decorator
sesmith177 Feb 11, 2019
05862aa
update todo
sesmith177 Feb 11, 2019
1b62da4
add Stats::Store& back to Api ctor
sesmith177 Feb 11, 2019
4b8fbb3
Merge branch 'master' into filesystem-decorator
sesmith177 Feb 13, 2019
91c161c
Merge branch 'master' into filesystem-decorator
sesmith177 Feb 13, 2019
f8e155d
Revert createApiForTest
Feb 13, 2019
685a541
Merge branch 'master' into filesystem-decorator
Feb 21, 2019
85458c4
only close open files
sesmith177 Feb 21, 2019
b973d12
Merge branch 'master' into filesystem-decorator
Feb 21, 2019
7db72ea
Merge branch 'master' into filesystem-decorator
Feb 21, 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
1 change: 0 additions & 1 deletion include/envoy/access_log/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ envoy_cc_library(
name = "access_log_interface",
hdrs = ["access_log.h"],
deps = [
"//include/envoy/filesystem:filesystem_interface",
"//include/envoy/http:header_map_interface",
"//include/envoy/stream_info:stream_info_interface",
],
Expand Down
35 changes: 28 additions & 7 deletions include/envoy/access_log/access_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,34 @@
#include <string>

#include "envoy/common/pure.h"
#include "envoy/filesystem/filesystem.h"
#include "envoy/http/header_map.h"
#include "envoy/stream_info/stream_info.h"

namespace Envoy {
namespace AccessLog {

class AccessLogFile {
public:
virtual ~AccessLogFile() {}

/**
* Write data to the file.
*/
virtual void write(absl::string_view) PURE;

/**
* Reopen the file.
*/
virtual void reopen() PURE;

/**
* Synchronously flush all pending data to disk.
*/
virtual void flush() PURE;
};

using AccessLogFileSharedPtr = std::shared_ptr<AccessLogFile>;

class AccessLogManager {
public:
virtual ~AccessLogManager() {}
Expand All @@ -25,10 +46,10 @@ class AccessLogManager {
* @param file_name specifies the file to create/open.
* @return the opened file.
*/
virtual Filesystem::FileSharedPtr createAccessLog(const std::string& file_name) PURE;
virtual AccessLogFileSharedPtr createAccessLog(const std::string& file_name) PURE;
};

typedef std::unique_ptr<AccessLogManager> AccessLogManagerPtr;
using AccessLogManagerPtr = std::unique_ptr<AccessLogManager>;

/**
* Interface for access log filters.
Expand All @@ -46,7 +67,7 @@ class Filter {
const Http::HeaderMap& response_trailers) PURE;
};

typedef std::unique_ptr<Filter> FilterPtr;
using FilterPtr = std::unique_ptr<Filter>;

/**
* Abstract access logger for requests and connections.
Expand All @@ -68,7 +89,7 @@ class Instance {
const StreamInfo::StreamInfo& stream_info) PURE;
};

typedef std::shared_ptr<Instance> InstanceSharedPtr;
using InstanceSharedPtr = std::shared_ptr<Instance>;

/**
* Interface for access log formatter.
Expand All @@ -92,7 +113,7 @@ class Formatter {
const StreamInfo::StreamInfo& stream_info) const PURE;
};

typedef std::unique_ptr<Formatter> FormatterPtr;
using FormatterPtr = std::unique_ptr<Formatter>;

/**
* Interface for access log provider.
Expand All @@ -116,7 +137,7 @@ class FormatterProvider {
const StreamInfo::StreamInfo& stream_info) const PURE;
};

typedef std::unique_ptr<FormatterProvider> FormatterProviderPtr;
using FormatterProviderPtr = std::unique_ptr<FormatterProvider>;

} // namespace AccessLog
} // namespace Envoy
13 changes: 1 addition & 12 deletions include/envoy/api/os_sys_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef SysCallResult<int> SysCallIntResult;
typedef SysCallResult<ssize_t> SysCallSizeResult;
typedef SysCallResult<void*> SysCallPtrResult;
typedef SysCallResult<std::string> SysCallStringResult;
typedef SysCallResult<bool> SysCallBoolResult;

class OsSysCalls {
public:
Expand All @@ -49,18 +50,6 @@ class OsSysCalls {
*/
virtual SysCallIntResult ioctl(int sockfd, unsigned long int request, void* argp) PURE;

/**
* Open file by full_path with given flags and mode.
* @return file descriptor.
*/
virtual SysCallIntResult open(const std::string& full_path, int flags, int mode) PURE;

/**
* Write num_bytes to fd from buffer.
* @return number of bytes written if non negative, otherwise error code.
*/
virtual SysCallSizeResult write(int fd, const void* buffer, size_t num_bytes) PURE;

/**
* @see writev (man 2 writev)
*/
Expand Down
1 change: 1 addition & 0 deletions include/envoy/filesystem/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ envoy_cc_library(
name = "filesystem_interface",
hdrs = ["filesystem.h"],
deps = [
"//include/envoy/api:os_sys_calls_interface",
"//include/envoy/event:dispatcher_interface",
],
)
Expand Down
68 changes: 36 additions & 32 deletions include/envoy/filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,74 @@
#include <memory>
#include <string>

#include "envoy/api/os_sys_calls.h"
#include "envoy/common/pure.h"
#include "envoy/event/dispatcher.h"
#include "envoy/thread/thread.h"

#include "absl/strings/string_view.h"

namespace Envoy {
namespace Filesystem {

/**
* Abstraction for a file on disk.
* Abstraction for a basic file on disk.
*/
class File {
public:
virtual ~File() {}

/**
* Write data to the file.
* Open the file with O_RDWR | O_APPEND | O_CREAT
* The file will be closed when this object is destructed
*
* @return bool whether the open succeeded
*/
virtual Api::SysCallBoolResult open() PURE;

/**
* Write the buffer to the file. The file must be explicitly opened before writing.
*
* @return ssize_t number of bytes written, or -1 for failure
*/
virtual Api::SysCallSizeResult write(absl::string_view buffer) PURE;

/**
* Close the file.
*
* @return bool whether the close succeeded
*/
virtual void write(absl::string_view) PURE;
virtual Api::SysCallBoolResult close() PURE;

/**
* Reopen the file.
* @return bool is the file open
*/
virtual void reopen() PURE;
virtual bool isOpen() PURE;

/**
* Synchronously flush all pending data to disk.
* @return string the file path
*/
virtual void flush() PURE;
virtual std::string path() PURE;

/**
* @return string a human-readable string describing the error code
* TODO(sesmith177) Use the IOError class after #5829 merges
Copy link
Member

Choose a reason for hiding this comment

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

I'm going to merge this soon, so up to you if you want to merge that in or just do a quick follow up here.

Copy link
Member Author

Choose a reason for hiding this comment

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

we've got a follow-up queued up; we will fix this there

*/
virtual std::string errorToString(int error) PURE;
};

typedef std::shared_ptr<File> FileSharedPtr;
using FilePtr = std::unique_ptr<File>;

/**
* Captures state, properties, and stats of a file-system.
* Abstraction for some basic filesystem operations
*/
class Instance {
public:
virtual ~Instance() {}

/**
* Creates a file, overriding the flush-interval set in the class.
*
* @param path The path of the file to open.
* @param dispatcher The dispatcher used for set up timers to run flush().
* @param lock The lock.
* @param file_flush_interval_msec Number of milliseconds to delay before flushing.
* @param path The path of the File
* @return a FilePtr. The file is not opened.
*/
virtual FileSharedPtr createFile(const std::string& path, Event::Dispatcher& dispatcher,
Thread::BasicLockable& lock,
std::chrono::milliseconds file_flush_interval_msec) PURE;

/**
* Creates a file, using the default flush-interval for the class.
*
* @param path The path of the file to open.
* @param dispatcher The dispatcher used for set up timers to run flush().
* @param lock The lock.
*/
virtual FileSharedPtr createFile(const std::string& path, Event::Dispatcher& dispatcher,
Thread::BasicLockable& lock) PURE;
virtual FilePtr createFile(const std::string& path) PURE;

/**
* @return bool whether a file exists on disk and can be opened for read.
Expand Down Expand Up @@ -109,8 +115,6 @@ class Instance {
virtual bool illegalPath(const std::string& path) PURE;
};

typedef std::unique_ptr<Watcher> WatcherPtr;

enum class FileType { Regular, Directory, Other };

struct DirectoryEntry {
Expand Down
2 changes: 2 additions & 0 deletions source/common/access_log/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ envoy_cc_library(
deps = [
"//include/envoy/access_log:access_log_interface",
"//include/envoy/api:api_interface",
"//source/common/buffer:buffer_lib",
"//source/common/common:thread_lib",
],
)

Expand Down
Loading