Service state detection method, device and equipment and readable storage medium
By combining service activity detection and response detection methods in the registry, the service status misjudgment problem caused by network instability or delay is solved, and the accuracy of service status detection is improved.
Patent Information
- Application Number
- CN202411906657.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the case of unstable network or high latency, the registry may misjudgment of service instances unhealthy and remove them from the service registry, resulting in misjudgment of service status detection.
By implementing service status detection methods in the registry, combining service activity detection and service response detection, a service list is obtained, activity status detection and response status detection are carried out, and service status is determined to avoid misjudgment caused by delay or loss of heartbeat information.
Improve the accuracy of service status detection, avoid misjudgment caused by network instability or delay, and ensure accurate monitoring of service status.
Smart Images

Figure CN119892675A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a service status detection method, device, equipment and readable storage medium. Background Art
[0002] With the development of Internet technology, microservice frameworks have gradually attracted the attention of users and enterprises. Among them, the registration center can be used to manage and monitor each service instance in the microservice architecture, and provides service discovery and failover functions. Through the registration center, microservices can perceive and call each other to achieve high availability and elastic expansion. However, if there is a health problem with the interface of the service instance, the service instance will be unavailable, resulting in the failure of calling the microservice, affecting the normal operation of the business.
[0003] In related technologies, microservice instances can indicate that they are healthy by regularly sending heartbeat information to the server. However, when the network is unstable or the latency is high, the heartbeat packet may be delayed or lost. The registration center will determine that the service instance is unhealthy and remove it from the service registry, which will lead to a misjudgment of the service status. Summary of the invention
[0004] The embodiments of the present invention provide a service status detection method, device, electronic device and readable storage medium, which can prevent the registration center from determining that the service instance is unhealthy and removing it from the service registration table when the network is unstable or the delay is high, thereby improving the accuracy of service status detection.
[0005] In order to solve the above problems, in a first aspect, an embodiment of the present invention discloses a service status detection method, which is applied to a registration center, where multiple services are registered, and includes:
[0006] Obtain a service list of a registration center; the service list includes multiple services;
[0007] At a specified detection time, performing a service activity detection on each service in the service list to obtain activity status information corresponding to each service;
[0008] Performing a service response detection on a target service to obtain response status information corresponding to the target service; the target service is one of the multiple services;
[0009] The service state of the target service is determined according to the activity state information corresponding to the target service and the response state information corresponding to the target service, where the service state includes a healthy state or an unhealthy state.
[0010] Optionally, performing service response detection on the target service to obtain response status information corresponding to the target service includes:
[0011] Obtain the number of requests for the target service within a specified detection period;
[0012] When the number of requests is abnormal and the activity status information corresponding to the target service indicates that the activity is normal, a service response detection is performed on the target service to obtain the response status information corresponding to the target service.
[0013] Optionally, performing service activity detection on each service in the service list at a specified detection time to obtain activity status information corresponding to each service includes:
[0014] For each of the services, at a specified detection time, sending detection information to the service;
[0015] receiving response information returned by the service in response to the detection information;
[0016] In a case where the response information represents a normal response, determining that the activity status information corresponding to the service is normal activity;
[0017] In the case where the response information indicates an abnormal response, a response duration of the service is obtained; and activity status information corresponding to the service is determined according to the response duration.
[0018] Optionally, the sending the detection information to the service includes one of the following methods:
[0019] Sending detection information to the service via a network request;
[0020] Send detection information to the detection port of the service.
[0021] Optionally, determining the activity status information corresponding to the service according to the response duration includes:
[0022] When the response time is less than a preset time threshold, determining that the activity status information corresponding to the service is normal activity;
[0023] When the response duration is greater than or equal to a preset duration threshold, the preset duration threshold is adjusted, and the steps of sending detection information to the service and receiving response information returned by the service in response to the detection information are re-executed to determine the activity status information corresponding to the service according to the adjusted preset duration threshold.
[0024] Optionally, determining the activity status information corresponding to the service according to the adjusted preset duration threshold includes:
[0025] When the adjusted preset duration threshold is greater than or equal to the maximum duration, if the acquired response duration is greater than or equal to the adjusted preset duration threshold, it is determined that the activity state information corresponding to the service is abnormal activity.
[0026] Optionally, performing service response detection on the target service to obtain response status information corresponding to the target service includes:
[0027] Sending a data request to the target service; and receiving an execution result returned by the target service in response to the data request;
[0028] When the execution result satisfies the preset result, the response status information corresponding to the target service is normal response;
[0029] When the execution result does not meet the preset result, the response status information corresponding to the target service is a response exception.
[0030] Optionally, the activity status information includes normal activity and abnormal activity, and the response status information includes normal response and abnormal response; and determining the service status of the target service according to the activity status information corresponding to the target service and the response status information corresponding to the target service includes:
[0031] When the activity status information indicates that the activity is normal and the response status information indicates that the response is normal, determining that the service status of the target service is a healthy status;
[0032] When the activity status information is the activity exception, or the response status information is the response exception, it is determined that the service status of the target service is an unhealthy state.
[0033] In a second aspect, an embodiment of the present invention provides a service status detection device, the device comprising:
[0034] An acquisition module is used to acquire a service list of a registration center; the service list includes multiple services;
[0035] A first detection module, configured to perform service activity detection on each service in the service list at a specified detection time to obtain activity status information corresponding to each service;
[0036] A first detection module is used to perform service response detection on a target service to obtain response status information corresponding to the target service; the target service is one of the multiple services;
[0037] The determination module is used to determine the service state of the target service according to the activity state information corresponding to the target service and the response state information corresponding to the target service, wherein the service state includes a healthy state or an unhealthy state.
[0038] Optionally, the second detection module includes:
[0039] The acquisition submodule is used to obtain the number of requests for the target service within a specified detection period;
[0040] The detection submodule is used to perform service response detection on the target service to obtain response status information corresponding to the target service when the number of requests is abnormal and the activity status information corresponding to the target service indicates that the activity is normal.
[0041] Optionally, the first detection module includes:
[0042] A first sending submodule is used to send detection information to each service at a specified detection time;
[0043] A receiving submodule, used to receive response information returned by the service in response to the detection information;
[0044] A first determination submodule is used to determine that the activity status information corresponding to the service is normal activity when the response information indicates a normal response;
[0045] The second determination submodule is used to obtain the response time of the service when the response information indicates an abnormal response; and determine the activity state information corresponding to the service according to the response time.
[0046] Optionally, the sending submodule is used to send the detection information to the service through a network request;
[0047] Send detection information to the detection port of the service.
[0048] Optionally, the second determination submodule is used to determine that the activity status information corresponding to the service is normal activity when the response duration is less than a preset duration threshold;
[0049] When the response duration is greater than or equal to the preset duration threshold, the preset duration threshold is adjusted, and the steps of sending detection information to the service and receiving response information returned by the service in response to the detection information are re-executed to determine the activity status information corresponding to the service based on the adjusted preset duration threshold.
[0050] Optionally, the second determination submodule is used to determine that the activity status information corresponding to the service is abnormal activity if the acquired response duration is greater than or equal to the adjusted preset duration threshold when the adjusted preset duration threshold is greater than or equal to the maximum duration.
[0051] Optionally, the second detection module includes:
[0052] A second sending submodule is used to send a data request to the target service; and receive an execution result returned by the target service in response to the data request;
[0053] The third determining submodule is used to determine that the response status information corresponding to the target service is a normal response when the execution result meets the preset result;
[0054] The fourth determining submodule is used to determine that, when the execution result does not meet the preset result, the response status information corresponding to the target service is a response exception.
[0055] Optionally, the activity status information includes normal activity and abnormal activity, and the response status information includes normal response and abnormal response; the determination module includes:
[0056] The fifth determining submodule is used to determine that the service state of the target service is a healthy state when the activity state information indicates that the activity is normal and the response state information indicates that the response is normal;
[0057] The sixth determining submodule is used to determine that the service state of the target service is an unhealthy state when the activity state information indicates that the activity is abnormal or the response state information indicates that the response is abnormal.
[0058] An embodiment of the present invention further discloses an electronic device, which includes a processor, a memory, and a computer program stored in the memory and executable on the processor; when the processor executes the program, the aforementioned method is implemented.
[0059] The embodiment of the present invention further discloses a readable storage medium. When instructions in the readable storage medium are executed by a processor of an electronic device, the electronic device can execute the aforementioned method.
[0060] The embodiments of the present invention include the following advantages:
[0061] The service status detection method provided by the embodiment of the present invention obtains the service list of the registration center; the service list includes multiple services; at a specified detection time, a service activity detection is performed on each service on the service list to obtain the activity status information corresponding to each service; a service response detection is performed on the target service to obtain the response status information corresponding to the target service; the target service is one of the multiple services; according to the activity status information corresponding to the target service and the response status information corresponding to the target service, the service status of the target service is determined, and the service status includes a healthy state or an unhealthy state. In this way, the service activity detection and the service response detection can be combined to not only check whether the service is running, but also whether the service can correctly respond to the request, which can avoid the situation where the service status is misjudged due to the misleading heartbeat information, and can improve the accuracy of service status detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 is a flow chart of a service status detection method provided in an embodiment of the present application;
[0063] Figure 2 is a flow chart of another service status detection method provided by an embodiment of the present invention;
[0064] Figure 3 is a block diagram of a service status detection device provided in an embodiment of the present application;
[0065] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0066] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0067] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0068] Before introducing the service status detection method, device, electronic device and readable storage medium provided by the present disclosure, the application scenarios involved in each embodiment of the present disclosure are first introduced. The present disclosure can be applied to the scenario of service status detection, and the service status detection method provided by the embodiment of the present disclosure can be applied to the registration center. Among them, the registration center is a key component in the microservice architecture, which can be in the form of a software service or a software component, and can be run on a server (which can be a physical server or a virtual server), and realizes functions such as service registration and discovery through specific software programs. For example, in a cloud computing environment, the registration center can be deployed on a cloud server to provide services as an application.
[0069] With the development of Internet technology, microservice frameworks have gradually attracted the attention of users and enterprises. Among them, the registration center can be used to manage and monitor each service instance in the microservice architecture, and provides service discovery and failover functions. Through the registration center, microservices can perceive and call each other to achieve high availability and elastic expansion. However, if there is a health problem with the interface of the service instance, the service instance will be unavailable, resulting in the failure of calling the microservice, affecting the normal operation of the business.
[0070] In related technologies, microservice instances can indicate that they are healthy by regularly sending heartbeat information to the server. However, when the network is unstable or the latency is high, the heartbeat packet may be delayed or lost. The registration center will determine that the service instance is unhealthy and remove it from the service registry, which will lead to a misjudgment of the service status.
[0071] In order to solve the above problems, the present disclosure provides a service status detection method, device, electronic device and readable storage medium, which can be combined with service activity detection and service response detection, not only to check whether the service is running, but also to detect whether the service can correctly respond to requests, and can avoid the misjudgment of service status due to misleading heartbeat information, thereby improving the accuracy of service status detection.
[0072] Method Embodiment
[0073] The following is a detailed description of the service status detection method provided in the embodiment of the present application through specific embodiments and their application scenarios in conjunction with the accompanying drawings.
[0074] Figure 1 is a flow chart of a service status detection method provided in an embodiment of the present application, such as Figure 1 As shown, the method is applied to a registration center, in which multiple services are registered.
[0075] The method may include the following steps.
[0076] In step S101, a service list of a registration center is obtained.
[0077] The service list includes multiple services. The registration center can be a distributed open source distributed application coordination service, or a software that provides consistency services for distributed applications. The functions it provides may include: configuration maintenance, domain name services, distributed synchronization, group services and other services.
[0078] The service list can be a list maintained by the registry, which records the relevant information of all microservices registered in the registry. This information includes but is not limited to the service name, the network address of the service instance (such as IP address and port number), the service version number, the health status of the service, and other custom metadata. It is the core data structure used by the registry to manage and provide service discovery functions.
[0079] In this step, you can obtain the service list of the registry center in the following ways:
[0080] Method 1: Obtain through the API (Application Programming Interface) interface provided by the registration center.
[0081] For example, the registry usually provides a set of API interfaces for querying the service list and other operations. These interfaces are generally RESTful (Representational State Transfer) interfaces based on the HTTP (HyperText Transfer Protocol) protocol, and the service list data is obtained by sending HTTP requests, such as GET (get) requests, to a specific endpoint.
[0082] Specifically, taking the Eureka (an open source tool for service registration and discovery) registration center as an example, Eureka includes a detection endpoint. The microservice can use the tool to send a GET request to the address: http: / / <eureka-server-address> / endpoint. After receiving the request, the Eureka server returns a data containing all service information, which may include service name, instance information (such as address, port number, health status, etc.).
[0083] Method 2: Use the registration center client library to obtain it.
[0084] For example, the registry usually includes a corresponding client library that encapsulates the underlying logic of interacting with the registry. Developers can introduce these client libraries into the microservice code and then obtain the service list by calling the methods provided in the library.
[0085] Method 3: Obtain based on message notification mechanism.
[0086] For example, when the service list changes, the registration center can send a notification message to the client that has subscribed to the message. After receiving the notification, the client can update its locally cached service list according to the message content. However, in this way, the service list is not obtained directly, but it is notified in time when the service list is updated, so as to further obtain the service list.
[0087] In step S102, at a specified detection time, a service activity detection is performed on each service in the service list to obtain activity status information corresponding to each service.
[0088] The designated detection time may be a pre-set specific detection time (e.g., a time corresponding to every fixed few minutes), so that a service activity detection operation can be uniformly performed on each service in the service list at the designated detection time to ensure the regularity of the detection and timely discover changes in the service activity status. It should be noted that the interval between two adjacent designated detection times can be set according to the normal response time of the service.
[0089] In this step, at the specified detection time, detection information can be sent to each service on the service list, and when response information returned by the service in response to the detection information is received, the response time of each service can be obtained, and the activity status information corresponding to each service can be determined based on the numerical relationship between the response time and the preset response time threshold.
[0090] Specifically, when it is determined that the response time is greater than or equal to the preset response time threshold, the activity status information corresponding to the service can be determined as abnormal activity; and when the response time is less than the preset response time threshold, the activity status information corresponding to the service can be determined as normal activity.
[0091] Among them, the preset response time threshold can be consistent with the interval time between two adjacent designated detection times. That is to say, before the next designated detection time is detected, if the response information returned by the service in response to the detection information has not been received, it can be determined that the activity status information corresponding to the service is abnormal activity; and before the next designated detection time is detected, if the response information returned by the service in response to the detection information has been received, it can be determined that the activity status information corresponding to the service is normal activity.
[0092] In some embodiments, for each service, at a specified detection time, detection information can be sent to the service, and response information returned by the service in response to the detection information can be received; then, when the response information represents a normal response, the activity status information corresponding to the service is determined to be normal activity; and when the response information represents an abnormal response, the response duration of the service is obtained; and the activity status information corresponding to the service is determined based on the response duration.
[0093] Optionally, after sending the detection information to the service, after receiving the detection information, the service will process it according to its own internal logic, and then return corresponding response information to the detection end.
[0094] For example, when the service receives a GET request from the registration center, if the service is currently in normal operation and its business logic processing is normal, it will return response information in a predefined format.
[0095] For example, for an HTTP request, the service may return an HTTP response message with a status code of 200, and the response message may carry brief data about the service's own operating status, such as "{"status":"OK","message":"The inventory service is running normally, the database connection is stable, and the current inventory data can be queried normally"}". This indicates that the service can respond to external requests normally, the internal components work well together, and there are no failures that affect the service.
[0096] And when the received response information is characterized as a normal response, it can be determined that the activity status information corresponding to the service is active and normal.
[0097] Among them, the normal response can be determined at multiple levels:
[0098] Method 1: From the network protocol level.
[0099] If the status code returned in the HTTP protocol is 200, which indicates success, or other status codes that conform to normal request processing, it indicates a normal response.
[0100] Method 2: From the response content level.
[0101] If the returned content is in the correct format and meets expectations, the internal operation of the described service is also good, and there are no problems such as key component failure, resource exhaustion, etc. that may affect the service's ability to provide services externally.
[0102] If the descriptions at the above levels are met, it can be determined that the service is currently in a normal active state, which means that the service can normally receive external requests, process them according to its designed functions and business logic, provide corresponding services to the outside world, and is a trustworthy part of the system that can normally participate in business process interactions. For example, in a microservice architecture, if other services need to call the inventory microservice to obtain product inventory information, they can safely initiate a call request when they see that its active state is normal, ensuring the smooth progress of the entire e-commerce business process.
[0103] In this way, through the complete process of sending detection information, receiving response information and judging the normal activity status based on normal responses, the activity of the service can be effectively monitored, problems in the service operation process can be discovered in time, and the stable and reliable operation of the entire microservice architecture can be ensured.
[0104] Optionally, for each service in the service list, corresponding detection information may be sent to it from a detection end, and the detection end may be a registration center or a dedicated monitoring module.
[0105] Among them, the detection information is used for health inquiries, the purpose of which is to trigger the service to respond to the health inquiry, so that whether the service can respond normally to external requests can be determined based on whether a response is made or whether a response is made within a preset time period.
[0106] In a possible implementation, the detection information may be sent to the service via a network request.
[0107] For example, the registration center may first construct a request pointing to a specific network address of the service, wherein the specific network address is usually an interface address of the service exposed to the outside and used for status detection and other related purposes, and then may send a request pointing to the specific network address to the service as detection information.
[0108] For example, when the HTTP protocol is used, for a microservice that provides user information query, the interface address of the service for health check can be: "http: / / <service IP address>:<port number> / health". In this case, the registration center or the detection end corresponding to the registration center can send an HTTP GET request to the interface address of the service for health check. After the service receives the request, it can return corresponding response information in response to the HTTP GET request, for example, return a status code 200 and data content containing a description of the basic status of the current operation of the service, etc., to indicate whether its own status is normal.
[0109] In this way, due to the wide application of network protocols such as HTTP, most microservices support providing services or accepting detection through HTTP interfaces, which is more versatile. It is easier to customize request parameters, header information, etc. using network protocols. Targeted settings can be made according to the characteristics of different services and detection requirements, which is more flexible.
[0110] In another possible implementation, the detection information may be sent to a detection port of the service.
[0111] For example, the service itself has a reserved detection port, such as the health interface, which is used to receive detection information sent from the outside. This detection port is different from the port used by the service to provide normal business functions to the outside world. It is a port set up for operation and maintenance, monitoring and other related operations. The detection end will send corresponding data to this port as detection information in a specific protocol format.
[0112] For example, a microservice based on a custom protocol can open a detection port such as the health interface at startup, and stipulate that the detection information format sent to this port is a simple text command format, such as sending a preset command string to the port. When the server determines that the received command is a preset command string, it can return simple response information such as "OK" or "ERROR" through this port to indicate the status of the service.
[0113] In this way, reserving ports for the detection function can make the detection process relatively independent and clear, and will not interfere with the traffic of the normal business request port. It is easy to accurately obtain the service's own response to the detection information, which helps to more accurately judge the service's operating status and ensure the stability and reliability of the service.
[0114] When the received service response information is characterized as an abnormal response, it is not accurate to directly determine the active status of the service based on this result alone. Considering that the occurrence of abnormal responses includes many reasons, such as it may be just a short-term network fluctuation that causes a small problem in data transmission, the core operation function of the service itself may not be substantially affected; it may also be that there is indeed a fault inside the service, resulting in an abnormal response. Obtaining the response time of the service can provide key clues for further accurate judgment of the active status of the service.
[0115] Therefore, in some embodiments, when the response information represents an abnormal response, the response time of the service can be obtained; and the activity status information corresponding to the service can be determined according to the response time.
[0116] Optionally, determining the activity status information corresponding to the service according to the response duration may be achieved by the following steps:
[0117] Step S1: When the response duration is less than a preset duration threshold, determine that the activity status information corresponding to the service is normal.
[0118] Among them, the preset time threshold is a pre-set time standard, which can be used to measure whether the timeliness of the service response is within a reasonable range.
[0119] In this step, when the service returns an abnormal response, but its response time is less than the preset time threshold, it can be explained that although the response result is abnormal, the response speed of the service processing request meets the user's needs. Therefore, the abnormal response result may be caused by temporary, non-critical factors, such as momentary network jitter, occasional small errors in data transmission, etc., while the core operating mechanism of the service itself and the basic ability to respond to the outside world have not been substantially damaged.
[0120] For example, the preset time threshold can be set to 5 seconds. After sending detection information to a microservice, although the received response information shows that there are abnormal situations in which some data formats are not accurate (but it is not a serious problem that the service cannot process the request at all), the response time is only 3 seconds after measurement. In this case, the activity status information corresponding to the service can be considered to be normal. The service as a whole still has the ability to respond normally to the outside world, but this time the response has a small flaw in the content presentation. It can continue to be monitored regularly in the future, and there is no need to take large-scale troubleshooting or repair measures for the time being.
[0121] The above approach can demonstrate a certain degree of fault tolerance and adaptability to the actual complex network environment and service operation status. In the microservice architecture, the network environment is dynamically changing, and it is common to occasionally have some small fluctuations that do not seriously affect the service function. Through such relatively loose judgment conditions (based on the comparison of response time and threshold), it can reduce the frequent misjudgment of service failures due to such small problems, which helps to maintain the stability of the judgment of the operation status of the entire system and avoid unnecessary increase in operation and maintenance costs due to overreaction.
[0122] Step S2: When the response duration is greater than or equal to the preset duration threshold, adjust the preset duration threshold, and re-execute the steps of sending detection information to the service and receiving response information returned by the service in response to the detection information, so as to determine the activity status information corresponding to the service according to the adjusted preset duration threshold.
[0123] In this step, when the response time of the service is greater than or equal to the preset time threshold, it may be that the currently set threshold is not applicable to the current actual complex operation scenario. For example, the network has periodic congestion, the service is in a temporary high-load operation stage, etc., resulting in the response time exceeding the originally expected range. However, the service itself may not have completely lost its activity, but it just needs more time to process the request and return the result.
[0124] Therefore, the preset time threshold needs to be adjusted to give the service more "buffer space" and reconsider its responsiveness under different conditions to more accurately determine whether it really has substantial problems that affect activity.
[0125] After adjusting the preset time threshold, it is necessary to re-execute the steps of sending detection information to the service and receiving response information returned by the service in response to the detection information.
[0126] For example, the preset duration threshold is originally set to 8 seconds, and the response time of the service in a certain test reaches 10 seconds, which is greater than the threshold. Therefore, the preset duration threshold is adjusted to 12 seconds, and then the test information is sent to the service again. If the response time of the service becomes 11 seconds, which is less than the adjusted threshold, then the activity status information corresponding to the service can be re-determined as normal activity.
[0127] Optionally, the preset duration threshold can be adjusted repeatedly, and after each adjustment of the preset duration threshold, the steps of sending detection information to the service and receiving response information returned by the service in response to the detection information are re-executed until the adjusted preset duration threshold is greater than or equal to the maximum duration.
[0128] In a possible implementation, when the adjusted preset duration threshold is greater than or equal to the maximum duration, if the acquired response duration is still greater than or equal to the adjusted preset duration threshold, it is determined that the activity status information corresponding to the service is abnormal activity.
[0129] By adopting the above technical solution, through the process of dynamically adjusting the threshold and repeating the detection, it is possible to more flexibly and meticulously deal with abnormal response time of services in different operating scenarios, improve the accuracy of judging the activity status of services, and ensure that services with real potential fault hazards can be accurately discovered in the microservice architecture, while reducing misjudgments caused by external environmental factors.
[0130] In step S103, a service response detection is performed on the target service to obtain response status information corresponding to the target service.
[0131] The target service is one of the multiple services.
[0132] During the operation of the microservice architecture, considering that the number of requests received by the service is usually maintained in a relatively stable range and shows a certain regularity, if the number of requests increases or decreases significantly year-on-year and exceeds the preset threshold, this indicates that the service may have some potential problems or changes in the external environment have affected its normal operation. Although the service is displayed as normal through the conventional health interface detection at this time, the health interface often simply checks whether the service is alive and whether it can respond to basic conditions, and cannot fully reflect the service's processing capabilities when facing actual business requests. Therefore, further measures need to be taken to accurately determine whether the service is in a good operating state, that is, to continuously initiate real data requests to the service through the registration center and detect the success rate of its service response.
[0133] For example, in an e-commerce system, under normal circumstances, the product display microservice will receive about 1,000 requests per hour. The health interface detection of the product display microservice indicates that the activity is normal. However, if in a specific period (such as a certain hour), it is suddenly monitored that the number of requests it receives has increased by 80% year-on-year (reaching 1,800 times), or decreased by 60% year-on-year (down to 400 times), and exceeds the set threshold (assuming the threshold is a year-on-year change of 50%), then it means that the product display microservice may have other problems, and further measures need to be taken to accurately determine whether the service is in a good operating state.
[0134] In some embodiments, the number of requests for the target service within a specified detection period can be obtained; when the number of requests is abnormal and the activity status information corresponding to the target service indicates that the activity is normal, a service response detection is performed on the target service to obtain the response status information corresponding to the target service.
[0135] Optionally, a data request can be sent to the target service; and an execution result returned by the target service in response to the data request can be received; when the execution result meets the preset result, the response status information corresponding to the target service is a normal response; when the execution result does not meet the preset result, the response status information corresponding to the target service is an abnormal response.
[0136] In step S104, the service state of the target service is determined according to the activity state information corresponding to the target service and the response state information corresponding to the target service.
[0137] The activity status information includes normal activity and abnormal activity, the response status information includes normal response and abnormal response, and the service status includes a healthy state or an unhealthy state.
[0138] In this step, when the activity status information is that the activity is normal and the response status information is that the response is normal, the service status of the target service is determined to be a healthy state; and when the activity status information is that the activity is abnormal, or the response status information is that the response is abnormal, the service status of the target service is determined to be an unhealthy state.
[0139] The service status detection method provided by the embodiment of the present invention obtains the service list of the registration center; the service list includes multiple services; at the specified detection time, each service on the service list is subjected to service activity detection to obtain the activity status information corresponding to each service; the target service is subjected to service response detection to obtain the response status information corresponding to the target service; the target service is one of the multiple services; according to the activity status information corresponding to the target service and the response status information corresponding to the target service, the service status of the target service is determined, and the service status includes a healthy state or an unhealthy state. In this way, the service activity detection and the service response detection can be combined to not only check whether the service is running, but also whether the service can correctly respond to the request, which can avoid the situation where the service status is misjudged due to the misleading heartbeat information, and can improve the accuracy of service status detection.
[0140] Figure 2 is a flow chart of another service status detection method provided in an embodiment of the present application. Figure 2 As shown, the method is applied to a registration center, in which multiple services are registered.
[0141] The method may include the following steps.
[0142] In step S201, a service list of a registration center is obtained.
[0143] The service list includes multiple services.
[0144] In step S202, for each service, detection information is sent to the service at a specified detection time.
[0145] In step S203, response information returned by the service in response to the detection information is received.
[0146] If the response information indicates a normal response, execute steps S204, S207-S213;
[0147] If the response information indicates an abnormal response, execute steps S205 and S206;
[0148] In step S204, it is determined that the activity status information corresponding to the service is normal.
[0149] In step S205, the response time of the service is obtained.
[0150] If the response time is less than the preset time threshold, execute steps S204, S207-S213;
[0151] If the response duration is greater than or equal to the preset duration threshold, executing step S206;
[0152] In step S206, the preset duration threshold is adjusted, and steps S202-S205 are re-executed until the adjusted preset duration threshold is greater than or equal to the maximum duration.
[0153] If the response duration obtained again is greater than or equal to the maximum duration, execute step S214;
[0154] In step S214, it is determined that the activity status information corresponding to the service is abnormal activity.
[0155] In step S207, the number of requests for the target service within a specified detection period is obtained.
[0156] In step S208, a data request is sent to the target service.
[0157] In step S209, the execution result returned by the target service in response to the data request is received.
[0158] If the execution result meets the preset result, execute step S210;
[0159] If the execution result does not meet the preset result, execute step S211;
[0160] In step S210, the response status information corresponding to the target service is normal response.
[0161] In step S211, the response status information corresponding to the target service is response exception.
[0162] In step S212, when the activity status information indicates that the activity is normal and the response status information indicates that the response is normal, it is determined that the service status of the target service is a healthy status.
[0163] In step S213, when the activity status information is the activity exception, or the response status information is the response exception, it is determined that the service status of the target service is an unhealthy state.
[0164] The above technical solution is adopted, by obtaining the service list of the registration center; the service list includes multiple services; at the specified detection time, each service on the service list is subjected to service activity detection to obtain the activity status information corresponding to each service; the target service is subjected to service response detection to obtain the response status information corresponding to the target service; the target service is one of the multiple services; according to the activity status information corresponding to the target service and the response status information corresponding to the target service, the service status of the target service is determined, and the service status includes a healthy state or an unhealthy state. In this way, the service activity detection and the service response detection can be combined to not only check whether the service is running, but also whether the service can correctly respond to the request, which can avoid the misjudgment of the service status due to the misleading heartbeat information, and can improve the accuracy of service status detection.
[0165] Device Embodiment
[0166] Figure 3 is a block diagram of a service status detection device provided in an embodiment of the present application, such as Figure 3 As shown, the device 300 may include:
[0167] The acquisition module 301 is used to acquire a service list of the registration center; the service list includes multiple services;
[0168] A first detection module 302 is used to perform service activity detection on each service in the service list at a specified detection time to obtain activity status information corresponding to each service;
[0169] The second detection module 303 is used to perform service response detection on the target service to obtain response status information corresponding to the target service; the target service is one of the multiple services;
[0170] The determination module 304 is used to determine the service state of the target service according to the activity state information corresponding to the target service and the response state information corresponding to the target service, where the service state includes a healthy state or an unhealthy state.
[0171] Optionally, the second detection module includes:
[0172] The acquisition submodule is used to obtain the number of requests for the target service within a specified detection period;
[0173] The detection submodule is used to perform service response detection on the target service to obtain response status information corresponding to the target service when the number of requests is abnormal and the activity status information corresponding to the target service indicates that the activity is normal.
[0174] Optionally, the first detection module includes:
[0175] A first sending submodule is used to send detection information to each service at a specified detection time;
[0176] A receiving submodule, used to receive response information returned by the service in response to the detection information;
[0177] A first determination submodule is used to determine that the activity status information corresponding to the service is normal activity when the response information indicates a normal response;
[0178] The second determination submodule is used to obtain the response time of the service when the response information indicates an abnormal response; and determine the activity state information corresponding to the service according to the response time.
[0179] Optionally, the sending submodule is used to send the detection information to the service through a network request;
[0180] Send detection information to the detection port of the service.
[0181] Optionally, the second determination submodule is used to determine that the activity status information corresponding to the service is normal activity when the response duration is less than a preset duration threshold;
[0182] When the response duration is greater than or equal to the preset duration threshold, the preset duration threshold is adjusted, and the steps of sending detection information to the service and receiving response information returned by the service in response to the detection information are re-executed to determine the activity status information corresponding to the service based on the adjusted preset duration threshold.
[0183] Optionally, the second determination submodule is used to determine that the activity status information corresponding to the service is abnormal activity if the acquired response duration is greater than or equal to the adjusted preset duration threshold when the adjusted preset duration threshold is greater than or equal to the maximum duration.
[0184] Optionally, the second detection module includes:
[0185] A second sending submodule is used to send a data request to the target service; and receive an execution result returned by the target service in response to the data request;
[0186] The third determining submodule is used to determine that the response status information corresponding to the target service is a normal response when the execution result meets the preset result;
[0187] The fourth determining submodule is used to determine that, when the execution result does not meet the preset result, the response status information corresponding to the target service is a response exception.
[0188] Optionally, the activity status information includes normal activity and abnormal activity, and the response status information includes normal response and abnormal response; the determination module includes:
[0189] The fifth determining submodule is used to determine that the service state of the target service is a healthy state when the activity state information indicates that the activity is normal and the response state information indicates that the response is normal;
[0190] The sixth determining submodule is used to determine that the service state of the target service is an unhealthy state when the activity state information indicates that the activity is abnormal or the response state information indicates that the response is abnormal.
[0191] In summary, an embodiment of the present invention provides a service status detection device, which is used to obtain a service list from a registration center; the service list includes multiple services; at a specified detection time, perform service activity detection on each service on the service list to obtain activity status information corresponding to each service; perform service response detection on a target service to obtain response status information corresponding to the target service; the target service is one of the multiple services; according to the activity status information corresponding to the target service and the response status information corresponding to the target service, determine the service status of the target service, and the service status includes a healthy state or an unhealthy state. In this way, the service activity detection and service response detection can be combined to not only check whether the service is running, but also whether the service can correctly respond to requests, which can avoid the misjudgment of the service status due to the misleading heartbeat information, and can improve the accuracy of service status detection.
[0192] The service status detection device in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a GPU BOX, a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0193] The service status detection device provided in the embodiment of the present application can achieve Figure 1 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0194] Optional, such as Figure 4 As shown, an embodiment of the present application also provides an electronic device, including a processor and a memory, wherein the memory stores a program or instruction that can be executed on the processor, and when the program or instruction is executed by the processor, the various steps of the above-mentioned service status detection method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0195] In an embodiment of the present application, the memory may be used to store software programs and various data. The memory may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory may include a volatile memory or a non-volatile memory, or the memory may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory in the embodiments of the present application includes but is not limited to these and any other suitable types of memory.
[0196] The processor may include one or more processing units; optionally, the processor integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to the operating system, user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor.
[0197] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned service status detection method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0198] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0199] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned service status detection method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0200] It should be noted that, in this article, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved. For example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0201] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0202] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A service status detection method, characterized in that: The method is applied to a registration center, in which a plurality of services are registered, and the method comprises: Obtain a service list of a registration center; the service list includes multiple services; At a specified detection time, performing a service activity detection on each service in the service list to obtain activity status information corresponding to each service; Performing a service response detection on a target service to obtain response status information corresponding to the target service; the target service is one of the multiple services; The service state of the target service is determined according to the activity state information corresponding to the target service and the response state information corresponding to the target service, where the service state includes a healthy state or an unhealthy state.
2. The method according to claim 1, characterized in that: The performing service response detection on the target service to obtain response status information corresponding to the target service includes: Obtain the number of requests for the target service within a specified detection period; When the number of requests is abnormal and the activity status information corresponding to the target service indicates that the activity is normal, a service response detection is performed on the target service to obtain the response status information corresponding to the target service.
3. The method according to claim 1, characterized in that: The performing service activity detection on each service in the service list at the designated detection time to obtain activity status information corresponding to each service includes: For each of the services, at a specified detection time, sending detection information to the service; receiving response information returned by the service in response to the detection information; In a case where the response information represents a normal response, determining that the activity status information corresponding to the service is normal activity; In the case where the response information indicates an abnormal response, a response duration of the service is obtained; and activity status information corresponding to the service is determined according to the response duration.
4. The method according to claim 3, characterized in that The sending of detection information to the service includes one of the following methods: Sending detection information to the service via a network request; Send detection information to the detection port of the service.
5. The method according to claim 3, characterized in that: The determining, according to the response duration, the activity status information corresponding to the service comprises: When the response time is less than a preset time threshold, determining that the activity status information corresponding to the service is normal activity; When the response duration is greater than or equal to the preset duration threshold, the preset duration threshold is adjusted, and the steps of sending detection information to the service and receiving response information returned by the service in response to the detection information are re-executed to determine the activity status information corresponding to the service according to the adjusted preset duration threshold.
6. The method according to claim 5, characterized in that The determining the activity status information corresponding to the service according to the adjusted preset duration threshold comprises: When the adjusted preset duration threshold is greater than or equal to the maximum duration, if the acquired response duration is greater than or equal to the adjusted preset duration threshold, it is determined that the activity state information corresponding to the service is abnormal activity.
7. The method according to claim 1 or 2, characterized in that: The performing service response detection on the target service to obtain response status information corresponding to the target service includes: Sending a data request to the target service; and receiving an execution result returned by the target service in response to the data request; When the execution result satisfies the preset result, the response status information corresponding to the target service is normal response; When the execution result does not meet the preset result, the response status information corresponding to the target service is a response exception.
8. The method according to any one of claims 1 to 7, characterized in that The activity status information includes normal activity and abnormal activity, and the response status information includes normal response and abnormal response; The determining the service state of the target service according to the activity state information corresponding to the target service and the response state information corresponding to the target service comprises: When the activity status information indicates that the activity is normal and the response status information indicates that the response is normal, determining that the service status of the target service is a healthy status; When the activity status information is the activity exception, or the response status information is the response exception, it is determined that the service status of the target service is an unhealthy state.
9. A service status detection device, characterized in that: include: The acquisition module is used to obtain the service list of the registration center; The service list includes multiple services; A first detection module, configured to perform service activity detection on each service in the service list at a specified detection time to obtain activity status information corresponding to each service; A second detection module is used to perform service response detection on the target service to obtain response status information corresponding to the target service; The target service is one of the multiple services; The determination module is used to determine the service state of the target service according to the activity state information corresponding to the target service and the response state information corresponding to the target service, wherein the service state includes a healthy state or an unhealthy state.
10. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the detection method as claimed in any one of claims 1 to 8 when executing the program.
11. A readable storage medium, characterized in that: When the instructions or transactions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 8.
12. A computer program product, characterized in that The method comprises instructions or transactions, which, when executed by a processor in an electronic device, cause the electronic device to execute the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Service detection method, rule configuration method, related equipment and medium
CN111404759A
Server state detection method and device
CN113032223A
Node management method and device based on node state and readable storage medium
CN116915654A