Skip to content

Implement log extractor - #272

Merged
0xB10C merged 35 commits into
peer-observer:masterfrom
m4ycon:feat/log-extractor
Oct 29, 2025
Merged

0xB10C merged 35 commits into
peer-observer:masterfrom
m4ycon:feat/log-extractor

Conversation

@m4ycon

@m4ycon m4ycon commented Sep 24, 2025

Copy link
Copy Markdown
Collaborator

No description provided.

@m4ycon

m4ycon commented Sep 24, 2025

Copy link
Copy Markdown
Collaborator Author

Creating this Draft just to @edilmedeiros take a look, but feel free to take a look too @0xB10C. It still a WIP I will mark as ready when its done.

@0xB10C

0xB10C commented Sep 25, 2025

Copy link
Copy Markdown
Collaborator

Nice, looks good for a start! Sorry for the conflicts, I was refactoring some parts yesterday. Let me know if you need help rebasing it.

Comment thread extractors/log/src/lib.rs Resolved
@0xB10C 0xB10C mentioned this pull request Sep 25, 2025
4 of 7 tasks
@m4ycon

m4ycon commented Sep 30, 2025

Copy link
Copy Markdown
Collaborator Author

oh sh... I forgot that this repo has actions that run the tests, I got a problem with mine not stopping correctly, so problably these actions will timeout (6h from what I searched). If you see this and they still running, you can stop it @0xB10C.

Comment thread shared/src/log_matchers.rs Resolved
Comment thread shared/src/log_matchers.rs Resolved
Comment thread protobuf/log_extractor.proto Resolved
Comment thread extractors/log/tests/integration.rs Resolved
@m4ycon
m4ycon marked this pull request as ready for review October 1, 2025 02:16
@m4ycon
m4ycon requested a review from 0xB10C October 1, 2025 02:16

@0xB10C 0xB10C left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Had an early look, but didn't do any testing yet. Left a few comments.

Overall, looks good and very clean. Thank you a lot!

Plan to look at this in more detail in the next week.

Comment thread protobuf/log_extractor.proto Resolved
Comment thread shared/src/log_matchers.rs Resolved
Comment thread shared/src/log_matchers.rs Resolved
Comment thread protobuf/log_extractor.proto Outdated
package log_extractor;

message LogEvent {
required uint64 timestamp = 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hm, we already have a timestamp in EventMsg. I wonder if we should just set this one instead of adding another one here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(I agree that the timestamp_subsec_micros is a bit weird, I should probably refactor that!)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This timestamp you talking about is related to when the extractor is publishing that event, right? This one from LogEvent is the one that appears in the actual log and it could be different from the one in EventMsg, maybe I should've specified in its name 🤔... Is it reason enough to maintain it? maybe named like log_timestamp?

Comment thread protobuf/log_extractor.proto Resolved
Comment thread shared/src/log_matchers.rs Resolved
Comment thread shared/Cargo.toml Resolved
Comment thread shared/Cargo.toml Resolved
Comment thread extractors/log/src/lib.rs Resolved
@m4ycon

m4ycon commented Oct 2, 2025

Copy link
Copy Markdown
Collaborator Author

Don't know why but ubuntu action throw at build with a unused value that it is used, and the nix one did build correctly ¯\_(ツ)_/¯

@0xB10C

0xB10C commented Oct 15, 2025

Copy link
Copy Markdown
Collaborator

I haven't forgotten about this and plan to get to it as soon as I have time!

Don't know why but ubuntu action throw at build with a unused value that it is used, and the nix one did build correctly

I'll have a look!

Also, one thing that came to my mind was that I run my nodes with logtimemicros=1 (see https://github.com/0xB10C/peer-observer-infra-library/blob/2c235ce06d594dd0731d4d78cc064bb78e1fc44e/modules/node/node.nix#L163) for higher precision timestamps in the logs. I think it makes sense to support this here too (or at least test that it's supported and doesn't break).

@m4ycon

m4ycon commented Oct 18, 2025

Copy link
Copy Markdown
Collaborator Author

Also, one thing that came to my mind was that I run my nodes with logtimemicros=1 (see https://github.com/0xB10C/peer-observer-infra-library/blob/2c235ce06d594dd0731d4d78cc064bb78e1fc44e/modules/node/node.nix#L163) for higher precision timestamps in the logs. I think it makes sense to support this here too (or at least test that it's supported and doesn't break).

Added support for this option, it was really going to not match with the regex that I made.

  // log_extractor.proto
  required uint64 log_timestamp = 1; // unix timestamp in seconds
  required uint32 log_timestamp_micro = 2; // microseconds part of the timestamp

I separatted in another field on proto because it doesn't have a uint128 as returned by OffsetDateTime::unix_timestamp_nanos to store a microsecond unix time (or nano).

@0xB10C

0xB10C commented Oct 27, 2025 •

Copy link
Copy Markdown
Collaborator

I separatted in another field on proto because it doesn't have a uint128 as returned by OffsetDateTime::unix_timestamp_nanos to store a microsecond unix time (or nano).

I think we can just do as u64. It's not super clean, but a microseconds UNIX epoch timestamp will only overflow an u64 in more than 500 million years :)

Planning to play around with this PR this week.

Comment thread extractors/log/src/error.rs Resolved
@0xB10C
0xB10C force-pushed the feat/log-extractor branch from 6b2d77f to c645b27 Compare October 28, 2025 09:13
Comment thread extractors/log/src/lib.rs Resolved
Comment thread extractors/log/src/lib.rs Resolved
@0xB10C

0xB10C commented Oct 28, 2025 •

Copy link
Copy Markdown
Collaborator

Ok, this seems to be good to go from my side. I haven't worked on adding this to my setup yet, but that can happen later.

Possible followup ideas:

  • add more matchers for different log messages
  • add support for multiline matching. e.g. the bench block connection logs
  • look into fuzzing the matcher input to see if it breaks somewhere
  • ideally, the matcher should return an error on e.g. invalid timestamps and not 0
  • ...

@m4ycon let me know if you think anything else needs to be done here!

@0xB10C

0xB10C commented Oct 28, 2025 •

Copy link
Copy Markdown
Collaborator

Two more things that came to mind:

@0xB10C

0xB10C commented Oct 28, 2025

Copy link
Copy Markdown
Collaborator

coverage report:

master
|| Tested/Total Lines:
|| extractors/ebpf/src/error.rs: 0/34
|| extractors/ebpf/src/main.rs: 0/331
|| extractors/ebpf/src/tracing.gen.rs: 0/371
|| extractors/p2p/src/error.rs: 7/31
|| extractors/p2p/src/lib.rs: 81/107
|| extractors/p2p/src/main.rs: 0/10
|| extractors/p2p/tests/integration.rs: 49/51
|| extractors/rpc/src/error.rs: 0/36
|| extractors/rpc/src/lib.rs: 34/37
|| extractors/rpc/src/main.rs: 0/10
|| extractors/rpc/tests/integration.rs: 45/47
|| shared/src/metricserver.rs: 25/46
|| shared/src/nats_subjects.rs: 9/9
|| shared/src/protobuf/addrman.rs: 8/23
|| shared/src/protobuf/ctypes.rs: 27/147
|| shared/src/protobuf/event_msg.rs: 7/7
|| shared/src/protobuf/mempool.rs: 6/45
|| shared/src/protobuf/net_conn.rs: 7/41
|| shared/src/protobuf/net_msg.rs: 14/298
|| shared/src/protobuf/p2p_extractor.rs: 4/4
|| shared/src/protobuf/primitive.rs: 15/128
|| shared/src/protobuf/rpc.rs: 60/63
|| shared/src/protobuf/validation.rs: 6/13
|| shared/src/testing/nats_publisher.rs: 8/8
|| shared/src/testing/nats_server.rs: 44/57
|| shared/src/util.rs: 21/22
|| tools/connectivity-check/src/main.rs: 0/189
|| tools/connectivity-check/src/metrics.rs: 0/16
|| tools/logger/src/error.rs: 0/20
|| tools/logger/src/lib.rs: 44/51
|| tools/logger/src/main.rs: 0/10
|| tools/logger/tests/integration.rs: 44/47
|| tools/metrics/src/error.rs: 5/24
|| tools/metrics/src/lib.rs: 398/401
|| tools/metrics/src/main.rs: 0/10
|| tools/metrics/src/metrics.rs: 11/11
|| tools/metrics/src/stat_util.rs: 14/14
|| tools/metrics/tests/integration.rs: 66/77
|| tools/websocket/src/error.rs: 0/24
|| tools/websocket/src/lib.rs: 38/44
|| tools/websocket/src/main.rs: 0/10
|| tools/websocket/tests/integration.rs: 54/63
||
38.53% coverage, 1151/2987 lines covered
PR
|| Tested/Total Lines:
|| extractors/ebpf/src/error.rs: 0/34 +0.00%
|| extractors/ebpf/src/main.rs: 0/331 +0.00%
|| extractors/ebpf/src/tracing.gen.rs: 0/371 +0.00%
|| extractors/log/src/error.rs: 0/16
|| extractors/log/src/lib.rs: 30/38
|| extractors/log/src/main.rs: 0/7
|| extractors/log/tests/integration.rs: 55/57
|| extractors/p2p/src/error.rs: 7/31 +0.00%
|| extractors/p2p/src/lib.rs: 82/107 +0.93%
|| extractors/p2p/src/main.rs: 0/10 +0.00%
|| extractors/p2p/tests/integration.rs: 49/51 +0.00%
|| extractors/rpc/src/error.rs: 0/36 +0.00%
|| extractors/rpc/src/lib.rs: 34/37 +0.00%
|| extractors/rpc/src/main.rs: 0/10 +0.00%
|| extractors/rpc/tests/integration.rs: 45/47 +0.00%
|| shared/src/log_matchers.rs: 37/37
|| shared/src/metricserver.rs: 25/46 +0.00%
|| shared/src/nats_subjects.rs: 10/10 +0.00%
|| shared/src/protobuf/addrman.rs: 8/23 +0.00%
|| shared/src/protobuf/ctypes.rs: 27/147 +0.00%
|| shared/src/protobuf/event_msg.rs: 7/7 +0.00%
|| shared/src/protobuf/log_extractor.rs: 8/8
|| shared/src/protobuf/mempool.rs: 6/45 +0.00%
|| shared/src/protobuf/net_conn.rs: 7/41 +0.00%
|| shared/src/protobuf/net_msg.rs: 14/298 +0.00%
|| shared/src/protobuf/p2p_extractor.rs: 4/4 +0.00%
|| shared/src/protobuf/primitive.rs: 15/128 +0.00%
|| shared/src/protobuf/rpc.rs: 60/63 +0.00%
|| shared/src/protobuf/validation.rs: 6/13 +0.00%
|| shared/src/testing/nats_publisher.rs: 8/8 +0.00%
|| shared/src/testing/nats_server.rs: 44/57 +0.00%
|| shared/src/util.rs: 21/22 +0.00%
|| tools/connectivity-check/src/main.rs: 0/189 +0.00%
|| tools/connectivity-check/src/metrics.rs: 0/16 +0.00%
|| tools/logger/src/error.rs: 0/20 +0.00%
|| tools/logger/src/lib.rs: 47/56 -2.35%
|| tools/logger/src/main.rs: 0/10 +0.00%
|| tools/logger/tests/integration.rs: 45/48 +0.13%
|| tools/metrics/src/error.rs: 5/24 +0.00%
|| tools/metrics/src/lib.rs: 406/408 +0.26%
|| tools/metrics/src/main.rs: 0/10 +0.00%
|| tools/metrics/src/metrics.rs: 11/11 +0.00%
|| tools/metrics/src/stat_util.rs: 14/14 +0.00%
|| tools/metrics/tests/integration.rs: 66/77 +0.00%
|| tools/websocket/src/error.rs: 0/24 +0.00%
|| tools/websocket/src/lib.rs: 38/44 +0.00%
|| tools/websocket/src/main.rs: 0/10 +0.00%
|| tools/websocket/tests/integration.rs: 54/63 +0.00%
||
40.93% coverage, 1295/3164 lines covered, +2.40% change in coverage

@m4ycon

m4ycon commented Oct 28, 2025

Copy link
Copy Markdown
Collaborator Author

@m4ycon let me know if you think anything else needs to be done here!

Nothing that should be done in this PR, but I would like to add some points in your list:

  • How to organize a LogMatcher to support many implementations of a same log (e.g. diff btc-core versions), don't think that it'll be difficult but deciding on some pattern it's important.

  • "ideally, the matcher should return an error on e.g. invalid timestamps and not 0", if you say this, I assume that an unexpected error on log-extractor parsing problably won't stop its loop, right? If so I'm ok with it.

It's interesting to say that debug.log is a kind of persistent memory for log extractor 😄, people running a node for months before this was implemented could parse all logs through it and see some result now, unlike other extractors.

Also I'll work on mutated block related logs, as it was the reason I was helping with the log extractor here hehe.

@0xB10C
0xB10C merged commit aad58cc into peer-observer:master Oct 29, 2025
@0xB10C

0xB10C commented Oct 29, 2025

Copy link
Copy Markdown
Collaborator

huge thank you @m4ycon!

Tracking followups in #285

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants