Skip to content

Framework: Add Prometheus observability metrics - #241

Open
razor950 wants to merge 4 commits into
MafiaHub:developfrom
razor950:feat/prometheus
Open

Framework: Add Prometheus observability metrics#241
razor950 wants to merge 4 commits into
MafiaHub:developfrom
razor950:feat/prometheus

Conversation

@razor950

@razor950 razor950 commented Jul 21, 2026

Copy link
Copy Markdown

Vendor prometheus-cpp-lite behind a framework-owned registry and expose a
configurable metrics endpoint.

Instrument server ticks, HTTP routes, networking, replication, jobs,
scripting, resources, and masterlist updates. Add registry and job-system
metric coverage.

Summary by CodeRabbit

  • New Features

    • Added selectable metrics backend (Prometheus-compatible or disabled) plus a unified metrics registry API.
    • Added extensive monitoring across HTTP (per-route method/status, latency, in-flight), server lifecycle/handshakes, networking, jobs, replication, scripting, and resource restarts.
    • Added a configurable, protected metrics HTTP endpoint (default /metrics) with optional bearer-token access.
  • Bug Fixes

    • Improved timing for tick scheduling using a monotonic clock and refined metrics capture for effective HTTP statuses and handler exceptions.
  • Tests

    • Expanded metrics unit tests to cover both backends and verify job batching behavior.

Vendor prometheus-cpp-lite behind a framework-owned registry and expose a
  configurable metrics endpoint.

Instrument server ticks, HTTP routes, networking, replication, jobs,
  scripting, resources, and masterlist updates. Add registry and job-system
  metric coverage.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cb4dce28-b7e7-4d2d-b7ff-ba6174812206

📥 Commits

Reviewing files that changed from the base of the PR and between e191cc8 and 6846b3d.

📒 Files selected for processing (8)
  • code/framework/src/http/webserver.cpp
  • code/framework/src/integrations/server/instance.cpp
  • code/framework/src/integrations/server/instance.h
  • code/framework/src/scripting/builtins/events.cpp
  • code/framework/src/scripting/resource/resource_manager.cpp
  • code/tests/modules/metrics_ut.h
  • vendors/prometheus-cpp-lite/include/prometheus/core.h
  • vendors/prometheus-cpp-lite/include/prometheus/summary.h
🚧 Files skipped from review as they are similar to previous changes (6)
  • code/framework/src/scripting/resource/resource_manager.cpp
  • code/framework/src/http/webserver.cpp
  • code/tests/modules/metrics_ut.h
  • vendors/prometheus-cpp-lite/include/prometheus/summary.h
  • vendors/prometheus-cpp-lite/include/prometheus/core.h
  • code/framework/src/integrations/server/instance.cpp

Walkthrough

The framework adds configurable Prometheus and no-op metrics backends, instruments HTTP, server, job, networking, replication, and scripting paths, exposes protected metrics, and adds backend, exposition, and job-scheduling tests.

Changes

Metrics observability

Layer / File(s) Summary
Metrics registry, backends, and vendored library
code/framework/src/metrics/*, vendors/prometheus-cpp-lite/*, CMakeLists.txt, code/framework/CMakeLists.txt, vendors/CMakeLists.txt
Adds metric handles, backend selection, Prometheus rendering, vendored metric implementations, build targets, compatibility APIs, and installation rules.
HTTP and server lifecycle metrics
code/framework/src/http/webserver.cpp, code/framework/src/integrations/server/*
Records route status, duration, in-flight requests, tick timing, uptime, masterlist outcomes, and exposes an optional bearer-protected metrics endpoint.
Job scheduling metrics
code/framework/src/jobs/*
Tracks task scheduling, queue depth, execution timing, exceptions, blocking calls, callback depth, and batch execution.
Transport and connection metrics
code/framework/src/networking/network_peer.*, network_server.*
Records transport statistics, RPC signals, packet counts, authentication failures, readiness, kicks, and closure reasons.
Replication instrumentation
code/framework/src/networking/replication/*
Records serialization, interest candidates and selections, entity lifecycle, ownership changes, stale epochs, and rejected updates.
Scripting instrumentation and validation
code/framework/src/scripting/*, code/tests/*
Counts script activity and resource restarts, and validates rendering, backend behavior, metric handles, job metrics, and batch scheduling.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Suggested reviewers: segfaultd

Poem

A rabbit counts routes in the moonlight,
While gauges hop softly in flight.
Jobs queue in a row,
Packets shimmer and glow,
And metrics bloom bright overnight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 51.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding Prometheus observability metrics to the framework.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 10

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
code/framework/src/networking/network_server.cpp (1)

175-197: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Shutdown() doesn't clear _peerIdentities.

Shutdown() bulk-clears _acceptedClients, _authenticatedClients, and _readyClients and resets the associated gauges, but _peerIdentities (populated via SetPeerIdentity) is left untouched. Per-connection disconnects go through ClearClientState, which does erase the identity entry — this bulk path is the one exception, leaving stale identity data around after shutdown.

🧹 Proposed fix
         _acceptedClients.clear();
         _authenticatedClients.clear();
         _readyClients.clear();
+        _peerIdentities.clear();
         if (_authenticatedConnections) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/framework/src/networking/network_server.cpp` around lines 175 - 197,
Update NetworkServer::Shutdown() to clear _peerIdentities alongside
_acceptedClients, _authenticatedClients, and _readyClients before destroying the
peer, ensuring no stale identity entries remain after bulk shutdown.
🧹 Nitpick comments (5)
vendors/prometheus-cpp-lite/include/prometheus/prometheus.h (1)

1-14: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add #pragma once header guard.

This is the only header in the vendored set without a guard. As per coding guidelines, **/*.{h,hh,hpp} files should "Use #pragma once for header guards". Also, Line 9 uses <prometheus/file_saver.h> while Lines 2-7 use quoted includes — align for consistency.

♻️ Proposed change
+#pragma once
 
 `#include` "prometheus/counter.h"
 `#include` "prometheus/gauge.h"
 `#include` "prometheus/summary.h"
 `#include` "prometheus/histogram.h"
 `#include` "prometheus/benchmark.h"
 `#include` "prometheus/info.h"
-
-#include <prometheus/file_saver.h>
+#include "prometheus/file_saver.h"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@vendors/prometheus-cpp-lite/include/prometheus/prometheus.h` around lines 1 -
14, Add `#pragma` once at the beginning of prometheus.h to prevent repeated
inclusion, and change the file_saver.h include to use the same quoted-include
style as the other local prometheus headers.

Source: Coding guidelines

code/framework/src/jobs/job_system.cpp (1)

48-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract a ScheduledCounter(priority) helper to match QueueGauge/WaitHistogram/ExecutionHistogram.

Both Schedule overloads repeat the same priority == ftl::TaskPriority::High ? g_jobsSchedHigh : g_jobsSchedNormal ternary twice (once to null-check, once to dereference), duplicated across two call sites. The file already has the right pattern (QueueGauge, WaitHistogram, ExecutionHistogram) for exactly this kind of priority-keyed lookup.

♻️ Suggested helper + usage
         Metrics::Gauge *QueueGauge(ftl::TaskPriority priority) {
             return priority == ftl::TaskPriority::High ? g_jobsQueueHigh : g_jobsQueueNormal;
         }
+
+        Metrics::Counter *ScheduledCounter(ftl::TaskPriority priority) {
+            return priority == ftl::TaskPriority::High ? g_jobsSchedHigh : g_jobsSchedNormal;
+        }
-        if (priority == ftl::TaskPriority::High ? g_jobsSchedHigh : g_jobsSchedNormal) {
-            (priority == ftl::TaskPriority::High ? g_jobsSchedHigh : g_jobsSchedNormal)->Inc();
-        }
+        if (auto *scheduled = ScheduledCounter(priority)) {
+            scheduled->Inc();
+        }

(apply the same replacement in the WaitGroup* overload)

Also applies to: 152-167, 175-190

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/framework/src/jobs/job_system.cpp` around lines 48 - 58, Extract a
`ScheduledCounter(ftl::TaskPriority priority)` helper alongside `QueueGauge`,
`WaitHistogram`, and `ExecutionHistogram`, returning the high- or
normal-priority scheduled counter. Update both `Schedule` overloads, including
the `WaitGroup*` overload, to use this helper for null-checking and
dereferencing instead of repeating the priority ternary.
code/framework/src/jobs/job_system.h (1)

320-326: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant duplicate private: access specifier.

A second private: block was added for the new metric members instead of folding them into the existing one two lines below. Purely cosmetic but easy to clean up.

🧹 Merge the two private sections
       private:
-        Metrics::Counter *_blockingCalls    = nullptr;
-        Metrics::Gauge *_callbackQueueDepth = nullptr;
-        void RecordBlockingCall();
-
-      private:
         std::unique_ptr<ftl::TaskScheduler> _scheduler;
+        Metrics::Counter *_blockingCalls    = nullptr;
+        Metrics::Gauge *_callbackQueueDepth = nullptr;
+        void RecordBlockingCall();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/framework/src/jobs/job_system.h` around lines 320 - 326, Remove the
redundant first private: access specifier around the Metrics::Counter,
Metrics::Gauge, and RecordBlockingCall declarations, folding those members into
the existing private section that contains _scheduler.
code/framework/src/networking/replication/replication_manager.h (1)

141-149: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

RecordStaleEpochDrop/RecordRejectedNonOwnerUpdate/RecordSerialization are public.

These three are declared with no access specifier between them and the preceding public members (OnClosedConnection, AllocConnection), making them callable by any code holding a ReplicationManager* — which is reachable via the existing public NetworkPeer::GetReplicationManager() escape hatch. They exist solely to let NetworkEntity::Serialize/Deserialize report instrumentation events; exposing them publicly lets any caller (including scripting/game code) fabricate fw_repl_* metric values with no corresponding replication event.

Move them under private: and grant NetworkEntity friend access instead.

♻️ Proposed fix
-        void RecordStaleEpochDrop(int channel);
-        void RecordRejectedNonOwnerUpdate();
-        void RecordSerialization(double durationSeconds, uint64_t bytes);
-
       private:
+        friend class NetworkEntity;
+        void RecordStaleEpochDrop(int channel);
+        void RecordRejectedNonOwnerUpdate();
+        void RecordSerialization(double durationSeconds, uint64_t bytes);
+
         bool _isServer             = false;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/framework/src/networking/replication/replication_manager.h` around lines
141 - 149, Restrict RecordStaleEpochDrop, RecordRejectedNonOwnerUpdate, and
RecordSerialization to a private section in ReplicationManager, and add
NetworkEntity as a friend so its Serialize/Deserialize instrumentation calls
remain valid. Keep the existing public networking callbacks and connection
allocation methods unchanged.
code/framework/src/networking/network_peer.cpp (1)

52-56: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Per-tick scratch containers are allocated fresh every call.

SampleTransportStats() runs every Update() tick and constructs three DataStructures::List objects plus an std::unordered_set<uint64_t> (live) on every invocation. Elsewhere in this same PR, InterestGrid explicitly documents reusing scratch containers as members so its per-tick hot path "performs no steady-state allocations." Consider applying the same pattern here — hoist addresses, guids, stats, and live to reusable members (clear/reserve instead of reconstruct) to avoid per-tick heap churn.

Also applies to: 84-86

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/framework/src/networking/network_peer.cpp` around lines 52 - 56, Update
NetworkPeer::SampleTransportStats to reuse persistent scratch members for
addresses, guids, stats, and live instead of constructing them on each tick.
Clear the containers at the start of each sample, reserve appropriate capacity
where needed, and preserve the existing statistics-sampling behavior without
steady-state per-tick allocations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@code/framework/src/http/webserver.cpp`:
- Around line 19-44: Update RouteStatusCounter and MakeRouteMetrics to accept an
HTTP method and include it as a metric label alongside route for all counters,
histogram, and gauge registrations. Thread the method through every
MakeRouteMetrics caller, including RegisterRequest and RegisterPostRequest, so
identical paths use distinct metrics; avoid resetting an already-registered
in-flight gauge during re-registration.
- Around line 53-58: Update EffectiveStatus so an unset response status defaults
to 200 unconditionally; remove the req.ranges-based 206 inference, while
preserving explicitly assigned response statuses.

In `@code/framework/src/integrations/server/instance.cpp`:
- Around line 318-336: Update MetricsConfig so metrics exporting is disabled by
default, while preserving explicit opt-in behavior in the _opts.metrics.enabled
mounting condition. Also ensure the unauthenticated token-empty case is
prominently surfaced when the exporter is enabled, using warning-level logging
rather than the existing info-only message; do not alter the existing
authenticated request flow.
- Around line 1017-1031: Update the `_nextTick` assignment to preserve the
fractional tick interval instead of converting
`Utils::Time::SecondsToMs(_opts.worldConfig.tickInterval)` to integral
`std::chrono::milliseconds`. Use a duration representation with sub-millisecond
precision while retaining the existing steady-clock scheduling behavior.

In `@code/framework/src/scripting/builtins/events.cpp`:
- Around line 722-726: Update EmitLocalCallback to measure synchronous handler
duration around its InvokeHandlersToPromiseArray call, using the same
steady_clock timing and conditional g_scriptEventDur->Observe pattern as the
existing dispatch path. Preserve the current handler invocation and promise
handling behavior.
- Around line 669-677: Clarify the outbound metric as tracking network-bound
events: remove its increment from the local/native path in EmitInternal and
increment g_scriptEventsOut within BroadcastLuaEvent for emitServer and
emitAllClients. Preserve g_scriptEventsIn for client-scoped incoming events and
ensure local Events.emit or emitLocal are not counted as outbound.

In `@code/framework/src/scripting/resource/resource_manager.cpp`:
- Around line 475-477: Update both restart-counter sites in
code/framework/src/scripting/resource/resource_manager.cpp at lines 475-477 and
557-559 to call g_scriptRestarts->Inc with affected.size() instead of the
default increment, so each affected resource is counted.

In `@code/tests/modules/metrics_ut.h`:
- Around line 141-144: Update the global fw_jobs_* metric assertions in the
affected test to avoid exact count matching against process-wide registry
values. Replace the hardcoded 0 and 1 expectations with assertions that tolerate
prior JobSystem activity, such as parsing values and verifying the relevant
counts are at least one where appropriate, while preserving the existing
metric-name and priority-label checks.

In `@vendors/prometheus-cpp-lite/include/prometheus/core.h`:
- Around line 144-164: Add the standard headers <charconv> and <limits> to the
includes used by WriteValue so both the std::to_chars path and the
std::numeric_limits fallback compile reliably.

In `@vendors/prometheus-cpp-lite/include/prometheus/summary.h`:
- Around line 341-367: Update collect() so excess observations are removed from
the underlying live_data storage, not only from the local observations snapshot.
Apply the max_observations trim through the live_data API or state used by
Snapshot, while preserving the sorted snapshot for quantile computation and
existing snapshot_count/snapshot_sum behavior.

---

Outside diff comments:
In `@code/framework/src/networking/network_server.cpp`:
- Around line 175-197: Update NetworkServer::Shutdown() to clear _peerIdentities
alongside _acceptedClients, _authenticatedClients, and _readyClients before
destroying the peer, ensuring no stale identity entries remain after bulk
shutdown.

---

Nitpick comments:
In `@code/framework/src/jobs/job_system.cpp`:
- Around line 48-58: Extract a `ScheduledCounter(ftl::TaskPriority priority)`
helper alongside `QueueGauge`, `WaitHistogram`, and `ExecutionHistogram`,
returning the high- or normal-priority scheduled counter. Update both `Schedule`
overloads, including the `WaitGroup*` overload, to use this helper for
null-checking and dereferencing instead of repeating the priority ternary.

In `@code/framework/src/jobs/job_system.h`:
- Around line 320-326: Remove the redundant first private: access specifier
around the Metrics::Counter, Metrics::Gauge, and RecordBlockingCall
declarations, folding those members into the existing private section that
contains _scheduler.

In `@code/framework/src/networking/network_peer.cpp`:
- Around line 52-56: Update NetworkPeer::SampleTransportStats to reuse
persistent scratch members for addresses, guids, stats, and live instead of
constructing them on each tick. Clear the containers at the start of each
sample, reserve appropriate capacity where needed, and preserve the existing
statistics-sampling behavior without steady-state per-tick allocations.

In `@code/framework/src/networking/replication/replication_manager.h`:
- Around line 141-149: Restrict RecordStaleEpochDrop,
RecordRejectedNonOwnerUpdate, and RecordSerialization to a private section in
ReplicationManager, and add NetworkEntity as a friend so its
Serialize/Deserialize instrumentation calls remain valid. Keep the existing
public networking callbacks and connection allocation methods unchanged.

In `@vendors/prometheus-cpp-lite/include/prometheus/prometheus.h`:
- Around line 1-14: Add `#pragma` once at the beginning of prometheus.h to prevent
repeated inclusion, and change the file_saver.h include to use the same
quoted-include style as the other local prometheus headers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a574143-a4e4-4892-977e-faaef78040a9

📥 Commits

Reviewing files that changed from the base of the PR and between ecd28ad and 0be7d4c.

📒 Files selected for processing (38)
  • code/framework/CMakeLists.txt
  • code/framework/src/http/webserver.cpp
  • code/framework/src/integrations/server/instance.cpp
  • code/framework/src/integrations/server/instance.h
  • code/framework/src/jobs/job_system.cpp
  • code/framework/src/jobs/job_system.h
  • code/framework/src/metrics/registry.cpp
  • code/framework/src/metrics/registry.h
  • code/framework/src/networking/network_peer.cpp
  • code/framework/src/networking/network_peer.h
  • code/framework/src/networking/network_server.cpp
  • code/framework/src/networking/network_server.h
  • code/framework/src/networking/replication/interest_grid.cpp
  • code/framework/src/networking/replication/interest_grid.h
  • code/framework/src/networking/replication/network_entity.cpp
  • code/framework/src/networking/replication/replication_manager.cpp
  • code/framework/src/networking/replication/replication_manager.h
  • code/framework/src/scripting/builtins/events.cpp
  • code/framework/src/scripting/resource/resource_manager.cpp
  • code/tests/framework_ut.cpp
  • code/tests/modules/metrics_ut.h
  • vendors/CMakeLists.txt
  • vendors/prometheus-cpp-lite/.gitignore
  • vendors/prometheus-cpp-lite/CMakeLists.txt
  • vendors/prometheus-cpp-lite/LICENSE
  • vendors/prometheus-cpp-lite/README.md
  • vendors/prometheus-cpp-lite/include/prometheus/atomic_floating.h
  • vendors/prometheus-cpp-lite/include/prometheus/benchmark.h
  • vendors/prometheus-cpp-lite/include/prometheus/core.h
  • vendors/prometheus-cpp-lite/include/prometheus/counter.h
  • vendors/prometheus-cpp-lite/include/prometheus/file_saver.h
  • vendors/prometheus-cpp-lite/include/prometheus/gauge.h
  • vendors/prometheus-cpp-lite/include/prometheus/histogram.h
  • vendors/prometheus-cpp-lite/include/prometheus/info.h
  • vendors/prometheus-cpp-lite/include/prometheus/prometheus.h
  • vendors/prometheus-cpp-lite/include/prometheus/simpleapi.h
  • vendors/prometheus-cpp-lite/include/prometheus/summary.h
  • vendors/prometheus-cpp-lite/src/simpleapi.cpp

Comment thread code/framework/src/http/webserver.cpp Outdated
Comment thread code/framework/src/http/webserver.cpp Outdated
Comment on lines +318 to +336
if (_opts.metrics.enabled && _opts.webServerEnabled && _webServer) {
const std::string token = _opts.metrics.token;
const std::string path = _opts.metrics.path.empty() ? std::string("/metrics") : _opts.metrics.path;
_webServer->RegisterRequest(path, [token](const httplib::Request &req, httplib::Response &res) {
if (!token.empty()) {
const std::string auth = req.get_header_value("Authorization");
if (auth != "Bearer " + token) {
res.status = 401;
res.set_content("unauthorized\n", "text/plain; version=0.0.4");
return;
}
}
thread_local std::string buf;
Metrics::Registry::Get().Render(buf);
res.set_content(buf, "text/plain; version=0.0.4");
res.status = 200;
});
Logging::GetLogger(FRAMEWORK_INNER_HTTP)->info("Prometheus /metrics exporter mounted at {}", path);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

/metrics is enabled and unauthenticated by default.

MetricsConfig::enabled defaults to true and token defaults to empty (see instance.h MetricsConfig), so unless an operator explicitly sets a token, this mounts /metrics on the same public webserver with no auth check at all (if (!token.empty()) skips the check entirely). That exposes uptime, connection/auth-failure counts, tick health, and build info to anyone reaching the HTTP port. Consider defaulting enabled to false, or logging a loud warning (not just info) when the exporter is mounted without a token, so insecure defaults are visible to operators.

Separately, the token check itself (auth != "Bearer " + token) is a plain (non-constant-time) string compare — a minor hardening opportunity if this is ever exposed beyond a trusted network.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@code/framework/src/integrations/server/instance.cpp` around lines 318 - 336,
Update MetricsConfig so metrics exporting is disabled by default, while
preserving explicit opt-in behavior in the _opts.metrics.enabled mounting
condition. Also ensure the unauthenticated token-empty case is prominently
surfaced when the exporter is enabled, using warning-level logging rather than
the existing info-only message; do not alter the existing authenticated request
flow.

Comment thread code/framework/src/integrations/server/instance.cpp Outdated
Comment thread code/framework/src/scripting/builtins/events.cpp Outdated
Comment thread code/framework/src/scripting/builtins/events.cpp
Comment thread code/framework/src/scripting/resource/resource_manager.cpp
Comment thread code/tests/modules/metrics_ut.h Outdated
Comment thread vendors/prometheus-cpp-lite/include/prometheus/core.h
Comment thread vendors/prometheus-cpp-lite/include/prometheus/summary.h

@zpl-zak zpl-zak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. Here are some things that I would propose to improve:

  • It is good that the metrics are backend-agnostic on the surface but it would also be nice to have the backend implementation independent from Prometheus. There should be an ability to change, using CMake, what kind of backend you would like to build with. We can use Prometheus as a default for now. That means that the registry system should be decoupled from the actual internal implementation that includes Prometheus together with framework metrics implementation.
  • Please strip the AI comments. They are excessive and don't really help much with the understanding of the implementation.
  • Could you provide some detail on the changes to the JobSystem::ScheduleBatch(...) function please?
  • I would also suggest providing the compile-time ability to disable metrics altogether. Such an option should only provide stubs. However, there should be no code pulled from Prometheus and such.

Thank you!

  - add CMake-selectable Prometheus and no-op backends
  - keep Prometheus as the default backend
  - preserve job metrics with allocation-efficient batch scheduling
  - add backend and ScheduleBatch test coverage
applied the coderabbit suggested changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants