A Distributed Alarm Monitoring Method and System Based on Declarative Annotations and Lock-Free Window Aggregation
Patent Information
- Application Number
- CN202511994264.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-26
- Publication Date
- 2026-09-18
- Estimated Expiration
- 2045-12-26
AI Technical Summary
[0004]为了解决现有技术中存在的监控粒度粗糙、代码维护成本高以及聚合性能受限的问题,本发明提供基于声明式注解与无锁窗口聚合的分布式告警监控方法及系统
本发明实现了主动式代码级监控,将告警规则通过语言原生注解嵌入程序元素,可在运行时主动评估业务逻辑条件并访问完整执行上下文,实现细粒度业务逻辑监控而非仅局限于网络层数据;同时,通过类型层次结构实现告警规则的自动继承与选择性抑制,在3-5级类型层次结构中减少60%-70%的规则重复,使规则复用率提升60%-70%;而基于CAS操作的分布式窗口状态机,支持在消费者节点本地进行告警聚合,无需集中式协调或分布式锁,既消除了延迟隐患,也实现线性水平扩展,可支撑每日百万级告警消息的聚合;此外,通过标签提取器从运行时上下文动态派生指标维度,支持任意维度组合的细粒度分析,还能预先定义维度以避免维度爆炸问题;最后,提供完整的算法实现与架构设计具备完全的工业可复现性和确定性,不依赖操作员经验或主观判断,保障了工业级可靠性。
Smart Images

Figure CN121722642B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a distributed alarm monitoring method and system based on declarative annotations and lockless window aggregation. Background Technology
[0002] With the widespread adoption of microservice architecture and distributed computing, accurate monitoring of service runtime status has become crucial. Currently, existing monitoring technologies mainly fall into two categories: one is traditional distributed alert monitoring solutions, which typically employ a procedural coding approach, requiring developers to manually insert a large amount of monitoring logic into the business code. Secondly, there are API security detection technologies based on traffic monitoring. For example, Chinese patent application CN120880751A discloses a dynamic detection method for API security vulnerabilities based on anomaly monitoring. This patent application aims to detect API security vulnerabilities by collecting API request and response data through traffic monitoring, predicting vulnerability chains through behavioral feature extraction and context-aware analysis, and generating temporary detection rules to achieve real-time threat interception. This patent application is essentially a passive, externally observed network layer security protection technology. On the other hand, Chinese patent application CN120896737A discloses a method, system, device, and medium for detecting abnormal behavior of API interfaces through multi-feature fusion. This patent application also focuses on API anomaly detection by deploying traffic probes to collect API traffic data and combining time-series feature analysis and deep learning algorithms to fuse and analyze content features to determine API call anomalies. This patent application is still limited to the scope of network layer traffic analysis.
[0003] However, in practical applications, the aforementioned existing technologies suffer from several drawbacks. First, existing traffic monitoring technologies can only observe network-level input and output, failing to obtain the program's internal execution context, such as local variable states, detailed call stacks, and business logic branch paths. This limits the monitoring system's ability to detect errors but not pinpoint their cause, resulting in limited monitoring granularity. Second, traditional procedural alarm definitions lead to tight coupling between monitoring and business logic. In large-scale systems, similar alarm conditions need to be repeatedly implemented across multiple microservices, lacking rule inheritance and reuse mechanisms. Changes in alarm strategies require modifications to a large amount of scattered code, resulting in extremely high maintenance costs and difficulties in code coupling and maintenance. Finally, when aggregating massive amounts of alarm data, such as counting more than 10 errors within 5 minutes, existing technologies often rely on centralized analysis engines or distributed locks to ensure state consistency. Centralized engines are prone to single-point-of-failure risks, while distributed locks introduce significant network overhead and latency, typically in the 50-200ms range, limiting system throughput in high-concurrency scenarios and causing performance bottlenecks in centralized aggregation. Consequently, the accuracy, timeliness, and reliability of alarm monitoring are affected. Summary of the Invention
[0004] To address the issues of coarse monitoring granularity, high code maintenance costs, and limited aggregation performance in existing technologies, this invention provides a distributed alarm monitoring method and system based on declarative annotations and lock-free window aggregation.
[0005] Firstly, this invention provides a distributed alarm monitoring method based on declarative annotations and lock-free window aggregation, employing the following technical solution: A distributed alarm monitoring method based on declarative annotations and lock-free window aggregation includes: scanning the type hierarchy of target program elements through reflection, collecting and parsing alarm annotations and suppression annotations defined in the type hierarchy; compiling the parsed alarm annotations and suppression annotations into executable alarm predicates and suppression predicates, and storing the compilation results in a local cache; intercepting the execution process of the target program elements and obtaining the runtime execution context, which includes at least variable states, call stacks, and business logic states; filtering alarm predicates using suppression predicates based on the runtime execution context, and evaluating unsuppressed alarm predicates; generating alarm objects according to the alarm modes defined in the alarm annotations when the evaluation result of the alarm predicate is true; sending alarm objects to a message queue to trigger immediate notification when the alarm mode is immediate; extracting dimension labels of alarm objects when the alarm mode is threshold mode, performing lock-free window aggregation on alarm objects using comparison and exchange operations of distributed key-value storage, and triggering alarm notification when the aggregation result meets a preset threshold, thereby realizing distributed alarm monitoring.
[0006] This invention utilizes reflection to scan the type hierarchy and parse alarm annotations, enabling the definition of declarative monitoring logic. This decouples monitoring logic from business logic, improving code maintainability and reusability. Local caching of compilation results ensures efficient runtime execution. By intercepting the execution process and obtaining the runtime execution context, it achieves deep monitoring of the program's internal state, acquiring detailed information such as variable states, call stacks, and business logic states, thus improving monitoring granularity and fault location capabilities. By filtering alarm predicates through predicate suppression, redundant alarms are effectively reduced. The differentiated processing of immediate and threshold modes meets the alarm requirements of different scenarios. Lock-free window aggregation based on distributed key-value storage avoids single points of failure in centralized engines and the performance overhead of distributed locks, improving system throughput and alarm response timeliness in high-concurrency scenarios.
[0007] Furthermore, the step of scanning the type hierarchy of target program elements through reflection includes: starting from the runtime type of the target program element, recursively traversing the parent type until the root type; during the traversal, collecting warning annotations in order from the base type to the derived type, so that the general warning rules defined by the base type are automatically applied to the derived type; and simultaneously collecting suppression annotations, which are used to selectively disable the warning rules inherited from the base type in the derived type.
[0008] Furthermore, the parsed alarm annotations are compiled into alarm predicates, including compilation in the following priority order: in response to the alarm annotation containing an expression language string, a sub-predicate based on the expression parser is created, and runtime request and response objects are injected into the evaluation context for performing dynamic expression evaluation; in response to the alarm annotation specifying a response code or business error code, a sub-predicate based on numerical equivalence comparison is created; in response to the alarm annotation referencing a custom condition checker class, the checker class is instantiated and a sub-predicate that calls the check method is created; all sub-predicates are combined into an alarm predicate, which is configured to evaluate to true only if the evaluation results of all sub-predicates are true.
[0009] This invention achieves flexible definition of alarm conditions by constructing a combination mechanism of multiple types of sub-predicates; expression language sub-predicates support dynamic calculation, numerical comparison sub-predicates handle response code verification, and custom checker sub-predicates extend the verification logic; Logical combination ensures accurate matching of complex alarm conditions, improving the expressiveness and accuracy of alarm rules.
[0010] Furthermore, the parsed suppression annotations are compiled into suppression predicates, including: identifying suppression condition configurations in the suppression annotations; generating matching logic based on rule name string comparison in response to the suppression condition configuration being set to name matching mode; generating dynamic expression logic based on Boolean values calculated from the runtime execution context in response to the suppression condition configuration being set to conditional expression mode; and constructing a suppression predicate, which is configured to output an interception instruction to prevent subsequent processing of the alarm predicate when the evaluation result of the above matching logic or dynamic expression logic is true.
[0011] This invention enables flexible configuration of alarm suppression by constructing two suppression modes: name matching and conditional expression. The name matching mode supports static suppression based on rule names, while the conditional expression mode supports dynamic suppression based on runtime context. This effectively reduces redundant alarms and improves the accuracy and practicality of the monitoring system.
[0012] Furthermore, the filtering of alarm predicates using suppression predicates includes: checking whether there is a suppression rule applicable to the current alarm object, wherein the applicable conditions for the suppression rule include: the name of the suppression rule matches the name of the alarm rule, or the condition predicate of the suppression rule is true based on the evaluation of the runtime execution context; in response to the existence of an applicable suppression rule and the alarm type specified by the suppression rule matches the alarm type of the current alarm object, the alarm object is discarded; in response to the existence of multiple alarm rules that match simultaneously, including default alarm rules and non-default alarm rules, the non-default alarm rules are retained first, and the default alarm rules are filtered out.
[0013] This invention achieves precise matching of suppression rules by constructing a dual applicability check based on name matching and condition evaluation; alarm type matching ensures the targeted nature of suppression; and priority processing of default and non-default alarm rules avoids the generation of redundant alarms; thereby improving the accuracy of alarms and the effectiveness of the monitoring system.
[0014] Furthermore, the step of generating an alarm object based on the alarm mode defined in the alarm annotation includes: identifying the alarm mode field in the alarm annotation; in response to the alarm mode field indicating an immediate mode, routing the alarm object to the message producer, which serializes the alarm object and pushes it to the immediate message queue; in response to the alarm mode field indicating a threshold mode, routing the alarm object to the metric recorder based on the routing configuration in the alarm annotation, which writes the alarm data point to the metric system, or routing the alarm object to the message producer so that it can enter the subsequent stream pipeline and window aggregation process via the immediate message queue.
[0015] This invention achieves precise response to different alarm needs by distinguishing between immediate mode and threshold mode; immediate mode ensures rapid notification of emergency alarms, while threshold mode supports intelligent alarms based on statistical aggregation; thus avoiding the impact of massive alarm data and improving the response efficiency and accuracy of the alarm system.
[0016] Furthermore, the extraction of dimension tags from alarm objects includes: obtaining static dimension tags defined in alarm annotations; calling a predefined tag extractor interface, passing the target program element as a parameter, and dynamically extracting dynamic dimension tags in key-value pair form from the runtime execution context; and merging the static dimension tags with the dynamic dimension tags to form a complete dimension set for aggregation analysis.
[0017] Furthermore, the lock-free window aggregation of alarm objects using the comparison and exchange operation of the distributed key-value store includes: constructing a window key based on the unique identifier of the alarm object, reading the current window metadata corresponding to the window key, and obtaining the current version number; calculating the updated accumulator state and the new version number in local memory based on the alarm object; sending a comparison and exchange operation to the distributed key-value store, wherein the comparison and exchange operation updates the window metadata to a new value containing the updated accumulator state and the new version number only when the actual version number of the window key in the distributed key-value store is equal to the read current version number; and in response to the failure of the comparison and exchange operation, rereading the current window metadata and retrying the update operation until the update is successful or the window expires.
[0018] Furthermore, it also includes a window closing step: when the end of the window time is detected, an exclusive lock for the window key is attempted using a distributed lock mechanism; in response to successfully acquiring the lock, the version number of the window metadata is read and verified again to ensure data consistency; the final accumulator state is read and a threshold evaluation is performed, and then the window metadata is deleted from the distributed key-value store; the distributed lock is released, and the aggregation result is output to the notification receiver; wherein, the window metadata includes: a version number used for optimistic locking control to prevent concurrent update conflicts, a window identifier used to logically uniquely identify a specific aggregation window, an accumulator state used to store statistical values within the current time window, and an expiration time used to define the lifecycle of the window data and trigger automatic cleanup.
[0019] Secondly, this invention provides a distributed alarm monitoring system based on declarative annotations and lock-free window aggregation, employing the following technical solution: The distributed alarm monitoring system based on declarative annotations and lock-free window aggregation includes: an alarm detection engine for performing scanning, compilation, interception, and evaluation steps; an indicator logger connected to the alarm detection engine for writing alarm data points into the indicator system and performing dimension extraction steps; an event dispatcher connected to the alarm detection engine for performing routing steps; a message producer connected to the event dispatcher for performing serialization and push steps; a message consumer for receiving alarm objects in real-time mode or threshold mode; a streaming pipeline connected to the message consumer for streaming processing of alarm objects; a window function component connected to the streaming pipeline for performing lock-free window aggregation and window closing steps; a key-value store connected to the window function component for maintaining window state and supporting comparison and exchange operations; and a notification receiver connected to the window function component for receiving aggregation results and sending notifications.
[0020] This invention achieves the division of labor and collaboration among alarm detection, data routing, streaming processing, and aggregation notification by constructing a modular distributed monitoring system architecture. The alarm detection engine centrally handles annotation parsing and predicate evaluation, while the stream pipeline and window function components handle time-series aggregation, and key-value storage provides lock-free state maintenance. The architecture of this invention ensures the system's high concurrency processing capability and good scalability.
[0021] The present invention has the following technical effects: This invention achieves proactive code-level monitoring by embedding alarm rules into program elements using native language annotations. It proactively evaluates business logic conditions and accesses the complete execution context at runtime, enabling fine-grained business logic monitoring rather than being limited to network layer data. Simultaneously, it achieves automatic inheritance and selective suppression of alarm rules through a type hierarchy, reducing rule duplication by 60%-70% in a 3-5 level type hierarchy, thus increasing rule reusability by 60%-70%. Furthermore, the distributed window state machine based on CAS operations supports alarm aggregation locally on consumer nodes, eliminating the need for centralized coordination or distributed locks. This eliminates latency risks and achieves linear horizontal scalability, supporting the aggregation of millions of alarm messages daily. In addition, a tag extractor dynamically derives indicator dimensions from the runtime context, supporting fine-grained analysis of arbitrary dimension combinations and allowing for pre-defined dimensions to avoid dimensionality explosion. Finally, it provides a complete algorithm implementation and architecture design with full industrial reproducibility and determinism, independent of operator experience or subjective judgment, ensuring industrial-grade reliability. Attached Figure Description
[0022] Figure 1 This is a flowchart of the distributed alarm monitoring method based on declarative annotations and lockless window aggregation in an embodiment of the present invention.
[0023] Figure 2 This is a detailed flowchart illustrating the rule discovery and compilation process in the distributed alarm monitoring method based on declarative annotations and lockless window aggregation, as described in this embodiment of the invention.
[0024] Figure 3 This is a schematic diagram of the state machine transition of the lockless window aggregation in the distributed alarm monitoring method based on declarative annotations and lockless window aggregation in an embodiment of the present invention.
[0025] Figure 4 This is a schematic diagram of the architecture components of a distributed alarm monitoring system based on declarative annotations and lockless window aggregation, according to an embodiment of the present invention. Detailed Implementation
[0026] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0027] This invention discloses a distributed alarm monitoring method based on declarative annotations and lock-free window aggregation, referring to... Figure 1 This includes steps S01-S03: S01: Executed when the system starts up or when the target program element is loaded for the first time, completing the rule discovery and compilation phase of annotation scanning, predicate compilation, and rule caching.
[0028] When a class, method, or function in an application is annotated as a target program element for alarm monitoring, the following sub-steps are executed upon system startup or the first loading of the target program element: S11: Hierarchical reflective scanning.
[0029] The system uses reflection to scan the type hierarchy of target program elements. The scanning algorithm starts from the runtime type of the target element and recursively traverses all its parent types up to the root type. During the traversal, the system collects warning annotations and suppression annotations defined at each type level in turn according to the base class first collection strategy. The hierarchical collection mechanism enables the system to achieve automatic inheritance and selective overriding of rules, reducing the need for repeated rule definition.
[0030] Specifically, the process starts with the runtime type of the monitored element and traverses its parent types sequentially, collecting all alert annotations and suppression annotations. During the traversal, the system collects alert annotations in order from the base type to the derived type, so that the general alert rules defined in the base type are automatically applied to the derived types. At the same time, the system also collects suppression annotations, which are used to selectively disable the alert rules inherited from the base type in the derived types. This ensures that the general rules defined in the base class can be automatically inherited by the derived classes, and that the derived classes can override the base class configuration by defining new rules, thus realizing automatic rule propagation and selective suppression.
[0031] S12: Alarm predicate compilation.
[0032] The parsed alarm annotations are compiled into executable alarm predicates. The alarm annotations contain the following types of fields: condition specification fields, including expression language strings, response code matching, business error code matching, message content matching, and custom condition checker class references; alarm mode fields, including alarm type, alarm name, and alarm level; route configuration fields, including alarm key extractor, message extractor, metric system configuration, and dynamic tag extractor; and priority fields, including the default alarm identifier.
[0033] The compilation process generates three levels of subpredicates in the following priority order: Expression compilation: If the alert annotation contains an expression language string, a sub-predicate based on the expression parser is created. At runtime, this sub-predicate will receive an evaluation context injected with the request object and response object and perform dynamic Boolean value calculation. Numerical matching: If the alarm annotation specifies a response code or business error code, create a sub-predicate based on numerical equivalence comparison; Custom checks: If the alert annotation references a custom condition checker class, instantiate the class using reflection and create a sub-predicate that calls its check method; Ultimately, the system configures the above sub-predicates by logical AND combination so that the evaluation result of the alarm predicate is true only when the evaluation results of all sub-predicates are true; during the compilation process, the system will also process other configurations in the annotations, such as alarm name, severity level, alarm mode, etc.
[0034] S13: Suppress predicate compilation.
[0035] The parsed suppression annotations are compiled into suppression predicates. The suppression annotations contain the following types of fields: name matching field, used to specify the name of the alarm to be suppressed, to achieve precise suppression based on the name; condition matching field, which supports configuring conditions such as response code, business error code, message content, etc., and suppression is triggered only when these specific conditions are met; type matching field, used to specify the type of alarm to be suppressed, immediate mode or threshold mode, to ensure that the suppression rules only apply to alarms of the matching type and avoid false positives; custom checker field, which allows referencing user-implemented custom suppression condition checker classes to support complex business suppression logic.
[0036] The suppression predicate supports three suppression modes: Name matching mode: Generates logic based on rule name string comparison. When the suppression annotation specifies the alarm name to be suppressed, the system creates a predicate to check the alarm rule name. Conditional expression pattern: Generates dynamic logic that evaluates Boolean values based on runtime context. When the suppression annotation contains expression language, the system creates suppression logic based on expression evaluation. Custom Inspector Pattern: If an annotation references a custom suppression inspector class, the logic for calling the inspection methods of that class is generated. The system instantiates the custom suppression inspector through reflection and creates a predicate that calls its inspection methods. The above logic is used to determine at runtime whether to block a specific alarm. The compilation process of the suppression predicate is the same as that of the alarm predicate, but the focus is on when to suppress the alarm rather than when to trigger it.
[0037] S14: Rule caching.
[0038] The compiled predicate objects are stored in a local cache. The cache uses a two-level index structure of rule type and element type to achieve thread-safe lazy loading and eliminate runtime reflection overhead.
[0039] Specifically, the system uses a ConcurrentHashMap as the cache structure. The first-level index is the rule type, and the second-level index is the monitored element type. When the system processes an element of a certain type for the first time, it performs scanning and compilation and stores the results in the cache. Subsequent processing directly retrieves the compiled rules from the cache, ensuring that rule compilation is only performed on the first use, thus improving system performance.
[0040] S02: Executed when the business program reaches the monitored target program element, completing the runtime evaluation and routing phase of context interception, condition evaluation, and alarm routing.
[0041] When the business process reaches the monitored target program element, the following sub-steps are executed: S21: Context interception and evaluation.
[0042] Intercepting the execution process: Obtaining the runtime execution context, which includes method parameters, return values, exceptions, and variable states, such as... Figure 2 As shown, the process checks whether the rule is cached. If it is cached, it is used directly; otherwise, rule discovery and compilation are performed.
[0043] Filtering using suppression predicates: If an applicable suppression rule exists, such as when the condition is met and the alarm type matches, it is discarded directly. The system iterates through all suppression predicates to check if there is a suppression rule applicable to the current context. The conditions for the suppression rule to be applicable include: the condition predicate of the suppression rule evaluates to true, or the name of the suppression rule matches the name of the alarm rule, and the alarm type of the suppression rule matches the alarm type of the alarm rule.
[0044] Evaluation of unsuppressed alarm predicates: Inject the context into the predicate logic. If the result is true, generate an alarm object according to the annotation definition. If both the default rule and the specific rule match, the specific rule is retained first. The system applies a priority filtering mechanism. When multiple alarm rules match at the same time, if there is a non-default alarm rule, the system filters out all alarm rules marked as default and only retains the specific alarm rule.
[0045] S22: Dual-mode parallel routing.
[0046] The event dispatcher performs routing based on the pattern field in the alarm object: Instant mode: The alarm object is directly routed to the message producer, serialized and pushed to the instant message queue to achieve sub-second notification. The alarm object contains information such as alarm name, severity level and occurrence time. The message producer serializes it into JSON format and sends it to the message queue. Threshold mode: Parallel processing is performed. On the one hand, alarm objects are routed to the metric recorder, which calls the tag extractor interface to extract dynamic dimensions from the context, such as tenant ID, and merges them with static tags. The data points are then written to the metric system for long-term storage. On the other hand, alarm objects carrying dimension information are routed to the message producer, which then enters the subsequent stream pipeline for real-time aggregation via the message queue. The dual-mode routing architecture enables the system to simultaneously meet the needs of instant notification and statistical aggregation, and supports both modes through a single annotation specification.
[0047] S03: For threshold-mode alarm objects, perform streaming processing, window aggregation, and result notification streaming processing and lock-free window aggregation stages.
[0048] For threshold pattern alarm objects transmitted via message queues, perform the following sub-steps: S31: Dynamic assembly and processing of flow channels.
[0049] After receiving data, the message consumer passes it to the streaming pipeline, which is built on a hierarchical interface system. Basic Pipeline Element: Defines standard processing methods and serves as the base class for all pipeline components; Pipeline functions: support chaining downstream elements to achieve data transformation and filtering; Stateful functions: used to maintain intermediate states and support state-dependent processing logic; Keyed window functions: provide the keyBy method to support key grouping, as well as methods for processing single data entries and outputting results; The system uses a pipeline builder to dynamically assemble processing chains by adding processing functions and linking downstream elements. It processes input data in a loop, filters and transforms it, and then passes it to the aggregation module. The pipeline builder supports dynamic configuration at runtime and can flexibly assemble processing chains according to different alarm types and business needs.
[0050] S32: Window initialization and reading.
[0051] Window keys are constructed based on dynamically extracted dimensions and time windows of alarm objects, and the window metadata corresponding to the key is read from the distributed key-value store. If the window does not exist, an atomic operation (setIfAbsent / setNX) is used to attempt to create a new window. The window's metadata includes: version number, window identifier, accumulator status, start and end times, and expiration time.
[0052] S33: Lock-free comparison and swap aggregation.
[0053] Implement lock-free state updates using the characteristics of distributed key-value stores: Local calculation: The accumulator state is updated in memory based on the new alarm, such as incrementing the count by 1, and a new version number is generated. The system applies the new alarm data to the current accumulator state according to the definition of the window function. Atomic update: Sending a Compare-and-Swap (CAS) instruction, such as the Watch / Multi / Exec transaction in a distributed key-value store system. The instruction logic is that the data is updated to the new value only if the current version number of the key in the store is equal to the version number at the time of reading. Conflict retry: If CAS fails, the latest metadata is read again and the calculation is repeated until it succeeds. The system implements a retry mechanism to automatically retry when CAS conflicts occur, ensuring eventual consistency.
[0054] like Figure 3 As shown, this process describes a distributed window state machine using CAS operations. The window starts from a no-window state, creates a window through the setNX operation, and enters the active window state. In the active state, the system updates the window state through CAS operations. When the window time expires, the window closing process is triggered.
[0055] S34: Window closing and result notification.
[0056] When the window time expires, the scheduler triggers the shutdown process: Distributed Lock: Attempts to acquire an exclusive lock with a timeout setting for the window key, ensuring that a single node performs the shutdown. The system uses a distributed lock mechanism to prevent multiple consumer nodes from processing the same window simultaneously. Consistency check: After acquiring the lock, verify the version number again to ensure that the window state has not been modified by other nodes; Threshold evaluation: Read the final accumulator status; if it exceeds a preset threshold, send an aggregation alarm to the notification receiver. The system evaluates the aggregation result according to the configured threshold rules. Cleanup: Delete window metadata from storage and release the lock. The system performs a cleanup operation to release distributed storage resources. The window closing process ensures the accuracy and consistency of the aggregation results while avoiding resource leaks.
[0057] This invention also discloses a distributed alarm monitoring system based on declarative annotations and lock-free window aggregation, such as... Figure 4 As shown, the distributed alarm monitoring system includes two main parts: producer nodes and consumer nodes. The producer node contains monitored program elements, alarm detection engine, event dispatcher, message producer and indicator recorder; the consumer node contains message consumer, stream pipeline, window function, notification receiver and key-value store; the message queue and indicator system serve as middleware to connect the producer node and consumer node.
[0058] Detailed descriptions of each component of the system: Alarm Detection Engine S101: The alarm detection engine S101 is the core component of the system, responsible for rule discovery, predicate compilation, condition evaluation, and alarm object generation, such as... Figure 2 As shown, when the monitored element S100 is executed, the alarm detection engine S101 first checks whether the rule has been cached. If it has been cached, it is used directly; if it has not been cached, the rule is found from the type hierarchy, the predicate is compiled, and the result is cached.
[0059] The alarm detection engine S101 performs hierarchical reflection scanning to collect alarms and suppression annotations on the type hierarchy; compiles alarm and suppression predicates, converting declarative conditions into executable functions; implements a rule caching mechanism to eliminate the overhead of repeated compilation; intercepts execution at runtime to evaluate alarm conditions; and generates alarm objects and passes them to the event dispatcher.
[0060] Metrics recorder S102: Metrics recorder S102 is connected to alarm detection engine S101 and is responsible for recording the dimensional metrics of threshold mode alarms to external metrics system S106. Metrics recorder S102 extracts dimensional information from alarm objects, calls the tag extractor interface to obtain dynamic dimensions, merges dynamic dimensions with static dimensions, and writes the metric data to external metrics system S106.
[0061] Event Dispatcher S103: Event dispatcher S103 is connected to alarm detection engine S101 and is responsible for routing alarm objects to message queue S105 or indicator system S106 according to alarm mode. Event dispatcher S103 receives alarm objects generated by alarm detection engine S101 and determines the routing path according to the alarm mode field: for immediate mode alarms, it forwards them to message producer S104; for threshold mode alarms, it forwards them to both indicator recorder S102 and message producer S104.
[0062] Message Producer S104: Message Producer S104 connects to Event Distributor S103 and is responsible for serializing alarm objects and sending them to Message Queue S105; Message Producer S104 serializes alarm objects into a transmission format and sends them to Message Queue S105, handling message sending failures; Message Producer S104 supports multiple Message Queue S105 protocols to ensure compatibility with existing infrastructure.
[0063] Message consumer S107: Message consumer S107 receives alarm objects from message queue S105 and passes the alarm objects to stream pipeline S108; message consumer S107 adopts a batch consumption and acknowledgment mechanism to ensure that alarm data is not lost.
[0064] Streaming Pipeline S108: Streaming Pipeline S108 connects to Message Consumer S107 and is responsible for streaming processing and transformation of alarm objects. Streaming Pipeline S108 consists of a series of components that implement interfaces such as PipelineFunction, supporting dynamic assembly and chained processing. Streaming Pipeline S108 supports filtering, transformation and other operations to prepare for subsequent window aggregation.
[0065] Window function S109: The window function S109 component is connected to the flow pipeline S108 and is responsible for aggregating alarms by pressing the alarm key and time window, and using CAS operations to maintain the distributed state; the window function S109 component interacts with the distributed key-value store S111 to execute window initialization, CAS lock-free aggregation and window closing logic.
[0066] like Figure 3 As shown, window function S109 manages the window lifecycle, performs lock-free window aggregation, evaluates the aggregation result, and triggers alarm notifications. Window function S109 creates new windows through the setIfAbsent atomic operation, updates the window state through the CAS operation, and ensures that the window is closed only once through a distributed lock.
[0067] Key-value store S111: Key-value store S11 connects to window function component S109, providing distributed key-value storage services, maintaining window state and supporting atomic CAS operations; Key-value store S111 supports distributed key-value storage systems, etcd, DynamoDB and other systems, provides setIfAbsent atomic operation for window creation, provides CAS operation support for lock-free state updates, and provides TTL automatic cleanup mechanism to avoid resource leaks.
[0068] Notification Receiver S110: Notification Receiver S110 is connected to window function S109 and is responsible for transmitting notifications through the configured channel when the aggregation threshold is exceeded. Notification Receiver S110 receives the aggregation alarm results and sends alarms through the configured notification channel, supporting multiple notification methods such as email, SMS, and instant messaging.
[0069] Example 1: Immediate mode for rapid response to critical faults.
[0070] User configuration annotations: ; When the API returns a 429 status code, the system sends a notification directly through the instant channel in S22 without going through aggregation, ensuring a fast response time. This is suitable for critical faults that require immediate response, such as service rate limiting and authentication failures.
[0071] Example 2: Dual-mode configuration of fast response and noise suppression.
[0072] Configure two annotations on the same element: ; ; During runtime, when a 500 error occurs: In the immediate path, a single alarm is immediately sent to notify operations personnel of the error; in the threshold path, the event is simultaneously recorded in the metrics system and pushed to the flow pipeline for aggregation. If the number of errors exceeds 100 within one minute, the window function component will trigger an aggregated alarm indicating a surge in the error rate. This dual-mode configuration balances the awareness of the first failure and the noise reduction of large-scale failure storms, making it suitable for high-traffic services.
[0073] Example 3: Hierarchical inheritance and suppression of strategy reuse.
[0074] General rules for base class definition: ; Subclasses inherit from base class and define: ; At runtime, subclasses automatically inherit the base class rules. When a subclass returns 403, the suppression predicate takes effect and the alarm is intercepted; when it returns 500, the base class rule takes effect and the alarm is triggered. This demonstrates how to achieve strategy reuse and selective suppression through hierarchical rule combination, which is suitable for business systems with inheritance relationships.
[0075] The above are all preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Therefore, all equivalent changes made in accordance with the technical solutions, logic and principles of the present invention should be covered within the scope of protection of the present invention.
Claims
1. A distributed alarm monitoring method based on declarative annotations and lock-free window aggregation, characterized in that, include: The target program element type hierarchy is scanned by reflection mechanism, and warning and suppression annotations defined in the type hierarchy are collected and parsed. The parsed alarm annotations and suppression annotations are compiled into executable alarm predicates and suppression predicates, and the compilation results are stored in the local cache. When the target program element is running, intercept its execution process and obtain the runtime execution context, which includes at least the variable state, call stack, and business logic state. Based on the runtime execution context, the alarm predicates are filtered using suppression predicates, and the alarm predicates that are not suppressed are evaluated. When the evaluation result of the alarm predicate is true, an alarm object is generated according to the alarm mode defined in the alarm annotation; In response to an alarm being in real-time mode, the alarm object is sent to a message queue to trigger an immediate notification; In response to the alarm mode being threshold mode, the dimension labels of the alarm objects are extracted, and the comparison and exchange operation of the distributed key-value storage is used to perform lock-free window aggregation on the alarm objects. When the aggregation result meets the preset threshold, an alarm notification is triggered to achieve distributed alarm monitoring. The parsed alarm annotations are compiled into alarm predicates, including compilation in the following priority order: If the alert annotation contains an expression language string, a sub-predicate based on the expression parser is created, and runtime request and response objects are injected into the evaluation context for performing dynamic expression evaluation; if the alert annotation specifies a response code or business error code, a sub-predicate based on numerical equality comparison is created; if the alert annotation references a custom condition checker class, the checker class is instantiated and a sub-predicate that calls the check method is created. Combine all subpredicates into an alarm predicate. The alarm predicate is configured to evaluate to true only if all subpredicates evaluate to true. The parsed suppression annotations are compiled into suppression predicates, including: Identify the suppression condition configuration in suppression annotations; In response to the suppression condition being configured as name matching mode, matching logic based on rule name string comparison is generated; In response to the suppression condition being configured as a conditional expression mode, dynamic expression logic is generated based on the runtime execution context to compute Boolean values. Construct a suppression predicate, which is configured to output an interception instruction to prevent further processing of the alarm predicate when the evaluation result of the above matching logic or dynamic expression logic is true. The filtering of alarm predicates using suppression predicates includes: Check if there is a suppression rule applicable to the alarm rule corresponding to the current alarm predicate. The applicable conditions for the suppression rule include: The name of the suppression rule matches the name of the alarm rule, or the conditional predicate of the suppression rule is true based on the evaluation of the runtime execution context; If an applicable suppression rule exists and the alarm type specified by the suppression rule matches the alarm type of the current alarm rule, then the alarm rule is discarded. If multiple alarm rules match simultaneously, including both default and non-default alarm rules, the non-default alarm rules will be retained first, and the default alarm rules will be filtered out. Extract the dimension labels of the alarm objects, including: Retrieve the static dimension tags defined in the alert annotation; Call the predefined tag extractor interface, pass the target program element as a parameter, and dynamically extract dynamic dimension tags in the form of key-value pairs from the runtime execution context; Static dimension labels and dynamic dimension labels are merged to form a complete set of dimensions for aggregation analysis.
2. The distributed alarm monitoring method based on declarative annotations and lock-free window aggregation according to claim 1, characterized in that, The step of scanning the type hierarchy of target program elements via reflection includes: Starting from the runtime type of the target program element, recursively traverse the parent types until the root type; During the traversal, alert annotations are collected in order from base type to derived type, so that the general alert rules defined in the base type are automatically applied to the derived type; Simultaneously, suppressive annotations are collected, which are used to selectively disable warning rules inherited from the base type in derived types.
3. The distributed alarm monitoring method based on declarative annotations and lock-free window aggregation according to claim 1, characterized in that, The step of generating an alarm object based on the alarm pattern defined in the alarm annotation includes: Identify the alarm mode field in alarm annotations; When the alarm mode field indicates that it is in real-time mode, the alarm object is routed to the message producer, which serializes the alarm object and pushes it to the real-time message queue. When the alarm mode field indicates threshold mode, the alarm object is routed to the metric logger based on the routing configuration in the alarm annotation. The metric logger then writes the alarm data point to the metric system. Alternatively, the alarm object is routed to the message producer so that it can enter the subsequent stream pipeline and window aggregation process via the real-time message queue.
4. The distributed alarm monitoring method based on declarative annotations and lock-free window aggregation according to claim 1, characterized in that, The method of performing lock-free window aggregation of alarm objects using the comparison and swap operation of distributed key-value storage includes: A window key is constructed based on the dynamically extracted dimensions and time windows of the alarm object. The current window metadata corresponding to the window key is read to obtain the current version number. The updated accumulator state and the new version number are calculated in local memory based on the alarm object. A compare-and-swap operation is sent to the distributed key-value store. The compare-and-swap operation updates the window metadata to a new value containing the updated accumulator state and the new version number only if the actual version number of the window key in the distributed key-value store is equal to the read current version number. In response to the failure of the compare-and-swap operation, the current window metadata is reread and the update operation is retried until the update is successful or the window expires.
5. The distributed alarm monitoring method based on declarative annotations and lock-free window aggregation according to claim 4, characterized in that, It also includes the window closing steps: When the window time is detected to be over, an exclusive lock for the window key is attempted using a distributed lock mechanism. In response to successfully acquiring the lock, the version number of the window metadata is read and verified again to ensure data consistency; Read the final accumulator state and perform threshold evaluation, then delete the window metadata from the distributed key-value store; release the distributed lock and output the aggregation result to the notification receiver. The distributed lock is only used for eventual consistency control during the window closing phase and does not participate in the window aggregation process. The window metadata includes: a version number used for optimistic locking to prevent concurrent update conflicts; a window identifier used to logically and uniquely identify a specific aggregation window; an accumulator state used to store statistical values within the current time window; and an expiration time used to define the lifecycle of window data and trigger automatic cleanup.
6. A distributed alarm monitoring system based on declarative annotations and lock-free window aggregation, characterized in that, include: An alarm detection engine is used to perform the scanning, compiling, intercepting and evaluating steps as described in any one of claims 1 to 5; The indicator recorder, connected to the alarm detection engine, is used to perform the step of writing alarm data points into the indicator system as described in claim 3, and to perform the step of dimension extraction as described in claim 1; the event dispatcher, connected to the alarm detection engine, is used to perform the routing step as described in claim 3; and the message producer, connected to the event dispatcher, is used to perform the serialization and push steps as described in claim 3. A message consumer is used to receive alarm objects in instant mode or threshold mode; a streaming pipeline is connected to the message consumer for streaming processing of alarm objects; a window function component is connected to the streaming pipeline for performing the steps of lockless window aggregation and window closing as described in any one of claims 4 or 5; a key-value store is connected to the window function component for maintaining window state and supporting comparison and exchange operations; and a notification receiver is connected to the window function component for receiving aggregation results and sending notifications.
Citation Information
Patent Citations
API security vulnerability dynamic detection method based on exception monitoring
CN120880751A
Multi-feature fusion API (Application Program Interface) abnormal behavior detection method, system and equipment and medium
CN120896737A
Monitoring alarm related information generation method and device, medium and electronic equipment
CN113242148A
Service analysis method and device
CN119046100A