Microservice code version monitoring method and device, equipment, medium and product

By generating and sending hash values ​​to the management center on the microservice server, the problem of inefficient code version monitoring in the microservice architecture is solved, and the consistency of quickly monitoring code versions is achieved.

CN118939308APending Publication Date: 2024-11-12CHINA UNITED NETWORK COMM GRP CO LTD +2
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411067298.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

In the prior art, the code version monitoring efficiency in the microservice architecture is low, and it needs to be monitored through two systems: code acquisition system and monitoring platform, resulting in low efficiency.

Method used

By setting up a code version generation unit on the server of the microservice, generating the hash value of the code file and sending it to the microservice management center, the management center judges the consistency of the code version based on the hash value of multiple servers, avoiding the Additional code acquisition system and monitoring platform.

Benefits of technology

It realizes rapid monitoring of multiple server code versions in the microservice architecture, improves monitoring efficiency, and can quickly determine the consistency of code version information of code files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939308A_ABST
    Figure CN118939308A_ABST
Patent Text Reader

Abstract

The invention provides a micro-service code version monitoring method and device, equipment, a medium and a product, and relates to the technical field of micro-services. The method comprises the following steps: a micro-service server generates a first hash value through a code version generation unit according to a code file of an application service stored in the server, and sends the first hash value to a micro-service management center; and the management center of the micro-service receives the first hash values sent by the plurality of servers of the micro-service, and determines the consistency among the code version information corresponding to the application service in the plurality of servers according to the consistency among the plurality of first hash values. According to the method, the first hash value generated according to the same code file is fixed, so that the code version information of the program codes in the code file is represented by the first hash value, and the code versions of the program codes running on a plurality of servers in the micro-service architecture can be quickly monitored.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of microservice technology, and in particular to a method, device, equipment, medium and product for monitoring code versions of microservices. Background Art

[0002] In the digital age, microservice architecture has been widely used in the development and deployment of various application systems. In a microservice architecture, multiple servers can provide the same application service, and ensuring the consistency of the application service code versions on each server is crucial to improving the reliability and performance of the application system.

[0003] In the prior art, it is usually necessary to set up a code collection system to obtain the application service code and its version information running on each server. The code collection system can send these application service codes and their version information to a monitoring platform, such as Prometheus, to monitor the code version, thereby ensuring the consistency of the application service code version loaded on each server.

[0004] However, the above method needs to go through two systems, namely the code collection system and the monitoring platform, and has the problem of low monitoring efficiency. Summary of the invention

[0005] The present application provides a microservice code version monitoring method, apparatus, device, medium and product for quickly monitoring the code version of program codes running on multiple servers in a microservice architecture.

[0006] In a first aspect, the present application provides a method for monitoring a code version of a microservice, the method being applied to any server of the microservice, the server being provided with a code file of the application service and a code version generation unit, the method comprising:

[0007] Generate a first hash value according to the code file of the application service stored in the server by a code version generation unit; wherein the first hash value is used to represent the code version information of the program code in the code file;

[0008] The first hash value is sent to a management center of the microservice, and the management center of the microservice is used to determine whether code version information of the same application service in multiple servers is consistent based on the first hash value.

[0009] In a possible design, generating a first hash value according to a code file of an application service stored in a server by a code version generating unit includes:

[0010] Get all code files corresponding to the application service;

[0011] For each code file, generating a second hash value corresponding to the code file according to the code file;

[0012] A first hash value is generated according to second hash values ​​corresponding to the plurality of code files.

[0013] In a possible design, generating a second hash value corresponding to the code file according to the code file includes:

[0014] Read the complete contents of the code file;

[0015] According to the complete content of the code file, a second hash value corresponding to the code file is calculated by using the first hash algorithm.

[0016] In one possible design, generating a first hash value according to second hash values ​​corresponding to a plurality of code files includes:

[0017] Sort the second hash values ​​corresponding to the multiple code files according to a preset rule;

[0018] Concatenate the sorted second hash values ​​into a string;

[0019] According to the character string formed by connecting the multiple second hash values, the first hash values ​​corresponding to the multiple code files are calculated by using the second hash algorithm.

[0020] In a possible design, generating a first hash value according to a code file of an application service stored in a server by a code version generating unit includes:

[0021] When the application service on the server is started, a service start message is sent to the management center of the microservice, and a first hash value is generated according to the code file of the application service stored in the server by the code version generation unit;

[0022] After the application service is started, the code version generation unit periodically generates a first hash value according to the code file of the application service stored in the server according to a preset time period.

[0023] In a second aspect, the present application provides a method for monitoring the code version of a microservice, which is applied to a management center of the microservice, and the method includes:

[0024] Receive first hash values ​​sent by multiple servers of the microservice, wherein each server is provided with: a code file of the application service and a code version generation unit; for each server, the code version generation unit in the server is used to generate a first hash value sent by the server according to the code file in the server, and the first hash value sent by the server is used to represent the code version information of the program code in the server;

[0025] According to the consistency between the multiple first hash values, the consistency between the code version information corresponding to the application service in the multiple servers is determined.

[0026] In a possible design, determining consistency among code version information corresponding to an application service in multiple servers according to consistency among multiple first hash values ​​includes:

[0027] If any two first hash values ​​are inconsistent, it is determined that the code version information corresponding to the application service in multiple servers is inconsistent;

[0028] If all the first hash values ​​are consistent, it is determined that the code version information corresponding to the application service in multiple servers is consistent.

[0029] In one possible design, the method further includes:

[0030] If any two first hash values ​​are inconsistent, first prompt information is output, where the first prompt information is used to indicate the inconsistent first hash values ​​and the corresponding server identifier.

[0031] In one possible design, the method further includes:

[0032] Obtain multiple historical monitoring results within a preset historical time period;

[0033] If multiple historical monitoring results all indicate that the code version information corresponding to the application service in multiple servers is inconsistent, a second prompt information is output, and the second prompt information is used to indicate that the program code of the corresponding application service in at least one server is not updated in time.

[0034] In a third aspect, the present application provides a code version monitoring device for a microservice, which is applied to any server of the microservice, and the server is provided with a code file and a code version generation unit of the application service, and the device includes:

[0035] A code version generating unit, configured to generate a first hash value according to a code file of an application service stored in a server; wherein the first hash value is used to represent code version information of a program code in the code file;

[0036] The sending module is used to send the first hash value to the management center of the microservice, and the management center of the microservice is used to determine whether the code version information of the same application service in multiple servers is consistent according to the first hash value.

[0037] In one possible design, the code version generation unit includes: an acquisition module, a second hash value module, and a first hash value module;

[0038] The acquisition module is used to obtain all code files corresponding to the application service;

[0039] A second hash value module, configured to generate, for each code file, a second hash value corresponding to the code file according to the code file;

[0040] The first hash value module is used to generate a first hash value according to second hash values ​​corresponding to multiple code files.

[0041] In one possible design, the second hash value module includes: a reading module and a first hash algorithm module;

[0042] Reading module, used to read the complete content of the code file;

[0043] The first calculation module is used to calculate a second hash value corresponding to the code file according to the complete content of the code file by using a first hash algorithm.

[0044] In one possible design, the first hash value module includes: a sorting module, a connection module, and a second calculation module;

[0045] A sorting module, used to sort the second hash values ​​corresponding to the multiple code files according to a preset rule;

[0046] A connection module, used for connecting the sorted second hash values ​​into a string;

[0047] The second calculation module is used to calculate the first hash values ​​corresponding to the plurality of code files by a second hash algorithm according to a character string formed by connecting the plurality of second hash values.

[0048] In a possible design, the code version generation unit further includes a startup generation module and a cycle generation module;

[0049] A startup generation module, used to send a service startup message to a management center of the microservice when an application service on the server is started, and generate a first hash value according to a code file of the application service stored in the server through a code version generation unit;

[0050] The periodic generation module is used to periodically generate a first hash value according to the code file of the application service stored in the server through the code version generation unit according to a preset time period after the application service is started.

[0051] In a fourth aspect, the present application provides a code version monitoring device for a microservice, which is applied to a management center of the microservice, and includes:

[0052] A receiving module, configured to receive first hash values ​​sent by multiple servers of a microservice, wherein each server is provided with: a code file of an application service and a code version generation unit; for each server, the code version generation unit in the server is configured to generate a first hash value sent by the server according to the code file in the server, and the first hash value sent by the server is used to represent code version information of a program code in the server;

[0053] The determination module is used to determine the consistency between the code version information corresponding to the application service in multiple servers according to the consistency between the multiple first hash values.

[0054] In a possible design, the determination module includes: a version inconsistency module and a version consistency module;

[0055] A version inconsistency module, used to determine that the code version information corresponding to the application service in multiple servers is inconsistent if any two first hash values ​​are inconsistent;

[0056] The version consistency module is used to determine that the code version information corresponding to the application service in multiple servers is consistent if all the first hash values ​​are consistent.

[0057] In a possible design, the version inconsistency module is also used to output a first prompt message if any two first hash values ​​are inconsistent, and the first prompt message is used to indicate the inconsistent first hash value and the corresponding server identifier.

[0058] In a possible design, the version inconsistency module includes: a historical result acquisition module and a second prompt information module;

[0059] A historical result acquisition module is used to obtain multiple historical monitoring results within a preset historical time period;

[0060] The second prompt information module is used to output second prompt information if multiple historical monitoring results all indicate that the code version information corresponding to the application service in multiple servers is inconsistent. The second prompt information is used to indicate that the program code of the corresponding application service in at least one server has not been updated in time.

[0061] In a fifth aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0062] Memory stores computer-executable instructions;

[0063] The processor executes the computer execution instructions stored in the memory to implement a code version monitoring method for a microservice according to the first or second aspect of the invention.

[0064] In a sixth aspect, the present application provides a computer-readable storage medium, which stores computer execution instructions. When the computer execution instructions are executed by a processor, a code version monitoring method for a microservice is used to implement the content of the first or second aspect of the invention.

[0065] In a seventh aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, is used to implement a code version monitoring method for a microservice according to the first or second aspect of the invention.

[0066] In an eighth aspect, the present application provides a code version monitoring system for a microservice, the system comprising a microservice management center and multiple servers; the server is used to execute a microservice code version monitoring method as described in the first aspect of the invention, and the management center is used to execute a microservice code version monitoring method as described in the second aspect of the invention.

[0067] The present application provides a method, apparatus, device, medium and product for monitoring the code version of a microservice. The server of the microservice generates a first hash value according to the code file of the application service stored in the server through a code version generation unit, and sends the first hash value to a management center of the microservice. The management center of the microservice receives the first hash values ​​sent by multiple servers of the microservice, and determines the consistency between the code version information corresponding to the application service in multiple servers based on the consistency between the multiple first hash values. The following technical effects are achieved: the server generates a first hash value according to the code file through the code version generation unit, and sends the first hash value to the management center of the microservice. The management center of the microservice determines whether the code version information of the same application service in multiple servers is consistent by comparing the consistency between multiple first hash values. There is no need to set up an additional code acquisition system and monitoring platform. Only the unique first hash value generated by the code file is used, and the code version information of the program code in the code file is represented by the first hash value. Through the existing microservice management center, such as the registration center or configuration center of the microservice, multiple hash values ​​are compared to determine whether they are consistent, so as to determine whether the code version information of the same application service in multiple servers is consistent. The code version of the program code running on multiple servers in the microservice architecture can be quickly monitored; the code version generation unit generates a first hash value according to the code file of the application service stored in the server, and the first hash value is used to represent the code version information of the program code in the code file, thereby solving the problem of how to quickly determine the code version information of the code file. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0069] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0070] Figure 1 A system architecture diagram of a code version monitoring method for a microservice provided in an embodiment of the present application;

[0071] Figure 2 A schematic diagram of a code version monitoring method for a microservice provided in an embodiment of the present application Figure 1 ;

[0072] Figure 3 A schematic diagram of a code version monitoring method for a microservice provided in an embodiment of the present application Figure 2 ;

[0073] Figure 4 A schematic diagram of the structure of a code version monitoring device for a microservice provided in an embodiment of the present application;

[0074] Figure 5 A schematic diagram of the structure of a code version monitoring device for a microservice provided in an embodiment of the present application;

[0075] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0076] Reference numerals:

[0077] 110-application system; 120-microservice management center; 111-application service; 112-server;

[0078] 310-code version generating unit; 320-sending module;

[0079] 410-receiving module; 420-determining module;

[0080] 510 - processor; 520 - memory; 530 - communication component; 540 - bus. DETAILED DESCRIPTION

[0081] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0082] In the embodiments of the present application, words such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. Those skilled in the art will appreciate that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit the difference. It should be noted that in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way. In the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more.

[0083] It should be noted that the "at..." in the embodiments of the present application can be the instant when a certain situation occurs, or it can be a period of time after a certain situation occurs, and the embodiments of the present application do not specifically limit this. In addition, the code version monitoring method of a microservice provided in the embodiments of the present application is only used as an example, and the code version monitoring method of a microservice can also include more or less content.

[0084] In order to clearly describe the technical solutions of the embodiments of the present application, some terms and technologies involved in the embodiments of the present application are briefly introduced below:

[0085] Microservice: refers to an architecture and organizational method for developing software, in which the developed application system may include multiple application services, each of which can be deployed on a single server or multiple servers. The application service in the embodiment of the present application refers to an application service deployed on multiple servers.

[0086] Application system: A set of integrated software components with multiple functions, which can include multiple application services, such as user services, order services, and product services.

[0087] Application service: refers to the specific application program functions included in the application system. The application service in the embodiment of the present application can be any one of user services, order services or product services.

[0088] Microservice architecture is a new technology for deploying applications and services in the cloud. The core idea of ​​microservices is to decompose the application system into multiple small application services, each of which has independent functions and roles. Each application service can be independently developed, tested, deployed and expanded. This improves the maintainability, scalability and flexibility of the entire application system. For each small application service, it can be deployed on a single server or on multiple servers. In other words, in the microservice architecture, multiple servers can provide the same application service. Therefore, ensuring the consistency of the application service code version on each server that provides the same application service is crucial to improving the reliability and performance of the application system.

[0089] In the prior art, it is usually necessary to set up a code collection system to obtain the application service code and its version information running on each server. The code collection system can send these application service codes and their version information to a monitoring platform, such as Prometheus, to monitor the code version, thereby ensuring the consistency of the application service code version loaded on each server.

[0090] However, the above method needs to go through two systems, namely the code collection system and the monitoring platform, and has the problem of low monitoring efficiency.

[0091] Based on this, the embodiments of the present application provide a code version monitoring method, device, equipment, medium and product for a microservice, which can be used in the field of microservice technology and aim to solve the above technical problems of the prior art.

[0092] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0093] Figure 1 A system architecture diagram of a code version monitoring method for a microservice provided in an embodiment of the present application. It should be noted that: Figure 1 What is shown is merely an example of a system architecture to which the embodiments of the present application can be applied, in order to help those skilled in the art understand the technical content of the present application, but it does not mean that the embodiments of the present application cannot be used in other devices, systems, environments or scenarios.

[0094] like Figure 1As shown, the system architecture of the method includes: an application system 110 and a microservice management center 120. The application system 110 and the microservice management center 120 are connected in communication, and the application system 110 may include multiple application services 111, and each application service 111 may be deployed on multiple servers 112. The multiple application services 111 may be user services, order services, product services, etc. It should be noted that Figure 1 The number of application services 111 and servers 112 deployed by each application service shown in the figure is for illustration only. In other embodiments, the system architecture may further include other numbers of application services 111, and each application service 111 may further be deployed on other numbers of servers 112. No specific limitation is made here.

[0095] The management center 120 of the microservice can be a registration center of the microservice or a configuration center, which is used to receive the startup message of the application service 111 and the version information of the program code sent by each server 112 to determine whether the code version information of the same application service in multiple servers is consistent. If the code version information is inconsistent, a prompt message is output to issue a corresponding warning to the staff, and at the same time remind the staff to process and update the server that has not updated the program code in time, so that the code version information of the same application service in multiple servers is consistent.

[0096] In some other embodiments, the management center 120 of the microservice may also be a monitoring platform, such as Prometheus, and no specific limitation is made here.

[0097] Figure 2 A schematic diagram of a code version monitoring method for a microservice provided in an embodiment of the present application Figure 1 .like Figure 2 As shown, the method includes:

[0098] S101. The microservice server generates a first hash value through a code version generation unit according to a code file of an application service stored in the server.

[0099] Specifically, the method can be applied to any server of the microservice, and the code file of the application service and the code version generation unit are set in the server. The first hash value can be generated according to the code file of the application service stored in the server by the code version generation unit. The code version generation unit may include a jar file set in advance, such as an information collection code jar file.

[0100] Since the first hash value generated from the same code file is fixed, when the content of the code file changes, for example, when the program code in the code file is updated, the first hash value generated from the code file will also change accordingly. Therefore, the embodiment of the present application uses the first hash value to represent the code version information of the program code in the code file.

[0101] S102: The microservice server sends the first hash value to the management center of the microservice.

[0102] Specifically, after generating the first hash value according to the code file, the microservice server may send the first hash value to the microservice management center, so that the microservice management center can determine whether the code version information of the same application service in multiple servers is consistent according to the first hash value.

[0103] S103: The management center of the microservice receives the first hash value sent by multiple servers of the microservice.

[0104] Specifically, the management center of the microservice is used to receive the first hash value sent by multiple servers in the microservice architecture. Each server is provided with: a code file of the application service and a code version generation unit; for each server, the code version generation unit in the server is used to generate the first hash value sent by the server according to the code file in the server, and the first hash value sent by the server is used to represent the code version information of the program code in the server.

[0105] S104. The management center of the microservice determines the consistency between the code version information corresponding to the application service in multiple servers based on the consistency between the multiple first hash values.

[0106] Specifically, after receiving the first hash values ​​sent by multiple servers, the management center of the microservice can determine the consistency between the code version information corresponding to the application service in multiple servers based on the consistency between the multiple first hash values. That is, by determining whether the first hash values ​​sent by multiple servers providing the same application service are the same, it can be determined whether the code versions corresponding to the application service in multiple servers are consistent.

[0107] This embodiment provides a code version monitoring method for a microservice, in which a server of the microservice generates a first hash value according to a code file of an application service stored in the server through a code version generation unit, and sends the first hash value to a management center of the microservice; the management center of the microservice receives the first hash values ​​sent by multiple servers of the microservice, and determines the consistency between the code version information corresponding to the application service in multiple servers based on the consistency between the multiple first hash values. The following technical effects are achieved: the server generates a first hash value according to the code file through the code version generation unit, and sends the first hash value to the management center of the microservice. The management center of the microservice determines whether the code version information of the same application service in multiple servers is consistent by comparing the consistency between multiple first hash values. There is no need to set up an additional code acquisition system and monitoring platform. Only the unique first hash value generated by the code file is used, and the code version information of the program code in the code file is represented by the first hash value. Through the existing microservice management center, such as the registration center or configuration center of the microservice, multiple hash values ​​are compared to determine whether they are consistent, so as to determine whether the code version information of the same application service in multiple servers is consistent. The code version of the program code running on multiple servers in the microservice architecture can be quickly monitored; the code version generation unit generates a first hash value according to the code file of the application service stored in the server, and the first hash value is used to represent the code version information of the program code in the code file, thereby solving the problem of how to quickly determine the code version information of the code file.

[0108] Figure 3 A schematic diagram of a code version monitoring method for a microservice provided in an embodiment of the present application Figure 2 In one possible example, Figure 3 As shown, in this embodiment Figure 2 Based on the embodiment, how the microservice server generates the first hash value and how the microservice management center determines the consistency between the code version information are described in detail. Figure 3 As shown, the method includes:

[0109] S201. The microservice server obtains all code files corresponding to the application service.

[0110] Specifically, the microservice server obtains all code files corresponding to the application service through the code version generation unit. The code file can be a source code file, a class file compiled from the source code file, or a jar file obtained by packaging the class file.

[0111] S202. For each code file, the microservice server reads the complete content of the code file.

[0112] For each code file, the microservice server can read the complete content of the code file through the code version generation unit to generate a second hash value corresponding to the code file according to the code file.

[0113] S203. For each code file, the microservice server calculates a second hash value corresponding to the code file according to the complete content of the code file by using the first hash algorithm.

[0114] Specifically, for each code file, the microservice server can calculate a second hash value corresponding to the code file through a first hash algorithm based on the complete content of the code file through a code version generation unit.

[0115] The first hash algorithm can be any existing algorithm that can be used to generate a hash value, such as Message Digest Algorithm 5 (MD5), Secure Hash Algorithm 256 (SHA-256), or Secure Hash Algorithm 512 (SHA-512).

[0116] S204. The microservice server sorts the second hash values ​​corresponding to the multiple code files according to a preset rule.

[0117] Specifically, the microservice server can sort the second hash values ​​corresponding to multiple code files according to a preset rule through the code version generation unit, such as sorting them in alphabetical order or file path order, to ensure that the generated first hash value is certain.

[0118] In this embodiment, the second Hash values ​​are sorted according to a preset rule, which can ensure that as long as the contents of the code files are the same, the first Hash values ​​finally generated are also the same.

[0119] S205: The microservice server connects the sorted multiple second hash values ​​into a string.

[0120] Specifically, in order to generate a first hash value according to the second hash values ​​corresponding to the multiple code files, the microservice server can connect the sorted multiple second hash values ​​into a complete string through the code version generation unit to obtain the first hash values ​​corresponding to the multiple code files according to the string.

[0121] S206. The microservice server calculates the first hash values ​​corresponding to the multiple code files through a second hash algorithm according to the character string formed by connecting the multiple second hash values.

[0122] Specifically, the code version generation unit in the microservice server can calculate the first hash values ​​corresponding to the multiple code files through the second hash algorithm according to the character string formed by connecting the multiple second hash values.

[0123] It should be noted that the second Hash algorithm in this embodiment may be the same as or different from the first Hash algorithm.

[0124] S207: The microservice server sends the first hash value to the management center of the microservice.

[0125] S208: The management center of the microservice receives the first hash value sent by multiple servers of the microservice.

[0126] S207-S208 are similar to S102-S103 and will not be described in detail in this embodiment.

[0127] S209: If any two first hash values ​​are inconsistent, the management center of the microservice determines that the code version information corresponding to the application service in multiple servers is inconsistent.

[0128] Specifically, after the microservice management center receives the first hash values ​​sent by multiple servers corresponding to the same application service, if it determines that any two of the first hash values ​​are inconsistent, it can be determined that the code version information corresponding to the application service in multiple servers is inconsistent.

[0129] S210: If any two first hash values ​​are inconsistent, the management center of the microservice outputs a first prompt message.

[0130] Specifically, when the management center of the microservice determines that any two first hash values ​​are inconsistent, it can determine that the code version information corresponding to the same application service in multiple servers is inconsistent, and can further output the first prompt information, which is used to indicate the inconsistent first hash value, as well as the corresponding server Internet Protocol (IP) address, domain name, application service name, port number, server name and other server identifiers.

[0131] S211. If all the first hash values ​​are consistent, the management center of the microservice determines that the code version information corresponding to the application service in multiple servers is consistent.

[0132] Specifically, since the first hash value generated according to the same code file is fixed, if all the first hash values ​​are consistent, the management center of the microservice can determine that the code version information corresponding to the application service in multiple servers is consistent.

[0133] A code version monitoring method for a microservice provided in an embodiment of the present application obtains all code files corresponding to an application service; for each code file, generates a second hash value corresponding to the code file based on the code file, and sorts the second hash values ​​corresponding to multiple code files according to a preset rule; then connects the sorted multiple second hash values ​​into a string; and then calculates the first hash values ​​corresponding to the multiple code files through a second hash algorithm based on the string formed by connecting the multiple second hash values, thereby solving the problem of how to calculate the first hash value of the code file, thereby obtaining the code version information of the program code in the code file.

[0134] In one embodiment, when the application service on the server is started, the server of the microservice can send a service startup message to the management center of the microservice, and generate a first hash value according to the code file of the application service stored in the server through the code version generation unit, that is, when the application service on each server is started, the first hash value can be synchronously calculated once in each server to determine the consistency between the code version information corresponding to the application service in multiple servers. And after the application service is started, according to the preset time period, the first hash value is periodically generated by the code version generation unit according to the code file of the application service stored in the server to monitor in real time whether the code version information of the same application service in multiple servers is consistent. Among them, the preset time period can be a specific time period such as 30 seconds, 1 minute, 2 minutes or 5 minutes, which can be set according to the specific situation, and no specific restrictions are made here.

[0135] An embodiment of the present application provides a code version monitoring method for a microservice. The server of the microservice can synchronously calculate a first hash value once in each server when an application service on each server is started, and after the application service is started, the first hash value is periodically calculated according to a preset time period, thereby achieving real-time monitoring of whether the code version information of the same application service in multiple servers is consistent.

[0136] In one embodiment, the management center of the microservice can obtain multiple historical monitoring results within a preset historical time period. If multiple historical monitoring results all indicate that the code version information corresponding to the application service in multiple servers is inconsistent, a second prompt information is output, and the second prompt information is used to indicate that the program code of the corresponding application service in at least one server has not been updated in time. Through the second prompt information, the management center of the microservice can issue an early warning to the staff to remind the staff to update the program code of the application service in time for the server that has not updated the program code in time, so that the code version information of the same application service in multiple servers is consistent. Among them, the preset historical time period refers to the time when the application service is released and launched that is greater than the preset time period. That is, in the process of the application system being released and launched, that is, in the process of rolling release of each application service, the code version information will be temporarily inconsistent, so the management center of the microservice will record the duration of the inconsistency of the first hash value. If the duration reaches the preset historical time period, such as 10 minutes, the second prompt information is output to remind the staff to find and handle the abnormal version of the server in time, so as to ensure the consistency of the code version information corresponding to the same application service in multiple servers.

[0137] An embodiment of the present application provides a code version monitoring method for a microservice. The management center of the microservice obtains multiple historical monitoring results within a preset historical time period, and when the multiple historical monitoring results all indicate that the corresponding code version information of the application service in multiple servers is inconsistent, the management center outputs a second prompt message, so as to remind the staff to update the program code of the application service in a timely manner for the server whose program code is not updated in time, so as to make the code version information of the same application service in multiple servers consistent.

[0138] In one embodiment, the code version generation unit in each server can also send the first hash value to a third-party storage unit for centralized storage, and the management center of the microservice can obtain the first hash value from the third-party storage unit and make a comparison. The third-party storage unit can be a database, such as a remote dictionary server (RemoteDictionary Server, Redis), etc.

[0139] The embodiment of the present invention can divide the electronic device or the main control device into functional modules according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present invention is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0140] Figure 4 A schematic diagram of a code version monitoring device for a microservice provided in an embodiment of the present application. The device is applied to any server of a microservice, such as Figure 4 As shown, the code version monitoring device of the microservice includes: a code version generating unit 310 and a sending module 320;

[0141] The code version generating unit 310 is used to generate a first hash value according to the code file of the application service stored in the server; wherein the first hash value is used to represent the code version information of the program code in the code file;

[0142] The sending module 320 is used to send the first hash value to the management center of the microservice, and the management center of the microservice is used to determine whether the code version information of the same application service in multiple servers is consistent according to the first hash value.

[0143] In one possible design, the code version generation unit 310 includes: an acquisition module, a second hash value module, and a first hash value module;

[0144] The acquisition module is used to obtain all code files corresponding to the application service;

[0145] A second hash value module, configured to generate, for each code file, a second hash value corresponding to the code file according to the code file;

[0146] The first hash value module is used to generate a first hash value according to second hash values ​​corresponding to multiple code files.

[0147] In one possible design, the second hash value module includes: a reading module and a first hash algorithm module;

[0148] Reading module, used to read the complete content of the code file;

[0149] The first calculation module is used to calculate a second hash value corresponding to the code file according to the complete content of the code file by using a first hash algorithm.

[0150] In one possible design, the first hash value module includes: a sorting module, a connection module, and a second calculation module;

[0151] A sorting module, used to sort the second hash values ​​corresponding to the multiple code files according to a preset rule;

[0152] A connection module, used for connecting the sorted second hash values ​​into a string;

[0153] The second calculation module is used to calculate the first hash values ​​corresponding to the plurality of code files by a second hash algorithm according to a character string formed by connecting the plurality of second hash values.

[0154] In one possible design, the code version generation unit 310 further includes a startup generation module and a cycle generation module;

[0155] A startup generation module, used to send a service startup message to a management center of the microservice when an application service on the server is started, and generate a first hash value according to a code file of the application service stored in the server through a code version generation unit;

[0156] The periodic generation module is used to periodically generate a first hash value according to the code file of the application service stored in the server through the code version generation unit according to a preset time period after the application service is started.

[0157] Figure 5 A schematic diagram of a microservice code version monitoring device provided in an embodiment of the present application. The device is applied to a microservice management center, such as Figure 5 As shown, the code version monitoring device of the microservice includes: a receiving module 410 and a determining module 420;

[0158] A receiving module 410 is used to receive first hash values ​​sent by multiple servers of a microservice, wherein each server is provided with: a code file of an application service and a code version generation unit; for each server, the code version generation unit in the server is used to generate a first hash value sent by the server according to the code file in the server, and the first hash value sent by the server is used to represent the code version information of the program code in the server;

[0159] The determination module 420 is used to determine the consistency between the code version information corresponding to the application service in multiple servers according to the consistency between the multiple first hash values.

[0160] In one possible design, the determination module 420 includes: a version inconsistency module and a version consistency module;

[0161] A version inconsistency module, used to determine that the code version information corresponding to the application service in multiple servers is inconsistent if any two first hash values ​​are inconsistent;

[0162] The version consistency module is used to determine that the code version information corresponding to the application service in multiple servers is consistent if all the first hash values ​​are consistent.

[0163] In a possible design, the version inconsistency module is also used to output a first prompt message if any two first hash values ​​are inconsistent, and the first prompt message is used to indicate the inconsistent first hash value and the corresponding server identifier.

[0164] In a possible design, the version inconsistency module includes: a historical result acquisition module and a second prompt information module;

[0165] A historical result acquisition module is used to obtain multiple historical monitoring results within a preset historical time period;

[0166] The second prompt information module is used to output second prompt information if multiple historical monitoring results all indicate that the code version information corresponding to the application service in multiple servers is inconsistent. The second prompt information is used to indicate that the program code of the corresponding application service in at least one server has not been updated in time.

[0167] The present embodiment provides a device for monitoring the code version of a microservice, which can execute a method for monitoring the code version of a microservice in the above-mentioned embodiment. The implementation principle and technical effects thereof are similar, and are not described in detail in the present embodiment.

[0168] In the specific implementation of the aforementioned code version monitoring device for a microservice, each module can be implemented as a processor, and the processor can execute computer execution instructions stored in the memory, so that the processor executes the aforementioned code version monitoring method for a microservice.

[0169] The present application also provides a microservice code version monitoring system, which includes a microservice management center and multiple servers; the server and the management center are used to implement the above microservice code version monitoring method.

[0170] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 6 As shown, the electronic device 500 includes: at least one processor 510 and a memory 520. The electronic device 500 also includes a communication component 530. The processor 510, the memory 520 and the communication component 530 are connected via a bus 540.

[0171] In the specific implementation process, at least one processor 510 executes the computer execution instructions stored in the memory 520, so that at least one processor 510 executes the code version monitoring method of a microservice executed by the electronic device side as above.

[0172] The specific implementation process of the processor 510 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.

[0173] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.

[0174] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk storage.

[0175] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.

[0176] The above-mentioned functions implemented by the electronic device and the main control device introduce the scheme provided by the embodiment of the present invention. It can be understood that in order to implement the above-mentioned functions, the electronic device or the main control device includes a hardware structure and / or software module corresponding to the execution of each function. In combination with the units and algorithm steps of each example described in the embodiment disclosed in the embodiment of the present invention, the embodiment of the present invention can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present invention.

[0177] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, it is used to implement the code version monitoring method of a microservice as described above.

[0178] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.

[0179] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as: ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in an electronic device or a main control device.

[0180] The present application also provides a computer program product, which includes a computer program. The computer program is stored in a readable storage medium. At least one processor of an electronic device can read the computer program from the readable storage medium. At least one processor executes the computer program so that the electronic device executes the solution provided in any of the above embodiments.

[0181] Those skilled in the art can understand that all or part of the steps of the above method embodiments can be completed by hardware related to program instructions. The above program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above method embodiments are executed; and the above storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.

[0182] So far, the technical solution of the present application has been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present application is obviously not limited to these specific embodiments, and the above embodiments are only used to illustrate the technical solution of the present application rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A code version monitoring method for microservices, characterized in that: The method is applied to any server of a microservice, wherein the server is provided with a code file of an application service and a code version generation unit, and the method comprises: Generate a first hash value according to the code file of the application service stored in the server by the code version generation unit; wherein the first hash value is used to represent the code version information of the program code in the code file; The first hash value is sent to a management center of a microservice, and the management center of the microservice is used to determine whether the code version information of the same application service in multiple servers is consistent according to the first hash value.

2. The method according to claim 1, characterized in that The generating a first hash value according to the code file of the application service stored in the server by the code version generating unit includes: Obtain all the code files corresponding to the application service; For each of the code files, generating a second hash value corresponding to the code file according to the code file; The first Hash value is generated according to the second Hash values ​​corresponding to the plurality of code files.

3. The method according to claim 2, characterized in that Generating a second hash value corresponding to the code file according to the code file includes: Read the complete content of the code file; According to the complete content of the code file, the second hash value corresponding to the code file is calculated by using a first hash algorithm.

4. The method according to claim 2, characterized in that: Generating the first Hash value according to the second Hash values ​​corresponding to the plurality of code files includes: Sort the second hash values ​​corresponding to the plurality of code files according to a preset rule; Connect the sorted plurality of the second hash values ​​into a string; The first hash values ​​corresponding to the plurality of code files are calculated using a second hash algorithm according to the character string formed by connecting the plurality of second hash values.

5. The method according to any one of claims 1 to 4, characterized in that Generating a first hash value according to the code file of the application service stored in the server by the code version generating unit includes: When the application service on the server is started, a service start message is sent to the management center of the microservice, and the first hash value is generated according to the code file of the application service stored in the server by the code version generation unit; After the application service is started, the first hash value is periodically generated by the code version generation unit according to the code file of the application service stored in the server at a preset time period.

6. A code version monitoring method for a microservice, characterized in that: The method is applied to a management center of a microservice, and the method includes: Receive first hash values ​​sent by multiple servers of microservices, wherein each of the servers is provided with: a code file of an application service and a code version generation unit; for each of the servers, the code version generation unit in the server is used to generate the first hash value sent by the server according to the code file in the server, and the first hash value sent by the server is used to represent the code version information of the program code in the server; The consistency between the code version information corresponding to the application service in the multiple servers is determined according to the consistency between the multiple first hash values.

7. The method according to claim 6, characterized in that Determining consistency among the code version information corresponding to the application service in the plurality of servers according to consistency among the plurality of the first hash values ​​includes: If any two of the first hash values ​​are inconsistent, it is determined that the code version information corresponding to the application service in the multiple servers is inconsistent; If all the first hash values ​​are consistent, it is determined that the code version information corresponding to the application service in the multiple servers is consistent.

8. The method according to claim 7, characterized in that The method further comprises: If any two of the first Hash values ​​are inconsistent, a first prompt message is output, where the first prompt message is used to indicate the inconsistent first Hash values ​​and the corresponding server identifier.

9. The method according to claim 7, characterized in that: The method further comprises: Obtain multiple historical monitoring results within a preset historical time period; If multiple historical monitoring results all indicate that the code version information corresponding to the application service in multiple servers is inconsistent, a second prompt information is output, wherein the second prompt information is used to indicate that the program code corresponding to the application service in at least one of the servers is not updated in time.

10. A code version monitoring device for a microservice, characterized in that: The device is applied to any server of a microservice, and a code file and a code version generation unit of an application service are provided in the server, and the device includes: The code version generating unit is used to generate a first hash value according to the code file of the application service stored in the server; wherein the first hash value is used to represent the code version information of the program code in the code file; A sending module is used to send the first hash value to a management center of a microservice, and the management center of the microservice is used to determine whether the code version information of the same application service in multiple servers is consistent according to the first hash value.

11. A code version monitoring device for a microservice, characterized in that: The device is applied to the management center of microservices, and the device includes: A receiving module, configured to receive first hash values ​​sent by multiple servers of a microservice, wherein each of the servers is provided with: a code file of an application service and a code version generation unit; for each of the servers, the code version generation unit in the server is configured to generate the first hash value sent by the server according to the code file in the server, and the first hash value sent by the server is used to represent the code version information of the program code in the server; A determination module is used to determine the consistency between the code version information corresponding to the application service in the multiple servers according to the consistency between the multiple first hash values.

12. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the code version monitoring method for a microservice as described in any one of claims 1 to 5 or the code version monitoring method for a microservice as described in any one of claims 6 to 9.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the code version monitoring method for a microservice as described in any one of claims 1 to 5 or the code version monitoring method for a microservice as described in any one of claims 6 to 9.

14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the code version monitoring method for a microservice as described in any one of claims 1 to 5 or the code version monitoring method for a microservice as described in any one of claims 6 to 9 is implemented.

15. A code version monitoring system for microservices, characterized in that: The system includes a microservice management center and multiple servers; the server is used to execute the method as described in any one of claims 1 to 5, and the management center is used to execute the method as described in any one of claims 6 to 9.

Citation Information

Cited By

  • Service updating method, electronic equipment, storage medium and program product

    CN120353487A