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

Merged
merged 6 commits into from
Feb 24, 2025
Merged

Conversation

pull[bot]
Copy link

@pull pull bot commented Feb 24, 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

Introduce new features for system shutdown handling, memory allocation tracking, and daemon status management. Enhance logging and configuration processes, and update build and CI configurations to support new dependencies and features.

New Features:

  • Introduce a new function to handle system shutdown and suspend events using systemd's D-Bus interface.
  • Add support for tracking and reporting memory allocation calls in the worker utilization metrics.
  • Implement a new mechanism to save and load daemon status to a JSON file, including crash detection and reporting.
  • Add support for posting status files to a remote server for analytics and crash reporting.
  • Introduce a new function to get the system boot time across different operating systems.
  • Add a new function to get the process path for the current executable across different operating systems.

Bug Fixes:

  • Fix potential issues with JSON parsing by ensuring proper handling of required fields and default values.
  • Correct the handling of UUID parsing and comparison to ensure accurate identification of system boot IDs.

Enhancements:

  • Refactor buffer management to improve memory allocation and deallocation tracking.
  • Enhance the logging system to include more detailed information about fatal errors and stack traces.
  • Improve the handling of system memory and disk space queries to provide more accurate and reliable data.
  • Optimize the handling of JSON payloads by introducing new parsing macros and functions.
  • Refactor the initialization and configuration loading process to ensure proper sequencing and error handling.

Build:

  • Add support for building with jemalloc allocator if available, including checks for arena API support.
  • Update CMake configuration to include new source files and dependencies for the added features.

CI:

  • Update GitHub Actions workflows to use the latest version of the upload-artifact action.

Deployment:

  • Enhance the Windows service management script to support running Netdata as a service with proper event logging.

Documentation:

  • Update documentation to reflect changes in the logging system and new features related to system shutdown handling.

Tests:

  • Add new tests to verify the correct behavior of the daemon status file handling and crash detection mechanisms.

Chores:

  • Remove unused or deprecated code related to older logging and memory management mechanisms.

dependabot bot and others added 6 commits February 24, 2025 10:16
… /src/go (#19698)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* detect netdata exit reasons

* log exit initiated

* commented debug logs

* commented debug logs again

* fix windows system shutdown detection

* commented debug logs again

* added exit reason msgid

* test shutdown detection by writing to exit.reason

* implement status file loading/saving

* accept also the shutdown event

* fix windows logs

* run as service from the script - not working yet

* save the first fatal message into the status file

* save memory information in the status file

* load machine guid early enough

* fix loading sequence

* simplify function run once logic; add dependencies on netdata.conf loading when required

* accept service parameter

* build for packaging is required for services

* log last exit status with a proper message; log node id and claim id in the status file

* added /var/cache disk space; fixed bug in rfc3339 parsing

* change log priority based on condition

* SIGINT is normal exit under windows

* wait to wevt provider to be initialized before logging

* Revert "fix windows logs (#19632)"

This reverts commit d8c3dc0.

* fix windows logs - the right way

* set default event log sizes

* added detection of netdata update

* added systemd dbus watcher for systemd shutdown/suspend events

* log system shutdown

* detect system reboot in a better way

* cleanup static thread

* on fatal, call _exit(); linunwind should not skip top calls on the stack

* make the sd bus watcher exit on netdata shutdown

* make the netdata agent version log also print the last exit status

* start watcher when shutdown is initiated; prevent double logging of shutdown initiation

* prepare for sending reports

* a single read per receiver

* track memory calls per worker

* use 4 malloc arenas on parents

* spread higher tiers flushing over time

* pgc and replication tuning

* on child disconnect, get retention from the rrdcontexts worker

* BUFFER: the default size is now 1024 bytes

* use dedicated jemalloc arena for judy allocations

* ARAL: do not double the page size unconditionally; cleanup old members

* double pgc partitions

* fix compiler warning

* make the default replication commit buffer big enough to avoid constant realloc

* post crash reports

* revert log2journal changes

* log2journal minor

* disable the crash report when there was no status file

* increase buffer sizes

* added os_boottime() and os_boot_id(), which are now used in the status file

* log2journal: convert \u000A to \n

* fix headers includes

* fix compilation on non-linux

* for host prefix when getting boot_id and boottime

* write status file to /run/netdata too

* fix /run/netdata on startup

* move the IPC pipe inside the run directory

* exclusive file lock to avoid running concurrently

* allow netdatacli to run from any user and still find the run dir of netdata

* fix pipe failure message

* fix nested loop sharing same variable in ADCS

* fix run_dir and netdatacli on windows

* fix status files on windows

* initialize nd_threads early enough to allow creating threads during initialization

* fix compiler warnings

* on shutdown ignore points with delayed flushing

* fix macos compilation

* added os_type to daemon status

* make daemon status schema ecs compatible

* save daemon status file on every signal

* fix external plugins log to journal

* use special allocators for judy, only on netdata - not the external plugins

* systemd-cat-native: default newline string is \n

* when generating json, prefer special 2 character sequences for common control characters

* fix daemon-status filenames

* log errors when the status file cannot be opened/saved/parsed

* make status file world readable

* do not write status file in /run/netdata; add fall back locations when the file cannot be saved in the cache dir

* move ram and disk into host

* simplified inline subobject parsing for jsonc

* ensure path is an array of at least 128 bytes

* fix non-linux compilation
@pull pull bot added the ⤵️ pull label Feb 24, 2025
@pull pull bot merged commit d28b61e into webfutureiorepo:master Feb 24, 2025
Copy link

sourcery-ai bot commented Feb 24, 2025

Reviewer's Guide by Sourcery

This pull request includes several changes to improve the netdata agent. It refactors the buffer management in libnetdata, adds analytics for memory calls, improves the systemd integration, and fixes several bugs.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Refactors buffer management in libnetdata to improve efficiency and readability.
  • Removes ALWAYS_INLINE from several buffer_* functions in buffer.h.
  • Reorders function definitions in buffer.h for better readability.
  • Replaces buffer_fast_strcat(wb, "-", 1) with buffer_putc(wb, '-') for efficiency.
  • Replaces buffer_fast_strcat(wb, ",", 1) with buffer_putc(wb, ',') for efficiency.
  • Replaces buffer_fast_strcat(wb, "\n", 1) with buffer_putc(wb, '\n') for efficiency.
  • Replaces buffer_fast_strcat(wb, ":", 1) with buffer_putc(wb, ':') for efficiency.
  • Replaces buffer_fast_strcat(wb, "[", 1) with buffer_putc(wb, '[') for efficiency.
  • Replaces buffer_fast_strcat(wb, "{", 1) with buffer_putc(wb, '{') for efficiency.
src/libnetdata/buffer/buffer.h
Adds analytics for memory calls in libnetdata and ml.
  • Introduces WORKERS_MEMORY_CALL enum and related functions for tracking memory calls.
  • Adds workers_memory_call() function to track memory allocation and deallocation calls.
  • Adds memory call tracking to nd-mallocz.c for mallocz, callocz, reallocz, strdupz, strndupz, and freez.
  • Adds memory call tracking to ml_memory.cc for new, new[], delete, and delete[] operators.
  • Adds memory calls chart to pulse-workers.c.
src/libnetdata/worker_utilization/worker_utilization.c
src/libnetdata/worker_utilization/worker_utilization.h
src/ml/ml_memory.cc
src/libnetdata/memory/nd-mallocz.c
src/daemon/pulse/pulse-workers.c
Improves systemd integration by listening for shutdown and suspend events via D-Bus.
  • Adds a new thread to listen for systemd D-Bus events.
  • Adds functions to handle PrepareForShutdown and PrepareForSleep signals.
  • Adds code to exit netdata when a shutdown signal is received.
  • Adds a new service type SERVICE_SYSTEMD.
  • Adds a new static thread for systemd watcher.
src/daemon/daemon-systemd-watcher.c
src/daemon/daemon-systemd-watcher.h
src/daemon/static_threads.c
src/daemon/daemon-service.h
src/daemon/signals.c
Adds a status file to store the last known state of the netdata agent.
  • Introduces DAEMON_STATUS enum and related functions for tracking the agent's status.
  • Adds functions to save and load the status file in JSON format.
  • Adds code to check for crashes and incomplete shutdowns on startup.
  • Adds code to post crash reports to agent-events.
  • Adds a new function daemon_status_file_register_fatal to register fatal messages.
  • Adds a new function netdata_log_exit_reason to log the exit reason.
  • Adds a new function exit_initiated_set to set the exit reason.
  • Adds a new function exit_initiated_reset to reset the exit reason.
  • Adds a new function is_exit_reason_normal to check if the exit reason is normal.
  • Adds a new function os_boottime to get the system boot time.
  • Adds a new function os_boot_id to get the system boot id.
  • Adds a new function os_disk_space to get the disk space information.
  • Adds a new function os_get_process_path to get the process path.
  • Adds a new function os_run_dir to get the run directory.
  • Adds a new function os_file_lock to get a file lock.
  • Adds a new function os_get_file_metadata to get the file metadata.
src/daemon/daemon-status-file.c
src/daemon/daemon-status-file.h
src/daemon/signals.c
src/daemon/daemon.c
src/libnetdata/os/system_memory.h
src/libnetdata/os/disk_space.c
src/libnetdata/os/disk_space.h
src/libnetdata/os/file_metadata.c
src/libnetdata/os/file_metadata.h
src/libnetdata/os/process_path.c
src/libnetdata/os/process_path.h
src/libnetdata/os/boottime.c
src/libnetdata/os/boottime.h
src/libnetdata/os/boot_id.c
src/libnetdata/os/boot_id.h
src/libnetdata/os/run_dir.c
src/libnetdata/os/run_dir.h
src/libnetdata/os/file_lock.c
src/libnetdata/os/file_lock.h
src/libnetdata/exit/exit_initiated.c
src/libnetdata/exit/exit_initiated.h
src/daemon/daemon-shutdown.c
src/libnetdata/log/nd_log.c
src/libnetdata/log/nd_log-internals.h
src/libnetdata/log/nd_log-field-formatters.c
src/libnetdata/log/nd_log.h
src/daemon/config/netdata-conf-global.c
src/daemon/config/netdata-conf.c
Updates the version of prometheus/prometheus dependency in go.mod.
  • Updates the version of github.com/prometheus/prometheus from v0.50.1 to v0.302.0.
src/go/go.mod
Adds support for jemalloc allocator.
  • Adds cmake options to enable jemalloc allocator.
  • Adds jemalloc initialization to libjudy_malloc_init.
  • Adds jemalloc malloc and free functions.
  • Adds HAVE_JEMALLOC_ARENA_API check.
src/libnetdata/libjudy/judy-malloc.c
src/libnetdata/libjudy/judy-malloc.h
CMakeLists.txt
Fixes a bug in health_dyncfg.c where the path was not correctly concatenated.
  • Replaces JSONC_PARSE_SUBOBJECT with JSONC_PARSE_SUBOBJECT_CB in health_dyncfg.c.
src/health/health_dyncfg.c
Fixes a bug in rfc3339.c where the timezone offset was not correctly applied.
  • Fixes a bug in rfc3339.c where the timezone offset was not correctly applied.
src/libnetdata/datetime/rfc3339.c
Fixes a bug in rrddim_collection.c where the last completed point was not flushed.
  • Adds a new function store_metric_at_tier_flush_last_completed to flush the last completed point.
  • Adds a new function store_metric_at_tier_save_last_completed to save the last completed point.
  • Adds a call to store_metric_at_tier_flush_last_completed in rrddim_finalize_collection_and_check_retention.
src/database/rrddim-collection.c
src/database/rrddim-collection.h
src/database/rrddim.c
Fixes a bug in systemd-journal-annotations.c where the UUID was not correctly formatted.
  • Replaces uuid_unparse_lower with uuid_unparse_lower_compact in systemd-journal-annotations.c.
src/libnetdata/log/systemd-journal-annotations.c
Fixes a bug in k8s_kubelet/collect.go and k8s_kubeproxy/collect.go where the bucket was not correctly parsed.
  • Adds strings.CutSuffix to k8s_kubelet/collect.go to remove the .0 suffix from the bucket.
  • Adds strings.TrimSuffix to k8s_kubeproxy/collect.go to remove the .0 suffix from the bucket.
src/go/plugin/go.d/collector/k8s_kubelet/collect.go
src/go/plugin/go.d/collector/k8s_kubeproxy/collect.go

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