Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable relaying log events via FFI #542

Merged
merged 32 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d441c19
checkpoint
nicklan Nov 26, 2024
e66118c
works :)
nicklan Nov 26, 2024
9150a0d
add file/line and COLORS
nicklan Nov 26, 2024
9107d04
proper log line formatting
nicklan Nov 26, 2024
41c08bf
feature flag it all
nicklan Nov 26, 2024
1ee3092
remove comment
nicklan Nov 26, 2024
c84e02d
update docs a bit
nicklan Nov 26, 2024
ca674d2
minor fixes
nicklan Nov 26, 2024
6e8c3e5
Merge branch 'main' into ffi-logging-take-1
nicklan Nov 26, 2024
34e53f6
add a test
nicklan Nov 27, 2024
7ad2c09
cleanups for docs and tests
nicklan Nov 27, 2024
2716128
Merge branch 'main' into ffi-logging-take-1
nicklan Dec 2, 2024
cb272a9
print target + don't allocate
nicklan Dec 2, 2024
43435c2
validate max_level
nicklan Dec 2, 2024
7378cfe
address comments
nicklan Dec 3, 2024
130ece6
update macro
nicklan Dec 3, 2024
679556e
fmt
nicklan Dec 3, 2024
819a54b
Merge branch 'main' into ffi-logging-take-1
nicklan Dec 3, 2024
dc7a2e4
clippy fix
nicklan Dec 3, 2024
973eed1
macro cleanup
nicklan Dec 3, 2024
76743da
actually is even more simple
nicklan Dec 3, 2024
f5716cf
address comments
nicklan Dec 4, 2024
013491c
Merge branch 'main' into ffi-logging-take-1
nicklan Dec 5, 2024
cee2caa
moar testing
nicklan Dec 5, 2024
eab8105
address nit
nicklan Dec 6, 2024
9918bb0
address nit
nicklan Dec 6, 2024
20de800
printlns for windwos
nicklan Dec 6, 2024
ef50fe9
fix windows test
nicklan Dec 6, 2024
baacea6
Merge branch 'main' into ffi-logging-take-1
nicklan Dec 6, 2024
07de218
fmt
nicklan Dec 6, 2024
4f3429d
don't need set_global_default to be pub
nicklan Dec 6, 2024
61a274a
Merge branch 'main' into ffi-logging-take-1
nicklan Dec 6, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
cargo build
popd
pushd ffi
cargo b --features default-engine,sync-engine,test-ffi
cargo b --features default-engine,sync-engine,test-ffi,tracing
popd
- name: build and run read-table test
run: |
Expand Down
3 changes: 3 additions & 0 deletions ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ crate-type = ["lib", "cdylib", "staticlib"]

[dependencies]
tracing = "0.1"
tracing-core = { version = "0.1", optional = true }
tracing-subscriber = { version = "0.3", optional = true, features = [ "json" ] }
url = "2"
delta_kernel = { path = "../kernel", default-features = false, features = [
"developer-visibility",
Expand Down Expand Up @@ -51,6 +53,7 @@ default-engine = [
"arrow-data",
"arrow-schema",
]
tracing = [ "tracing-core", "tracing-subscriber" ]
sync-engine = ["delta_kernel/sync-engine"]
developer-visibility = []
test-ffi = []
6 changes: 3 additions & 3 deletions ffi/examples/read-table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ This example is built with [cmake]. Instructions below assume you start in the d
Note that prior to building these examples you must build `delta_kernel_ffi` (see [the FFI readme] for details). TLDR:
```bash
# from repo root
$ cargo build -p delta_kernel_ffi [--release] [--features default-engine]
$ cargo build -p delta_kernel_ffi [--release] [--features default-engine, tracing]
# from ffi/ dir
$ cargo build [--release] [--features default-engine]
$ cargo build [--release] [--features default-engine, tracing]
```

There are two configurations that can currently be configured in cmake:
Expand Down Expand Up @@ -62,4 +62,4 @@ If you don't want to have to install this, you can run `ccmake ..` (`cmake-gui.e
from the `build` directory, and turn `OFF`/uncheckmark `PRINT_DATA`. Then "configure" and
"generate" and follow the above instructions again.

[cmake]: https://cmake.org/
[cmake]: https://cmake.org/
56 changes: 56 additions & 0 deletions ffi/examples/read-table/read_table.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>

#include "arrow.h"
#include "read_table.h"
Expand Down Expand Up @@ -150,13 +151,68 @@ void free_partition_list(PartitionList* list) {
free(list);
}

static const char *LEVEL_STRING[] = {
"ERROR", "WARN", "INFO", "DEBUG", "TRACE"
};

// define some ansi color escapes so we can have nice colored output in our logs
#define RED "\x1b[31m"
scovich marked this conversation as resolved.
Show resolved Hide resolved
#define BLUE "\x1b[34m"
#define DIM "\x1b[2m"
#define RESET "\x1b[0m"

void tracing_callback(struct Event event) {
struct timeval tv;
char buffer[32];
gettimeofday(&tv, NULL);
struct tm *tm_info = gmtime(&tv.tv_sec);
strftime(buffer, 26, "%Y-%m-%dT%H:%M:%S", tm_info);
char* level_color = event.level < 3 ? RED : BLUE;
printf(
scovich marked this conversation as resolved.
Show resolved Hide resolved
"%s%s.%06dZ%s [%sKernel %s%s] %s%.*s%s: %.*s\n",
DIM,
buffer,
(int)tv.tv_usec, // safe, microseconds are in int range
RESET,
level_color,
LEVEL_STRING[event.level],
RESET,
DIM,
(int)event.target.len,
event.target.ptr,
RESET,
(int)event.message.len,
event.message.ptr);
if (event.file.ptr) {
printf(
" %sat%s %.*s:%i\n",
scovich marked this conversation as resolved.
Show resolved Hide resolved
DIM,
RESET,
(int)event.file.len,
event.file.ptr,
event.line);
}
}

void log_line_callback(KernelStringSlice line) {
printf("%.*s", (int)line.len, line.ptr);
}

int main(int argc, char* argv[])
{
if (argc < 2) {
printf("Usage: %s table/path\n", argv[0]);
return -1;
}

#ifdef VERBOSE
enable_event_tracing(tracing_callback, TRACE);
// we could also do something like this if we want less control over formatting
// enable_formatted_log_line_tracing(log_line_callback, TRACE, FULL, true, true, false, false);
#else
enable_event_tracing(tracing_callback, INFO);
#endif

char* table_path = argv[1];
printf("Reading table at %s\n", table_path);

Expand Down
Loading
Loading