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 #325

Merged
merged 6 commits into from
Jan 28, 2025
Merged

Conversation

pull[bot]
Copy link

@pull pull bot commented Jan 28, 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

Improve the metadata cleanup process and update documentation with new examples.

New Features:

  • Add support for connecting to PostgreSQL using a Unix socket with a custom port.

Enhancements:

  • Improve the efficiency of metadata cleanup operations by removing unnecessary steps and optimizing database queries.
  • Remove unnecessary chart label deletion logic during node unregistration.
  • Restructure metadata scanning and storage to reduce overhead and improve performance.

Tests:

  • Add tests to verify the correctness of metadata cleanup operations.

stelfrag and others added 6 commits January 27, 2025 21:09
* Add worker for alert queue processing

* Add a worker job to monitor wait for execution
Make sure to worker_idle() after every host processing
* Add workers
Do not delete labels when removing a node
Complete one scan for chart and dimension metadata check

* Fix logs, formatting

* Remove unused function

* Code cleanup

* Fixed missing prepared statement check

* Do checks for vacuum at most every 60 seconds
@pull pull bot added the ⤵️ pull label Jan 28, 2025
@pull pull bot merged commit 605a4e2 into webfutureiorepo:master Jan 28, 2025
Copy link

sourcery-ai bot commented Jan 28, 2025

Reviewer's Guide by Sourcery

This pull request focuses on improving the metadata cleanup process by introducing several changes to how metadata is stored and deleted. It also includes changes to the database vacuuming process and the way labels are handled.

Sequence diagram for improved metadata cleanup process

sequenceDiagram
    participant Host
    participant MetadataWorker
    participant SQLite

    Host->>MetadataWorker: Queue metadata update
    activate MetadataWorker
    MetadataWorker->>MetadataWorker: Begin transaction
    MetadataWorker->>SQLite: Store host metadata
    MetadataWorker->>SQLite: Store chart metadata
    MetadataWorker->>SQLite: Store dimension metadata
    MetadataWorker->>MetadataWorker: Commit transaction
    MetadataWorker->>MetadataWorker: Run cleanup loop
    MetadataWorker->>SQLite: Vacuum database if needed
    deactivate MetadataWorker
Loading

Class diagram for metadata storage changes

classDiagram
    class MetadataWorker {
        -wc: metadata_wc*
        -work_buffer: BUFFER*
        -pending_ae_list: judy_list_t*
        -pending_ctx_cleanup_list: judy_list_t*
        -pending_uuid_deletion: judy_list_t*
        +store_metadata()
        +run_cleanup_loop()
        +vacuum_database()
    }

    class SQLiteMetadata {
        +store_chart_metadata()
        +store_dimension_metadata()
        +store_host_systeminfo()
        +check_dimension_metadata()
        +check_chart_metadata()
        +check_label_metadata()
    }

    MetadataWorker --> SQLiteMetadata: uses
Loading

State diagram for metadata cleanup process

stateDiagram-v2
    [*] --> Idle
    Idle --> ProcessingMetadata: Metadata update queued
    ProcessingMetadata --> StoringData: Begin transaction
    StoringData --> RunningCleanup: Commit transaction
    RunningCleanup --> VacuumingDB: Cleanup completed
    VacuumingDB --> Idle: Vacuum completed

    note right of ProcessingMetadata: Improved batch processing
    note right of RunningCleanup: Removed MAX_METADATA_CLEANUP limit
    note right of VacuumingDB: New vacuum frequency control
Loading

File-Level Changes

Change Details Files
Refactored metadata cleanup to use row IDs and avoid unnecessary full table scans.
  • Introduced row ID tracking for dimensions, charts, and labels.
  • Modified cleanup loops to use row IDs for more efficient processing.
  • Removed the limit on the number of metadata cleanup operations.
  • Added a check to avoid running cleanup if there are no new rows to process.
src/database/sqlite/sqlite_metadata.c
Removed chart and dimension check intervals.
  • Removed METADATA_DIM_CHECK_INTERVAL and METADATA_CHART_CHECK_INTERVAL constants.
  • Adjusted the logic to use a single maintenance repeat interval.
src/database/sqlite/sqlite_metadata.c
Consolidated chart and dimension metadata storage.
  • Modified store_chart_metadata and store_dimension_metadata to use thread-local prepared statements.
  • Removed the SQLITE_RESET calls after each insert.
  • Added error handling for failed metadata storage.
src/database/sqlite/sqlite_metadata.c
Improved database vacuuming.
  • Introduced a new constant DATABASE_VACUUM_FREQUENCY_SECONDS to control vacuum frequency.
  • Modified the vacuuming logic to run periodically instead of on every cleanup.
  • Added a check to avoid vacuuming if the free pages are below the threshold.
src/database/sqlite/sqlite_metadata.c
Removed the deletion of chart labels during host unregistration.
  • Removed the delete_host_chart_labels function.
  • Removed the call to metadata_delete_host_chart_labels from sql_unregister_node.
  • Removed the METADATA_DELETE_HOST_CHART_LABELS event.
  • Removed the metadata_delete_host_chart_labels function.
src/database/sqlite/sqlite_metadata.c
src/database/sqlite/sqlite_aclk.c
Added a dedicated worker for storing host metadata.
  • Introduced a new worker UV_EVENT_STORE_HOST.
  • Moved the host metadata storage logic to the new worker.
  • Added a new worker for storing chart metadata UV_EVENT_STORE_CHART.
  • Added a new worker for storing dimension metadata UV_EVENT_STORE_DIMENSION.
src/database/sqlite/sqlite_metadata.c
src/daemon/libuv_workers.c
src/daemon/libuv_workers.h
Improved host label handling.
  • Modified the host label storage to use a single SQL statement with ON CONFLICT clause.
  • Added a check to avoid storing labels if the host does not have the RRDHOST_FLAG_METADATA_LABELS flag set.
src/database/sqlite/sqlite_metadata.c
Added a new worker for alert queue processing.
  • Introduced a new worker WORKER_HEALTH_JOB_ALARM_LOG_QUEUE.
  • Added a new worker WORKER_HEALTH_JOB_WAIT_EXEC.
  • Moved the alert queue processing logic to the new worker.
src/health/health_event_loop.c
src/daemon/libuv_workers.c
src/daemon/libuv_workers.h
Updated libsensors vendoring.
  • Updated the minimum required CMake version for libsensors.
  • Removed the FindLibSensors.cmake file.
src/collectors/debugfs.plugin/libsensors/CMakeLists.txt
packaging/cmake/Modules/FindLibSensors.cmake

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.

4 participants