seqeron 0.18.0
Loading...
Searching...
No Matches
SeqeronCounters.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <cstring>
5#include <memory>
6#include <string>
7
8#include "Aeron.h"
9
10// C++ half of org.limitless.seqeron.protocol.SeqeronCounters, and of SeqeronCounters.cs. The type ids and key
11// layout MUST match the Java class: the exporter names a counter by type id and reads memberId/clientId out of
12// the key, so a mismatch publishes a counter nothing scrapes. App counters are keyed on {memberId, clientId},
13// since a node's several replicas publish the same type id. Aeron reserves 0-999.
15
16// ── SequencerService (5000-5099) ─────────────────────────────────────────────────────────────
17inline constexpr std::int32_t SEQUENCER_TYPE_ID_MIN = 5000;
18inline constexpr std::int32_t SEQUENCER_TYPE_ID_MAX = 5099;
19
20// The last clusterSeqNo emitted on this node's queue.
21inline constexpr std::int32_t SEQUENCER_CLUSTER_SEQ_NO_TYPE_ID = 5000;
22// Count of times the queue-emit back-pressure alert threshold has fired.
23inline constexpr std::int32_t SEQUENCER_QUEUE_BACKPRESSURE_ALERTS_TYPE_ID = 5001;
24// Count of malformed ingress messages the sequencer skipped.
25inline constexpr std::int32_t SEQUENCER_REJECTED_INGRESS_COUNT_TYPE_ID = 5002;
26// Count of leadership changes this node has observed and sequenced.
27inline constexpr std::int32_t SEQUENCER_LEADERSHIP_CHANGE_COUNT_TYPE_ID = 5003;
28// memberId of the leader last recorded by this node's sequencer.
29inline constexpr std::int32_t SEQUENCER_CURRENT_LEADER_MEMBER_ID_TYPE_ID = 5004;
30// Consensus timestamp of the last 1 Hz ClusterHeartbeat emitted.
31inline constexpr std::int32_t SEQUENCER_LAST_CLUSTER_HEARTBEAT_TIMESTAMP_TYPE_ID = 5005;
32// Count of standby-promotion GatewayActive frames emitted on a gateway session close.
33inline constexpr std::int32_t SEQUENCER_GATEWAY_PROMOTION_COUNT_TYPE_ID = 5006;
34// 1 once the bootstrap GatewayActive has been emitted in this cluster's log, else 0.
35inline constexpr std::int32_t SEQUENCER_BOOTSTRAP_ACTIVATED_TYPE_ID = 5007;
36// 1 while queue back-pressure has lasted past the stall threshold with no recording progress, else 0.
37inline constexpr std::int32_t SEQUENCER_QUEUE_STALLED_TYPE_ID = 5008;
38// 5009 is retired, and never reused.
39// Count of ingress messages successfully sequenced.
40inline constexpr std::int32_t SEQUENCER_INGRESS_MESSAGES_TYPE_ID = 5010;
41// Count of gateway session closes that found no standby to promote.
42inline constexpr std::int32_t SEQUENCER_GATEWAY_PROMOTION_FAILED_COUNT_TYPE_ID = 5011;
43
44// ── ReplayerService (5100-5199) ──────────────────────────────────────────────────────────────
45inline constexpr std::int32_t REPLAYER_TYPE_ID_MIN = 5100;
46inline constexpr std::int32_t REPLAYER_TYPE_ID_MAX = 5199;
47
48// 1 once the co-located queue recording is visible and replay requests are being served, else 0.
49inline constexpr std::int32_t REPLAYER_READY_TYPE_ID = 5101;
50// Current count of in-flight replays.
51inline constexpr std::int32_t REPLAYER_ACTIVE_SLOTS_TYPE_ID = 5102;
52// Current count of replay requests waiting for a free slot.
53inline constexpr std::int32_t REPLAYER_PENDING_REQUESTS_TYPE_ID = 5103;
54// Count of replays started since this node came up.
55inline constexpr std::int32_t REPLAYER_REPLAYS_SERVED_COUNT_TYPE_ID = 5104;
56// Count of control replies dropped because an app stopped draining the control stream.
57inline constexpr std::int32_t REPLAYER_CONTROL_REPLIES_DROPPED_COUNT_TYPE_ID = 5107;
58// Count of replay requests held pending only because the queue recording trailed the queue while a replay ran.
59inline constexpr std::int32_t REPLAYER_THROTTLED_REQUESTS_COUNT_TYPE_ID = 5110;
60// Count of local-archive calls that threw; a sustained rate means the archive is not serving replays.
61inline constexpr std::int32_t REPLAYER_ARCHIVE_ERRORS_COUNT_TYPE_ID = 5111;
62
63// ── Co-located application replicas (5200-5299) ──────────────────────────────────────────────
64// Core reserves 5200 and 5297-5299; a consumer allocates its own in 5201-5296 (doc/ops.md, "Counter type ids").
65inline constexpr std::int32_t APP_TYPE_ID_MIN = 5200;
66inline constexpr std::int32_t APP_TYPE_ID_MAX = 5299;
67
68// 1 while this replica's recovery has been reported unconvergent (see ReplayerRecovery::checkRecoveryProgress), else 0.
69inline constexpr std::int32_t APP_RECOVERY_STALLED_TYPE_ID = 5200;
70
71// How far a hosted client trails its host: the host's last dispatched position less the client's applied one.
72inline constexpr std::int32_t HOSTED_LAG_TYPE_ID = 5297;
73
74// The last snapshot round a participating client confirmed (doc/snapshot.md §4), 0 for none yet.
75inline constexpr std::int32_t APP_SNAPSHOT_ROUND_TYPE_ID = 5298;
76
77// Connections a gateway instance holds open: taken and not yet closed, and 0 while it does not serve.
78inline constexpr std::int32_t GATEWAY_CONNECTIONS_TYPE_ID = 5299;
79
80// ── ClientProxy and the clients it serves (5300-5399) ────────────────────────────────────────
81inline constexpr std::int32_t PROXY_TYPE_ID_MIN = 5300;
82inline constexpr std::int32_t PROXY_TYPE_ID_MAX = 5399;
83
84// A client's monotonic clock in ms, written by the client every duty cycle; the proxy judges the client by it.
85inline constexpr std::int32_t PROXY_CLIENT_HEARTBEAT_TYPE_ID = 5300;
86// The position of the last payload a client applied, written by the client.
87inline constexpr std::int32_t PROXY_CLIENT_APPLIED_TYPE_ID = 5301;
88// A proxy's monotonic clock in ms, written by the proxy every duty cycle; the client judges the proxy by it.
89inline constexpr std::int32_t PROXY_HEARTBEAT_TYPE_ID = 5302;
90// Total encoded length of the windowed commands that have left the proxy's queue, placed or dropped.
91inline constexpr std::int32_t PROXY_RETIRED_TYPE_ID = 5303;
92
93// The type ids seqeron owns, for a typeId-range scan.
94inline constexpr std::int32_t MIN_TYPE_ID = SEQUENCER_TYPE_ID_MIN;
95inline constexpr std::int32_t MAX_TYPE_ID = PROXY_TYPE_ID_MAX;
96
97// Key layout: an operator counter's key is the memberId; an app counter's is memberId, then clientId.
98inline constexpr std::size_t KEY_MEMBER_ID_OFFSET = 0;
99inline constexpr std::size_t KEY_CLIENT_ID_OFFSET = 4;
100inline constexpr std::size_t KEY_LENGTH = 4;
101inline constexpr std::size_t APP_KEY_LENGTH = 8;
102
114inline std::int64_t addAppCounter(const std::shared_ptr<aeron::Aeron>& aeron, const std::int32_t typeId,
115 const std::string& label, const std::int32_t memberId, const std::int32_t clientId)
116{
117 std::uint8_t key[APP_KEY_LENGTH] = {};
118 std::memcpy(key + KEY_MEMBER_ID_OFFSET, &memberId, sizeof(memberId));
119 std::memcpy(key + KEY_CLIENT_ID_OFFSET, &clientId, sizeof(clientId));
120 return aeron->addCounter(typeId, key, APP_KEY_LENGTH, label);
121}
122
123} // namespace org::limitless::seqeron::protocol
Definition ProxyProtocol.hpp:8
constexpr std::int32_t PROXY_TYPE_ID_MAX
Definition SeqeronCounters.hpp:82
constexpr std::int32_t REPLAYER_THROTTLED_REQUESTS_COUNT_TYPE_ID
Definition SeqeronCounters.hpp:59
constexpr std::int32_t SEQUENCER_TYPE_ID_MIN
Definition SeqeronCounters.hpp:17
constexpr std::int32_t SEQUENCER_QUEUE_STALLED_TYPE_ID
Definition SeqeronCounters.hpp:37
constexpr std::int32_t SEQUENCER_BOOTSTRAP_ACTIVATED_TYPE_ID
Definition SeqeronCounters.hpp:35
constexpr std::int32_t SEQUENCER_INGRESS_MESSAGES_TYPE_ID
Definition SeqeronCounters.hpp:40
constexpr std::int32_t MIN_TYPE_ID
Definition SeqeronCounters.hpp:94
constexpr std::int32_t SEQUENCER_QUEUE_BACKPRESSURE_ALERTS_TYPE_ID
Definition SeqeronCounters.hpp:23
constexpr std::size_t KEY_LENGTH
Definition SeqeronCounters.hpp:100
constexpr std::size_t APP_KEY_LENGTH
Definition SeqeronCounters.hpp:101
constexpr std::int32_t APP_RECOVERY_STALLED_TYPE_ID
Definition SeqeronCounters.hpp:69
constexpr std::int32_t PROXY_CLIENT_APPLIED_TYPE_ID
Definition SeqeronCounters.hpp:87
constexpr std::int32_t SEQUENCER_REJECTED_INGRESS_COUNT_TYPE_ID
Definition SeqeronCounters.hpp:25
constexpr std::int32_t PROXY_RETIRED_TYPE_ID
Definition SeqeronCounters.hpp:91
constexpr std::int32_t PROXY_HEARTBEAT_TYPE_ID
Definition SeqeronCounters.hpp:89
constexpr std::int32_t GATEWAY_CONNECTIONS_TYPE_ID
Definition SeqeronCounters.hpp:78
constexpr std::int32_t REPLAYER_CONTROL_REPLIES_DROPPED_COUNT_TYPE_ID
Definition SeqeronCounters.hpp:57
constexpr std::int32_t REPLAYER_READY_TYPE_ID
Definition SeqeronCounters.hpp:49
constexpr std::int32_t PROXY_TYPE_ID_MIN
Definition SeqeronCounters.hpp:81
constexpr std::int32_t REPLAYER_REPLAYS_SERVED_COUNT_TYPE_ID
Definition SeqeronCounters.hpp:55
constexpr std::int32_t SEQUENCER_GATEWAY_PROMOTION_FAILED_COUNT_TYPE_ID
Definition SeqeronCounters.hpp:42
constexpr std::int32_t SEQUENCER_TYPE_ID_MAX
Definition SeqeronCounters.hpp:18
constexpr std::int32_t APP_TYPE_ID_MAX
Definition SeqeronCounters.hpp:66
constexpr std::int32_t REPLAYER_ARCHIVE_ERRORS_COUNT_TYPE_ID
Definition SeqeronCounters.hpp:61
constexpr std::size_t KEY_CLIENT_ID_OFFSET
Definition SeqeronCounters.hpp:99
constexpr std::int32_t SEQUENCER_CLUSTER_SEQ_NO_TYPE_ID
Definition SeqeronCounters.hpp:21
constexpr std::int32_t PROXY_CLIENT_HEARTBEAT_TYPE_ID
Definition SeqeronCounters.hpp:85
std::int64_t addAppCounter(const std::shared_ptr< aeron::Aeron > &aeron, const std::int32_t typeId, const std::string &label, const std::int32_t memberId, const std::int32_t clientId)
Allocates an app counter keyed on {memberId, clientId}.
Definition SeqeronCounters.hpp:114
constexpr std::int32_t APP_SNAPSHOT_ROUND_TYPE_ID
Definition SeqeronCounters.hpp:75
constexpr std::int32_t HOSTED_LAG_TYPE_ID
Definition SeqeronCounters.hpp:72
constexpr std::int32_t REPLAYER_TYPE_ID_MAX
Definition SeqeronCounters.hpp:46
constexpr std::int32_t SEQUENCER_LEADERSHIP_CHANGE_COUNT_TYPE_ID
Definition SeqeronCounters.hpp:27
constexpr std::int32_t REPLAYER_PENDING_REQUESTS_TYPE_ID
Definition SeqeronCounters.hpp:53
constexpr std::int32_t APP_TYPE_ID_MIN
Definition SeqeronCounters.hpp:65
constexpr std::int32_t SEQUENCER_LAST_CLUSTER_HEARTBEAT_TIMESTAMP_TYPE_ID
Definition SeqeronCounters.hpp:31
constexpr std::size_t KEY_MEMBER_ID_OFFSET
Definition SeqeronCounters.hpp:98
constexpr std::int32_t MAX_TYPE_ID
Definition SeqeronCounters.hpp:95
constexpr std::int32_t REPLAYER_ACTIVE_SLOTS_TYPE_ID
Definition SeqeronCounters.hpp:51
constexpr std::int32_t SEQUENCER_CURRENT_LEADER_MEMBER_ID_TYPE_ID
Definition SeqeronCounters.hpp:29
constexpr std::int32_t SEQUENCER_GATEWAY_PROMOTION_COUNT_TYPE_ID
Definition SeqeronCounters.hpp:33
constexpr std::int32_t REPLAYER_TYPE_ID_MIN
Definition SeqeronCounters.hpp:45