Skip to content

Commit 31a64cf

Browse files
committed
Apply logger patch
1 parent 4cf8a59 commit 31a64cf

File tree

8 files changed

+38
-24
lines changed

8 files changed

+38
-24
lines changed

duckdb

Submodule duckdb updated 83 files

extension/httpfs/create_secret_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ bool CreateS3SecretFunctions::TryRefreshS3Secret(ClientContext &context, const S
158158
try {
159159
auto res = secret_manager.CreateSecret(context, refresh_input);
160160
auto &new_secret = dynamic_cast<const KeyValueSecret &>(*res->secret);
161-
DUCKDB_LOG_INFO(context, "httpfs.SecretRefresh", "Successfully refreshed secret: %s, new key_id: %s",
161+
DUCKDB_LOG_INFO(context, "Successfully refreshed secret: %s, new key_id: %s",
162162
secret_to_refresh.secret->GetName(), new_secret.TryGetValue("key_id").ToString());
163163
return true;
164164
} catch (std::exception &ex) {

extension/httpfs/httpfs.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "duckdb/common/thread.hpp"
99
#include "duckdb/common/types/hash.hpp"
1010
#include "duckdb/function/scalar/strftime_format.hpp"
11-
#include "duckdb/logging/http_logger.hpp"
11+
#include "duckdb/logging/file_system_logger.hpp"
1212
#include "duckdb/main/client_context.hpp"
1313
#include "duckdb/main/database.hpp"
1414
#include "duckdb/main/secret/secret_manager.hpp"
@@ -32,7 +32,8 @@ shared_ptr<HTTPUtil> HTTPFSUtil::GetHTTPUtil(optional_ptr<FileOpener> opener) {
3232
return make_shared_ptr<HTTPFSUtil>();
3333
}
3434

35-
unique_ptr<HTTPParams> HTTPFSUtil::InitializeParameters(optional_ptr<FileOpener> opener, optional_ptr<FileOpenerInfo> info) {
35+
unique_ptr<HTTPParams> HTTPFSUtil::InitializeParameters(optional_ptr<FileOpener> opener,
36+
optional_ptr<FileOpenerInfo> info) {
3637
auto result = make_uniq<HTTPFSParams>(*this);
3738
result->Initialize(opener);
3839

@@ -277,8 +278,8 @@ void TimestampToTimeT(timestamp_t timestamp, time_t &result) {
277278

278279
HTTPFileHandle::HTTPFileHandle(FileSystem &fs, const OpenFileInfo &file, FileOpenFlags flags,
279280
unique_ptr<HTTPParams> params_p)
280-
: FileHandle(fs, file.path, flags), params(std::move(params_p)), http_params(params->Cast<HTTPFSParams>()), flags(flags), length(0),
281-
buffer_available(0), buffer_idx(0), file_offset(0), buffer_start(0), buffer_end(0) {
281+
: FileHandle(fs, file.path, flags), params(std::move(params_p)), http_params(params->Cast<HTTPFSParams>()),
282+
flags(flags), length(0), buffer_available(0), buffer_idx(0), file_offset(0), buffer_start(0), buffer_end(0) {
282283
// check if the handle has extended properties that can be set directly in the handle
283284
// if we have these properties we don't need to do a head request to obtain them later
284285
if (file.extended_info) {
@@ -342,6 +343,9 @@ unique_ptr<FileHandle> HTTPFileSystem::OpenFileExtended(const OpenFileInfo &file
342343

343344
auto handle = CreateHandle(file, flags, opener);
344345
handle->Initialize(opener);
346+
347+
DUCKDB_LOG_FILE_SYSTEM_OPEN((*handle));
348+
345349
return std::move(handle);
346350
}
347351

@@ -356,6 +360,8 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
356360
throw InternalException("Cached file not initialized properly");
357361
}
358362
memcpy(buffer, hfh.cached_file_handle->GetData() + location, nr_bytes);
363+
DUCKDB_LOG_FILE_SYSTEM_READ(handle, nr_bytes, location);
364+
hfh.file_offset = location + nr_bytes;
359365
return;
360366
}
361367

@@ -366,17 +372,19 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
366372
bool skip_buffer = hfh.flags.DirectIO() || hfh.flags.RequireParallelAccess();
367373
if (skip_buffer && to_read > 0) {
368374
GetRangeRequest(hfh, hfh.path, {}, location, (char *)buffer, to_read);
369-
375+
DUCKDB_LOG_FILE_SYSTEM_READ(handle, nr_bytes, location);
370376
// Update handle status within critical section for parallel access.
371377
if (hfh.flags.RequireParallelAccess()) {
372378
std::lock_guard<std::mutex> lck(hfh.mu);
373379
hfh.buffer_available = 0;
374380
hfh.buffer_idx = 0;
381+
hfh.file_offset = location + nr_bytes;
375382
return;
376383
}
377384

378385
hfh.buffer_available = 0;
379386
hfh.buffer_idx = 0;
387+
hfh.file_offset = location + nr_bytes;
380388
return;
381389
}
382390

@@ -423,14 +431,15 @@ void HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes, id
423431
}
424432
}
425433
}
434+
hfh.file_offset = location + nr_bytes;
435+
DUCKDB_LOG_FILE_SYSTEM_READ(handle, nr_bytes, location);
426436
}
427437

428438
int64_t HTTPFileSystem::Read(FileHandle &handle, void *buffer, int64_t nr_bytes) {
429439
auto &hfh = handle.Cast<HTTPFileHandle>();
430440
idx_t max_read = hfh.length - hfh.file_offset;
431441
nr_bytes = MinValue<idx_t>(max_read, nr_bytes);
432442
Read(handle, buffer, nr_bytes, hfh.file_offset);
433-
hfh.file_offset += nr_bytes;
434443
return nr_bytes;
435444
}
436445

@@ -642,6 +651,10 @@ void HTTPFileHandle::Initialize(optional_ptr<FileOpener> opener) {
642651
http_params.state = make_shared_ptr<HTTPState>();
643652
}
644653

654+
if (opener) {
655+
TryAddLogger(*opener);
656+
}
657+
645658
auto current_cache = TryGetMetadataCache(opener, hfs);
646659

647660
bool should_write_cache = false;
@@ -711,5 +724,7 @@ void HTTPFileHandle::StoreClient(unique_ptr<HTTPClient> client) {
711724
client_cache.StoreClient(std::move(client));
712725
}
713726

714-
HTTPFileHandle::~HTTPFileHandle() = default;
727+
HTTPFileHandle::~HTTPFileHandle() {
728+
DUCKDB_LOG_FILE_SYSTEM_CLOSE((*this));
729+
};
715730
} // namespace duckdb

extension/httpfs/httpfs_client.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "httpfs_client.hpp"
22
#include "http_state.hpp"
3-
#include "duckdb/logging/http_logger.hpp"
43

54
#define CPPHTTPLIB_OPENSSL_SUPPORT
65
#include "httplib.hpp"
@@ -21,9 +20,6 @@ class HTTPFSClient : public HTTPClient {
2120
client->set_read_timeout(http_params.timeout, http_params.timeout_usec);
2221
client->set_connection_timeout(http_params.timeout, http_params.timeout_usec);
2322
client->set_decompress(false);
24-
if (http_params.logger) {
25-
SetLogger(*http_params.logger);
26-
}
2723
if (!http_params.bearer_token.empty()) {
2824
client->set_bearer_token_auth(http_params.bearer_token.c_str());
2925
}
@@ -38,9 +34,6 @@ class HTTPFSClient : public HTTPClient {
3834
state = http_params.state;
3935
}
4036

41-
void SetLogger(HTTPLogger &logger) {
42-
client->set_logger(logger.GetLogger<duckdb_httplib_openssl::Request, duckdb_httplib_openssl::Response>());
43-
}
4437
unique_ptr<HTTPResponse> Get(GetRequestInfo &info) override {
4538
if (state) {
4639
state->get_count++;

extension/httpfs/include/httpfs_client.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ struct FileOpenerInfo;
99
class HTTPState;
1010

1111
struct HTTPFSParams : public HTTPParams {
12-
HTTPFSParams(HTTPUtil &http_util) : HTTPParams(http_util) {}
12+
HTTPFSParams(HTTPUtil &http_util) : HTTPParams(http_util) {
13+
}
1314

1415
static constexpr bool DEFAULT_ENABLE_SERVER_CERT_VERIFICATION = false;
1516
static constexpr uint64_t DEFAULT_HF_MAX_PER_PAGE = 0;
@@ -25,7 +26,8 @@ struct HTTPFSParams : public HTTPParams {
2526

2627
class HTTPFSUtil : public HTTPUtil {
2728
public:
28-
unique_ptr<HTTPParams> InitializeParameters(optional_ptr<FileOpener> opener, optional_ptr<FileOpenerInfo> info) override;
29+
unique_ptr<HTTPParams> InitializeParameters(optional_ptr<FileOpener> opener,
30+
optional_ptr<FileOpenerInfo> info) override;
2931
unique_ptr<HTTPClient> InitializeClient(HTTPParams &http_params, const string &proto_host_port) override;
3032

3133
static unordered_map<string, string> ParseGetParameters(const string &text);

extension/httpfs/s3fs.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "duckdb.hpp"
55
#ifndef DUCKDB_AMALGAMATION
66
#include "duckdb/common/exception/http_exception.hpp"
7+
#include "duckdb/logging/log_type.hpp"
8+
#include "duckdb/logging/file_system_logger.hpp"
79
#include "duckdb/common/helper.hpp"
810
#include "duckdb/common/thread.hpp"
911
#include "duckdb/common/types/timestamp.hpp"
@@ -838,6 +840,8 @@ void S3FileSystem::Write(FileHandle &handle, void *buffer, int64_t nr_bytes, idx
838840
s3fh.file_offset += bytes_to_write;
839841
bytes_written += bytes_to_write;
840842
}
843+
844+
DUCKDB_LOG_FILE_SYSTEM_WRITE(handle, bytes_written, s3fh.file_offset - bytes_written);
841845
}
842846

843847
static bool Match(vector<string>::const_iterator key, vector<string>::const_iterator key_end,
@@ -918,8 +922,8 @@ vector<OpenFileInfo> S3FileSystem::Glob(const string &glob_pattern, FileOpener *
918922
string common_prefix_continuation_token;
919923
do {
920924
auto prefix_res =
921-
AWSListObjectV2::Request(prefix_path, *http_params, s3_auth_params, common_prefix_continuation_token,
922-
HTTPState::TryGetState(opener).get());
925+
AWSListObjectV2::Request(prefix_path, *http_params, s3_auth_params,
926+
common_prefix_continuation_token, HTTPState::TryGetState(opener).get());
923927
AWSListObjectV2::ParseFileList(prefix_res, s3_keys);
924928
auto more_prefixes = AWSListObjectV2::ParseCommonPrefix(prefix_res);
925929
common_prefixes.insert(common_prefixes.end(), more_prefixes.begin(), more_prefixes.end());

test/sql/secret/secret_refresh.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ statement ok
6161
FROM "s3://test-bucket/test-file.parquet"
6262

6363
query I
64-
SELECT message[0:46] FROM duckdb_logs WHERE type='httpfs.SecretRefresh'
64+
SELECT message[0:46] FROM duckdb_logs WHERE message like '%Successfully refreshed secret%'
6565
----
6666
Successfully refreshed secret: s1, new key_id:
6767

@@ -84,7 +84,7 @@ FROM "s3://test-bucket/test-file.parquet"
8484
HTTP 403
8585

8686
query I
87-
SELECT message[0:46] FROM duckdb_logs WHERE type='httpfs.SecretRefresh'
87+
SELECT message[0:46] FROM duckdb_logs WHERE message like '%Successfully refreshed secret%'
8888
----
8989
Successfully refreshed secret: s1, new key_id:
9090

@@ -125,5 +125,5 @@ HTTP 403
125125

126126
# -> log empty
127127
query II
128-
SELECT log_level, message FROM duckdb_logs WHERE type='httpfs.SecretRefresh'
128+
SELECT log_level, message FROM duckdb_logs WHERE message like '%Successfully refreshed secret%'
129129
----

test/sql/secret/secret_refresh_attach.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ ATTACH 's3://test-bucket/presigned/attach.db' AS db (READONLY 1);
4545

4646
# Secret refresh has been triggered
4747
query II
48-
SELECT log_level, message FROM duckdb_logs WHERE type='httpfs.SecretRefresh'
48+
SELECT log_level, message FROM duckdb_logs WHERE message like '%Successfully refreshed secret%'
4949
----
5050
INFO Successfully refreshed secret: uhuh_this_mah_sh, new key_id: all the girls

0 commit comments

Comments
 (0)