SERVER-113183 Mark module boundaries for `observability` (#43349)

GitOrigin-RevId: e810af1916caaedb1cde8d1e1b74bb50b2461daf
This commit is contained in:
Saman Memaripour 2025-10-31 09:30:17 -04:00 committed by MongoDB Bot
parent 3c3218efc7
commit b593b9aece
28 changed files with 87 additions and 45 deletions

View File

@ -600,6 +600,7 @@ observability:
meta:
slack: server-networking-observability
jira: Networking & Observability
fully_marked: true
files:
- src/mongo/db/connection_health_metrics_parameter.idl
- src/mongo/db/not_primary_error_tracker*
@ -624,6 +625,7 @@ observability.tracing:
meta:
slack: server-networking-observability
jira: Networking & Observability
fully_marked: true
files:
- src/mongo/otel/traces/
- src/mongo/util/tracing_support*
@ -632,6 +634,7 @@ observability.metrics:
meta:
slack: server-networking-observability
jira: Networking & Observability
fully_marked: true
files:
- src/mongo/otel/metrics/
@ -639,6 +642,7 @@ observability.ftdc:
meta:
slack: server-networking-observability
jira: Networking & Observability
fully_marked: true
files:
- src/mongo/db/ftdc/

View File

@ -31,6 +31,7 @@ global:
server_parameters:
enableDetailedConnectionHealthMetricLogLines:
mod_visibility: public
description: >-
Enables detailed log lines related to connection health in a cluster.
set_at: [startup, runtime]

View File

@ -30,8 +30,9 @@
#pragma once
#include "mongo/db/client.h"
#include "mongo/util/modules.h"
namespace mongo {
namespace MONGO_MOD_PUBLIC mongo {
class BSONObjBuilder;
static const char kUpsertedFieldName[] = "upserted";
@ -91,4 +92,4 @@ private:
bool _hadError = false;
};
} // namespace mongo
} // namespace MONGO_MOD_PUBLIC mongo

View File

@ -31,12 +31,13 @@
#include "mongo/util/duration.h"
#include "mongo/util/inline_memory.h"
#include "mongo/util/modules.h"
#include <cstddef>
#include <list>
#include <memory>
namespace mongo {
namespace MONGO_MOD_PUBLIC mongo {
class OperationContext;
@ -141,4 +142,4 @@ private:
Nanoseconds _elapsedAdjustment;
};
} // namespace mongo
} // namespace MONGO_MOD_PUBLIC mongo

View File

@ -44,6 +44,7 @@
#include "mongo/util/duration.h"
#include "mongo/util/future.h"
#include "mongo/util/future_impl.h"
#include "mongo/util/modules.h"
#include "mongo/util/time_support.h"
#include <functional>
@ -68,7 +69,7 @@ namespace process_health {
*
* If an active fault state persists, FaultManager will terminate the server process.
*/
class FaultManager : protected StateMachine<HealthCheckStatus, FaultState> {
class MONGO_MOD_PUBLIC FaultManager : protected StateMachine<HealthCheckStatus, FaultState> {
FaultManager(const FaultManager&) = delete;
FaultManager& operator=(const FaultManager&) = delete;

View File

@ -36,6 +36,7 @@
#include "mongo/stdx/mutex.h"
#include "mongo/stdx/unordered_map.h"
#include "mongo/util/duration.h"
#include "mongo/util/modules.h"
#include "mongo/util/synchronized_value.h"
#include <algorithm>
@ -75,7 +76,15 @@ std::ostream& operator<<(std::ostream& os, const FaultState& state);
/**
* Types of health observers available.
*/
enum class FaultFacetType { kSystem, kMock1, kMock2, kTestObserver, kLdap, kDns, kConfigServer };
enum class MONGO_MOD_PUBLIC FaultFacetType {
kSystem,
kMock1,
kMock2,
kTestObserver,
kLdap,
kDns,
kConfigServer
};
static const StringData FaultFacetTypeStrings[] = {
"systemObserver", "mock1", "mock2", "testObserver", "LDAP", "DNS", "configServer"};
@ -97,7 +106,7 @@ inline std::ostream& operator<<(std::ostream& os, const FaultFacetType& type) {
return os;
}
class FaultManagerConfig {
class MONGO_MOD_PUBLIC FaultManagerConfig {
public:
/* Maximum possible jitter added to the time between health checks */
static auto inline constexpr kPeriodicHealthCheckMaxJitter{Milliseconds{100}};

View File

@ -40,6 +40,7 @@
#include "mongo/transport/transport_layer_manager_impl.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/concurrency/thread_pool.h"
#include "mongo/util/modules.h"
#include "mongo/util/tick_source_mock.h"
#include <memory>
@ -65,7 +66,7 @@ inline std::unique_ptr<FaultManagerConfig> getConfigWithDisabledPeriodicChecks()
* Test wrapper class for FaultManager that has access to protected methods
* for testing.
*/
class FaultManagerTestImpl : public FaultManager {
class MONGO_MOD_NEEDS_REPLACEMENT FaultManagerTestImpl : public FaultManager {
public:
FaultManagerTestImpl(ServiceContext* svcCtx,
std::shared_ptr<executor::TaskExecutor> taskExecutor,
@ -122,7 +123,7 @@ public:
/**
* Test suite for fault manager.
*/
class FaultManagerTest : service_context_test::WithSetupTransportLayer,
class MONGO_MOD_PUBLIC FaultManagerTest : service_context_test::WithSetupTransportLayer,
service_context_test::RouterRoleOverride,
public ClockSourceMockServiceContextTest {
public:

View File

@ -31,6 +31,7 @@
#include "mongo/base/string_data.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/process_health/fault_manager_config.h"
#include "mongo/util/modules.h"
#include <memory>
#include <ostream>
@ -38,7 +39,7 @@
namespace mongo {
namespace process_health {
enum class Severity { kOk, kFailure };
enum class MONGO_MOD_PUBLIC Severity { kOk, kFailure };
static const StringData SeverityStrings[] = {"kOk", "kFailure"};
inline StringBuilder& operator<<(StringBuilder& s, const Severity& sev) {
@ -51,7 +52,7 @@ inline std::ostream& operator<<(std::ostream& s, const Severity& sev) {
/**
* Immutable class representing current status of an ongoing fault tracked by facet.
*/
class HealthCheckStatus {
class MONGO_MOD_PUBLIC HealthCheckStatus {
public:
HealthCheckStatus(FaultFacetType type, Severity severity, StringData description)
: _type(type), _severity(severity), _description(description) {}

View File

@ -37,6 +37,7 @@
#include "mongo/util/cancellation.h"
#include "mongo/util/duration.h"
#include "mongo/util/future.h"
#include "mongo/util/modules.h"
#include "mongo/util/time_support.h"
#include <memory>
@ -75,7 +76,7 @@ struct HealthObserverLivenessStats {
/**
* Interface to conduct periodic health checks.
*/
class HealthObserver {
class MONGO_MOD_PUBLIC HealthObserver {
public:
virtual ~HealthObserver() = default;

View File

@ -43,6 +43,7 @@
#include "mongo/util/duration.h"
#include "mongo/util/future.h"
#include "mongo/util/hierarchical_acquisition.h"
#include "mongo/util/modules.h"
#include "mongo/util/tick_source.h"
#include "mongo/util/time_support.h"
@ -59,7 +60,7 @@ namespace process_health {
* Every instance of health observer is wired internally to update the state of the FaultManager
* when a problem is detected.
*/
class HealthObserverBase : public HealthObserver {
class MONGO_MOD_OPEN HealthObserverBase : public HealthObserver {
public:
explicit HealthObserverBase(ServiceContext* svcCtx);
~HealthObserverBase() override = default;

View File

@ -30,6 +30,7 @@
#include "mongo/db/process_health/health_observer.h"
#include "mongo/db/service_context.h"
#include "mongo/util/modules.h"
#include <functional>
#include <memory>
@ -42,7 +43,7 @@ namespace process_health {
* Registration mechanism for all health observers.
* This is static class not requiring an instance to work.
*/
class HealthObserverRegistration {
class MONGO_MOD_PUBLIC HealthObserverRegistration {
public:
/**
* Registers a factory method, which will be invoked later to instantiate the observer.

View File

@ -35,6 +35,7 @@
#include "mongo/logv2/log.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/duration.h"
#include "mongo/util/modules.h"
#include "mongo/util/timer.h"
#include <array>
@ -114,7 +115,7 @@ private:
* - nonstatic makeTimer to initialize Timer.
*/
template <typename Policy>
class SplitTimer {
class MONGO_MOD_PUBLIC SplitTimer {
private:
template <typename E>
static constexpr size_t _idx(E e) {

View File

@ -31,6 +31,7 @@
#include "mongo/base/status.h"
#include "mongo/config.h"
#include "mongo/util/modules.h"
#include <string>
@ -38,11 +39,11 @@ namespace mongo::otel::metrics {
/**
* Initializes OpenTelemetry metrics using either the HTTP or file exporter.
*/
Status initialize(const std::string& name);
MONGO_MOD_PUBLIC Status initialize(const std::string& name);
/**
* Shuts down the OpenTelemetry metric export process by setting the global MeterProvider to a
* NoopMeterProvider.
*/
void shutdown();
MONGO_MOD_PUBLIC void shutdown();
} // namespace mongo::otel::metrics

View File

@ -32,6 +32,7 @@
#include "mongo/db/client.h"
#include "mongo/db/operation_context.h"
#include "mongo/otel/telemetry_context.h"
#include "mongo/util/modules.h"
#include <memory>
@ -44,7 +45,7 @@ namespace otel {
* propagate parent / child relationships between Spans as well as hold metadata to correlate
* various telemetry data.
*/
class TelemetryContextHolder {
class MONGO_MOD_PUBLIC TelemetryContextHolder {
public:
static TelemetryContextHolder& get(OperationContext* opCtx);

View File

@ -32,14 +32,14 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/db/operation_context.h"
#include "mongo/otel/telemetry_context.h"
#include "mongo/util/modules.h"
#ifdef MONGO_CONFIG_OTEL
#include <opentelemetry/context/propagation/text_map_propagator.h>
#endif
namespace mongo {
namespace otel {
namespace MONGO_MOD_PUBLIC otel {
#ifdef MONGO_CONFIG_OTEL
@ -80,5 +80,5 @@ public:
#endif
} // namespace otel
} // namespace MONGO_MOD_PUBLIC otel
} // namespace mongo

View File

@ -31,6 +31,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/otel/traces/tracing_utils.h"
#include "mongo/util/modules.h"
#include <opentelemetry/context/propagation/text_map_propagator.h>
@ -45,7 +46,7 @@ using opentelemetry::nostd::function_ref;
* providing interoperability between BSONObj and OpenTelemetry TextMap Propagators
* (https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-propagator).
*/
class BSONTextMapCarrier : public TextMapCarrier {
class MONGO_MOD_PARENT_PRIVATE BSONTextMapCarrier : public TextMapCarrier {
public:
/**
* Default constructor with an empty initial BSONObj. Intended to be used when using a

View File

@ -32,6 +32,7 @@
#include "mongo/db/service_context_test_fixture.h"
#include "mongo/otel/traces/mock_exporter.h"
#include "mongo/otel/traces/tracer_provider_service.h"
#include "mongo/util/modules.h"
#include <opentelemetry/sdk/trace/simple_processor_factory.h>
#include <opentelemetry/sdk/trace/tracer_provider_factory.h>
@ -45,7 +46,7 @@ namespace traces {
* Test fixture for tests that require OpenTelemetry TracerProvider to be initialized.
* Sets up a TracerProvider with MockExporter so tests can create and inspect spans.
*/
class OtelTestFixture : public ServiceContextTest {
class MONGO_MOD_OPEN OtelTestFixture : public ServiceContextTest {
public:
void setUp() override {
ServiceContextTest::setUp();

View File

@ -33,12 +33,13 @@
#include "mongo/config.h"
#include "mongo/db/operation_context.h"
#include "mongo/otel/telemetry_context.h"
#include "mongo/util/modules.h"
#include <memory>
namespace mongo {
namespace otel {
namespace traces {
namespace MONGO_MOD_PUBLIC traces {
#ifdef MONGO_CONFIG_OTEL
@ -141,6 +142,6 @@ public:
#endif
} // namespace traces
} // namespace MONGO_MOD_PUBLIC traces
} // namespace otel
} // namespace mongo

View File

@ -31,6 +31,7 @@
#include "mongo/base/string_data.h"
#include "mongo/otel/telemetry_context.h"
#include "mongo/util/modules.h"
#include <opentelemetry/context/propagation/text_map_propagator.h>
#include <opentelemetry/trace/context.h>
@ -53,7 +54,7 @@ constexpr OtelStringView falseValue = "false";
* SpanTelemetryContextImpl is an implementation of TelemetryContext that wraps OpenTelemetry's
* Context to allow for propagation of span state across OpenTelemetry functionality.
*/
class SpanTelemetryContextImpl : public TelemetryContext {
class MONGO_MOD_NEEDS_REPLACEMENT SpanTelemetryContextImpl : public TelemetryContext {
public:
explicit SpanTelemetryContextImpl(OtelContext ctx);
SpanTelemetryContextImpl() : _ctx() {}

View File

@ -32,10 +32,12 @@
#include "mongo/base/status.h"
#include "mongo/config.h"
#include "mongo/db/service_context.h"
#include "mongo/util/modules.h"
#include <string>
namespace mongo::otel::traces {
namespace mongo::otel {
namespace MONGO_MOD_PUBLIC traces {
#ifdef MONGO_CONFIG_OTEL
@ -52,4 +54,5 @@ inline void shutdown(ServiceContext* serviceContext) {}
#endif
} // namespace mongo::otel::traces
} // namespace MONGO_MOD_PUBLIC traces
} // namespace mongo::otel

View File

@ -30,9 +30,11 @@
#pragma once
#include "mongo/db/operation_context.h"
#include "mongo/rpc/metadata/metadata_hook.h"
#include "mongo/util/modules.h"
namespace mongo::otel::traces {
bool isTracingEnabled(OperationContext* opCtx);
MONGO_MOD_PUBLIC bool isTracingEnabled(OperationContext* opCtx);
}

View File

@ -34,6 +34,7 @@ imports:
feature_flags:
featureFlagTracing:
mod_visibility: public
description: "Feature flag for enabling the creation of tracing spans in the server code."
cpp_varname: gFeatureFlagTracing
default: false

View File

@ -32,6 +32,7 @@
#include "mongo/platform/atomic.h"
#include "mongo/platform/compiler.h"
#include "mongo/stdx/mutex.h"
#include "mongo/util/modules.h"
#include "mongo/util/scopeguard.h"
#include <cstdint>
@ -42,7 +43,7 @@
#include <boost/optional.hpp>
namespace mongo {
namespace MONGO_MOD_PUBLIC mongo {
namespace observable_mutex_details {
template <typename MutexType>
@ -215,13 +216,13 @@ public:
_mutex.unlock_shared();
}
void setExclusiveAcquisitions_forTest(MutexAcquisitionStats stat) {
MONGO_MOD_NEEDS_REPLACEMENT void setExclusiveAcquisitions_forTest(MutexAcquisitionStats stat) {
_exclusiveAcquisitions.contentions.store(stat.contentions);
_exclusiveAcquisitions.total.store(stat.total);
_exclusiveAcquisitions.waitCycles.store(stat.waitCycles);
}
void setSharedAcquisitions_forTest(MutexAcquisitionStats stat) {
MONGO_MOD_NEEDS_REPLACEMENT void setSharedAcquisitions_forTest(MutexAcquisitionStats stat) {
_sharedAcquisitions.contentions.store(stat.contentions);
_sharedAcquisitions.total.store(stat.total);
_sharedAcquisitions.waitCycles.store(stat.waitCycles);
@ -265,4 +266,4 @@ using ObservableMutex = MutexType;
using ObservableExclusiveMutex = ObservableMutex<stdx::mutex>;
using ObservableSharedMutex = ObservableMutex<std::shared_mutex>; // NOLINT
} // namespace mongo
} // namespace MONGO_MOD_PUBLIC mongo

View File

@ -31,6 +31,7 @@
#include "mongo/base/string_data.h"
#include "mongo/bson/bsonobj.h"
#include "mongo/util/modules.h"
#include "mongo/util/observable_mutex.h"
#include "mongo/util/string_map.h"
#include "mongo/util/system_clock_source.h"
@ -42,7 +43,7 @@ namespace mongo {
* The registry keeps track of all registered instances of `ObservableMutex` and provides an
* interface to collect contention stats.
*/
class ObservableMutexRegistry {
class MONGO_MOD_PUBLIC ObservableMutexRegistry {
public:
static constexpr auto kTotalAcquisitionsFieldName = "total"_sd;
static constexpr auto kTotalContentionsFieldName = "contentions"_sd;

View File

@ -36,6 +36,7 @@
#include "mongo/stdx/mutex.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/duration.h"
#include "mongo/util/modules.h"
#include <cstdint>
#include <functional>
@ -45,7 +46,7 @@
#include <boost/filesystem/path.hpp>
namespace mongo {
namespace MONGO_MOD_PUBLIC mongo {
class OperationContext;
class ServiceContext;
@ -117,7 +118,7 @@ private:
* - sleep(period)
* - callback
*/
class WatchdogPeriodicThread {
class MONGO_MOD_OPEN WatchdogPeriodicThread {
public:
WatchdogPeriodicThread(Milliseconds period, StringData threadName);
virtual ~WatchdogPeriodicThread() = default;
@ -346,7 +347,7 @@ public:
/**
* Gets whether checks are paused or not. For testing purposes only.
*/
virtual bool getShouldRunChecks_forTest() = 0;
MONGO_MOD_PUBLIC virtual bool getShouldRunChecks_forTest() = 0;
};
@ -445,4 +446,4 @@ private:
WatchdogMonitorThread _watchdogMonitorThread;
};
} // namespace mongo
} // namespace MONGO_MOD_PUBLIC mongo

View File

@ -28,7 +28,9 @@
*/
#pragma once
#include "mongo/platform/atomic_word.h"
#include "mongo/util/modules.h"
#include "mongo/watchdog/watchdog.h"
namespace mongo {
@ -37,7 +39,7 @@ namespace mongo {
* A mock WatchdogMonitor for use in C++ unit tests.
*
*/
class WatchdogMonitorMock final : public WatchdogMonitorInterface {
class MONGO_MOD_PUBLIC WatchdogMonitorMock final : public WatchdogMonitorInterface {
public:
WatchdogMonitorMock() = default;
~WatchdogMonitorMock() override = default;

View File

@ -31,11 +31,12 @@
#include "mongo/base/status.h"
#include "mongo/db/tenant_id.h"
#include "mongo/util/modules.h"
#include <boost/optional.hpp>
#include <boost/optional/optional.hpp>
namespace mongo {
namespace MONGO_MOD_PUBLIC mongo {
class ServiceContext;
@ -50,4 +51,4 @@ void startWatchdog(ServiceContext* service);
Status validateWatchdogPeriodSeconds(const int& value, const boost::optional<TenantId>&);
Status onUpdateWatchdogPeriodSeconds(const int& value);
} // namespace mongo
} // namespace MONGO_MOD_PUBLIC mongo

View File

@ -30,11 +30,12 @@
#pragma once
#include "mongo/base/string_data.h"
#include "mongo/util/modules.h"
#include <string>
#include <vector>
namespace mongo {
namespace MONGO_MOD_PUBLIC mongo {
/**
* Allow components a way to tell the watchdog what to watch.
@ -46,4 +47,4 @@ void registerWatchdogPath(StringData path);
*/
std::vector<std::string>& getWatchdogPaths();
} // namespace mongo
} // namespace MONGO_MOD_PUBLIC mongo