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

[pull] master from netdata:master #349

Merged
merged 4 commits into from
Feb 7, 2025
Merged

Conversation

pull[bot]
Copy link

@pull pull bot commented Feb 7, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Update the systemd journal watcher to handle symlinked directories, add agent version to OTP responses, fix a memory leak in the dictionary implementation, and improve database archiving logic. Also, fix a bug in extent writing and update disk space calculations.

New Features:

  • The systemd journal watcher now correctly handles symlinked directories.

Bug Fixes:

  • Fix a memory leak when freeing dictionary items.

Enhancements:

  • Add the agent version to OTP responses.
  • Improve the database archiving logic to consider the number of active instances.
  • Handle symlinked directories correctly in the systemd journal watcher.
  • Update disk space calculations after extent writes.

stelfrag and others added 4 commits February 7, 2025 17:17
Add agent_version to the challegne response
* fix incomplete implementation for journal watcher

* debug messages logged as info to verify operation

* detect symlinks to directories

* added error handling to all inotify calls

* fix for amazon linux not supporting IN_MASK_CREATE

* fix cleanup when removing directories and symlinks to directories
…rdinality (#19594)

Add check for instances_active > 0 (coverity warning div by 0)
* Cleanup request

* Safe release of wal after ctx_current_disk_space_increase and ctx_io_write_op_bytes
@pull pull bot added the ⤵️ pull label Feb 7, 2025
@pull pull bot merged commit 766c47d into webfutureiorepo:master Feb 7, 2025
Copy link

sourcery-ai bot commented Feb 7, 2025

Reviewer's Guide by Sourcery

This pull request enhances the systemd journal watcher by adding better event logging with inotify event masks, symlink resolution, and improved error handling. Additional improvements include refactoring of resource cleanup and minor adjustments in journal file and dictionary handling, as well as updates to the data engine and OTP payload.

Sequence Diagram for Processing Inotify Events in Journal Watcher

sequenceDiagram
    participant Inotify as Inotify
    participant JW as JournalWatcher
    participant Logger as Logger
    participant Resolver as SymlinkResolver

    Inotify->>JW: Receive inotify_event
    JW->>JW: errno_clear()
    JW->>JW: get_path_from_wd(watcher, event.wd)
    alt Watch descriptor not found
      JW->>Logger: Log missing watch descriptor
      JW-->>Inotify: Return (ignore event)
    else
      JW->>Logger: Log event details with event.mask
      alt Event is IN_CREATE or IN_MOVED_TO
        JW->>JW: sleep 1ms (stabilize symlink)
        JW->>Resolver: realpath(fullPath)
        Resolver-->>JW: Return resolved_path
        JW->>Logger: Log new/updated symlinked directory
        JW->>JW: (if directory) call watch_directory_and_subdirectories()
      else if Directory deletion/move event
        JW->>Logger: Log directory delete/move event
        JW->>JW: remove_directory_watch(watcher, inotifyFd, path_to_use)
      else if Journal file event
        JW->>JW: dictionary_set(watcher->pending, path_to_use, NULL, 0)
      else
        JW->>Logger: Log ignored event
      end
    end
Loading

Updated Class Diagram for Watcher Structures

classDiagram
    class Watcher {
      +WatchEntry *watchList
      +int watchCount
      +int watchListSize
      +DICTIONARY *pending
      +SYMLINKED_DIRS_JudyLSet symlinkedDirs
      +size_t errors
    }

    class WatchEntry {
      +int wd
      +char *path
      +int slot
    }

    Watcher --> WatchEntry : contains
Loading

File-Level Changes

Change Details Files
Improved systemd journal watcher functionality and error handling
  • Added ENUM_STR_MAP_DEFINE and BITMAP_STR_DEFINE_FUNCTIONS to map inotify event masks to human-readable strings
  • Introduced a new type and functions to manage symlinked directories using JudyL sets
  • Added calls to errno_clear() in several critical functions
  • Modified inotify_rm_watch calls to check return values and log errors
  • Enhanced watch_directory_and_subdirectories to resolve symlinks and use realpaths for accurate directory tracking
  • Updated condition in remove_directory_watch to correctly identify subpath relationships
  • Enhanced process_event to log detailed event mask information using buffer conversion, sleep briefly before processing to allow symlink resolution, and adjust event handling logic based on symlink presence
  • Added a new function process_inotify_events to read and process buffered inotify events in a robust manner
  • Refactored journal_watcher_main to initialize a buffered reader and use the new event processing function, plus added cleanup for symlinked directories
src/collectors/systemd-journal.plugin/systemd-journal-watcher.c
Adjusted disk space and IO write accounting in journalfile extent write
  • Moved ctx_current_disk_space_increase and ctx_io_write_op_bytes calls to earlier in the function logic
  • Removed duplicate calls at the end of journalfile_v1_extent_write
src/database/engine/journalfile.c
Refactored dictionary item freeing behavior
  • Moved the item_free_name call after executing delete callback in dict_item_free_with_hooks to ensure proper ordering
src/libnetdata/dictionary/dictionary-item.h
Updated JSON payload for OTP response
  • Modified aclk_send_otp_response to include agent_version field in the JSON output
src/aclk/aclk_otp.c
Enhanced extreme cardinality check in worker context
  • Added an additional check for instances_active in the condition evaluating extreme cardinality triggers
src/database/contexts/worker.c
Performed minor cleanup in RRD engine extent write
  • Added a uv_fs_req_cleanup call after the fs write request in extent write worker function
src/database/engine/rrdengine.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

2 participants