A component statistics reporting method, device and medium
By automatically registering the reporting mechanism when component loads, using the spring.factories configuration file and StatisticHandle class, the problem of inaccurate component statistics is solved, and more accurate and flexible component statistics are achieved.
Patent Information
- Application Number
- CN202211434890.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-16
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2042-11-16
AI Technical Summary
The prior art has problems with inaccurate data in component statistics, especially due to statistical data defects caused by pom file dependency delivery characteristics and differences in different project running containers.
The automatic registration and reporting mechanism is adopted when component loading, and the StatisticHandle class is instantiated by reading the spring.factories configuration file, and the report initialization method is called, component configuration information is collected, and reported to the display side through asynchronous Http requests.
The accuracy and flexibility of component statistics are achieved, reducing the impact on project performance, and providing richer statistical information.
Smart Images

Figure CN115904340B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer software technology, and in particular to a component statistics reporting method, device and medium. Background Art
[0002] Spring Cloud Alibaba provides a full range of solutions for developing and building microservice architectures. Using Spring Cloud Alibaba to build a microservice development technology platform to unify the company's technical architecture can not only unify the company's technology stack and accumulate the company's technical assets, but also enable business development using a unified platform, which can improve the quality of business development and lower the technical threshold for development.
[0003] In order to better maintain, upgrade and expand the technology platform, it is necessary to collect statistics on the platform technology components used in different projects of the company using the technology platform, and then strengthen testing of frequently used technology components to improve stability; for low-frequency used components, it is also necessary to investigate and analyze the reasons why projects are not using them, and then take corresponding measures.
[0004] The current mainstream method for component statistics is to perform a full package scan on the project, and scan all the platform components that the project depends on during the package scan to record and report. There are generally two main scanning methods:
[0005] The first is to scan the pom file of the project. The pom file is an xml file. The xml file reading technology can be used to obtain the content of the xml file, and then parse the content to find the platform technology components referenced in it. This method has a major flaw. The dependencies configured in the pom file can be passed from parent to child. For example, component A is referenced in the project, but component A references component B. Based on the characteristics of pom dependency transmission, the functions of components A and B can be used at the same time in the project, but scanning the pom file can only scan component A, resulting in inaccurate statistical data.
[0006] The second is to scan the final running package of the project. When packaging the project, the pom dependencies and their transitive dependencies will be unified into the running package. Scanning the running package can solve the defects of the first solution and will not miss any scans. This method also has defects. Different project running containers determine different packaging methods. There are both Jar and war package forms, which cannot take into account different usage scenarios. Summary of the invention
[0007] In view of the technical defects in the prior art, the purpose of the embodiments of the present invention is to provide a component statistics reporting method, device and medium. The component statistics reporting method of the present invention adopts an automatic registration and reporting mechanism when the component is loaded, which can solve the shortcomings of the existing technical solutions in the background technology, and is implemented based on the spring.factories mechanism, with low technical difficulty and simple code maintenance.
[0008] To achieve the above objectives, in a first aspect, an embodiment of the present invention provides a component statistics reporting method, which is applied to a statistics terminal and includes:
[0009] Read and load the contents of the spring.factories configuration file in the component package;
[0010] Instantiate the StatisticHandle class in the pring.factories configuration file;
[0011] Call the report initialization method defined in the StatisticHandle class to collect component configuration information;
[0012] Report the collected component configuration information to the display end.
[0013] Furthermore, the spring.factories configuration file is pre-written and generated according to the actual situation of the component package;
[0014] The spring.factories configuration file contains a list of classes that need to be instantiated when the component is loaded.
[0015] Further, the instantiation of the StatisticHandle class in the pring.factories configuration file includes:
[0016] Read the spring.factories configuration file, parse the configuration content in the spring.factories configuration file, and obtain the com.sca4cloud.sca.common.statistic.StatisticHandle processing class path;
[0017] The parameterless constructor function of the StatisticHandle class is called through the Java reflection method to obtain the instance object of the StatisticHandle class and complete the instantiation process.
[0018] Furthermore, the component configuration information includes component information itself and information defined in the StatisticProperties class, and the StatisticProperties class is a predefined statistical parameter configuration class.
[0019] Furthermore, the information defined in the StatisticProperties class is configured in a project configuration file on the statistics side.
[0020] Furthermore, the StatisticHandle class and the StatisticProperties class are separately encapsulated in a public jar package in the component package.
[0021] Furthermore, the display end data receiving interface is called through an asynchronous Http request to report the collected component configuration information to the display end.
[0022] Furthermore, the method further comprises:
[0023] Receive the processing status returned by the display end, and print the processing status to the statistics end log file.
[0024] In a second aspect, an embodiment of the present invention provides an electronic device, comprising a processor, an input device, an output device and a memory, wherein the processor, input device, output device and memory are interconnected, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method steps described in the first aspect.
[0025] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and wherein the program instructions, when executed by a processor, implement the method steps described in the first aspect.
[0026] Implement the method provided by the embodiment of the present invention:
[0027] 1. The present invention adopts a method of automatic registration and reporting of technical components, making component statistics simpler; the reported statistical information can be freely agreed and adjusted, making the statistical information richer and more flexible;
[0028] 2. Compared with the scanning method, the automatic registration and reporting method of the present invention has more accurate component statistics. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application. In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor.
[0030] Figure 1 is a structural block diagram of a display terminal provided by an embodiment of the present invention;
[0031] Figure 2 is an interface diagram of a display terminal provided by an embodiment of the present invention;
[0032] Figure 3 is a flow chart of a component statistics reporting method provided by an embodiment of the present invention;
[0033] Figure 4 It is a structural diagram of a component statistics reporting system provided by an embodiment of the present invention.
[0034] The realization of the purpose, functional features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. The above-mentioned drawings have shown clear embodiments of this application, which will be described in more detail later. These drawings and textual descriptions are not intended to limit the scope of the concept of this application in any way, but to illustrate the concept of this application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0035] 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.
[0036] It should be noted that, in this article, the terms "include", "comprises" 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 includes 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 "includes a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element. In addition, components, features, and elements with the same name in different embodiments of the present application may have the same meaning or different meanings, and their specific meanings need to be determined by their explanation in the specific embodiment or further combined with the context of the specific embodiment.
[0037] It should be understood that, although the terms first, second, third, etc. may be used to describe various information in this article, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this article, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein can be interpreted as "at the time of" or "when" or "in response to determination". Furthermore, as used in this article, the singular forms "one", "one" and "the" are intended to also include plural forms, unless there is an opposite indication in the context. It should be further understood that the terms "comprising" and "including" indicate that there are the described features, steps, operations, elements, components, projects, kinds, and / or groups, but do not exclude the existence, occurrence or addition of one or more other features, steps, operations, elements, components, projects, kinds, and / or groups. The terms "or", "and / or", "including at least one of the following" etc. used in this application can be interpreted as inclusive, or mean any one or any combination. For example, “comprising at least one of the following: A, B, C” means “any of the following: A; B; C; A and B; A and C; B and C; A and B and C”, and for another example, “A, B or C” or “A, B and / or C” means “any of the following: A; B; C; A and B; A and C; B and C; A and B and C”. An exception to this definition will only occur when a combination of elements, functions, steps or operations are inherently mutually exclusive in some manner.
[0038] It should be understood that, although the various steps in the flowchart in the embodiment of the present application are displayed in sequence according to the indication of the arrows, these steps are not necessarily performed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and it can be performed in other orders. Moreover, at least a portion of the steps in the figure may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and their execution order is not necessarily performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0039] As used herein, the words "if" and "if" may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0040] It should be noted that in this article, step codes such as S1 and S2 are used for the purpose of expressing the corresponding content more clearly and concisely, and do not constitute a substantial limitation on the order. When implementing the step, those skilled in the art may execute S2 first and then S1, etc., but these should all be within the scope of protection of this application.
[0041] SpringFactories is an SPI mechanism provided by spring. It reads the interface implementation class name configured in the project resource file META-INF / spring.factories file, and then reads these configuration files in the program and instantiates them.
[0042] In the technical platform, the Factories mechanism allows the use of technical components with little or no configuration, and only requires the introduction of our jar package in the service. The component statistics method of the present invention automatically reports component information when reading Factories and instantiating them in the program. The whole process has no code intrusion, and the service project has no perception. At the same time, the asynchronous processing mechanism is adopted, which does not affect the performance of the project.
[0043] In this embodiment, the statistics end and the display end together constitute the automatic statistics system of the technical platform component. Figure 1 As shown, the display end can include a reporting interface, a statistical query interface, and a data storage module. The main functions of the display end are: first, to provide a component reporting interface, receive registration information reported by the component and persist it to the database to facilitate subsequent data analysis; second, to provide display and analysis of component statistics related information. Display styles include but are not limited to reports, charts, etc. The component display example of the display end is shown in the figure below. Figure 2 shown.
[0044] The implementation of the display end is relatively simple. You can plan a separate service for processing, or you can rely on existing services for development. Because the display end has fewer functions, the present invention adopts the second method based on the existing user management service. The implementation steps are as follows:
[0045] (1) Define the component reporting information data structure. The reporting information includes: the project to which it belongs, the microservice to which it belongs, the component description, the component description, etc., which can be expanded;
[0046] (2) Write the code for processing the reported information data, including persistent storage of data in the database and statistical query;
[0047] (3) Write a reporting information receiving interface, which uses the HTTP RESTfull interface to receive reporting information, including but not limited to component name, description, and project name. The entire receiving and processing process uses asynchronous processing to reduce the time consumption of the statistics end.
[0048] The main function of the statistics end is to report the basic information of the component when the component is referenced and loaded. The statistics end adds references to the technical components in the main pom file of the project according to business needs. By adding references, you can use the relevant technical capabilities provided by the technical components.
[0049] First, please refer to Figure 3 , an embodiment of the present invention provides a flowchart of a component statistics reporting method, which is applied in a statistics terminal and is used to report basic information of a component when the component is referenced and loaded. The method may include:
[0050] S100: Read and load the contents of the spring.factories configuration file in the component package.
[0051] When the statistics end is started, it will scan all the component packages it references to check whether each component package contains the META-INF / spring.factories file. If it does, it will read and load the spring.factories file content of the component package. The spring.factories file configured in each component package will not affect the configuration of other components, nor will it be overwritten by other component configurations.
[0052] The spring.factories configuration file is pre-written and generated according to the actual situation of the component package, for example, the spring.factories configuration file is written according to the component function and the specific implementation code of the component. The spring.factories configuration file is part of the component and is written and generated during development. The spring.factories configuration file contains a list of classes that need to be instantiated when the component is loaded, such as the StatisticHandle class.
[0053] S200: Instantiate the StatisticHandle class in the pring.factories configuration file.
[0054] Specifically, instantiating the StatisticHandle class in the pring.factories configuration file may include:
[0055] S201: read the spring.factories configuration file, parse the configuration content in the spring.factories configuration file, and obtain the com.sca4cloud.sca.common.statistic.StatisticHandle processing class path;
[0056] S202: calling the parameterless constructor function of the StatisticHandle class through the Java reflection method, thereby obtaining an instance object of the StatisticHandle class and completing the instantiation process.
[0057] S300: calling the report initialization method defined in the StatisticHandle class to collect component configuration information.
[0058] The report initialization method collects and reports information including component information, such as component name, component reference coordinates, component description, etc., as well as information defined in StatisticProperties. The information defined in StatisticProperties is configured in the project configuration file on the statistics side, such as application.yml.
[0059] The function of the StatisticProperties class is to add configuration content to the project configuration file to enrich the information collected by the component. For example, the project department, project customer, project leader, etc. The specific content can be agreed upon with the project team. Its internal data structure uses Map, which can be flexibly configured, and there is no need to adjust the code to add configuration content later.
[0060] After the statistics end is started, the content configured in the project configuration file is filled into the StatisticProperties class. The report method can directly read the content in the StatisticProperties class and report it to the server together with the component's own information.
[0061] In this embodiment, the StatisticHandle class and the StatisticProperties class are separately encapsulated in a public jar package in the component package. Because the public data collection and reporting process does not involve specific technical components, encapsulation into a separate jar package is convenient for components that need statistical reporting to reference.
[0062] S400: Report the collected component configuration information to the display end.
[0063] In this embodiment, the display end data receiving interface is called through an asynchronous Http request to report the collected component configuration information to the display end. The asynchronous processing mechanism is adopted, which does not affect the performance of the project and reduces the time consumption of the statistical end.
[0064] Optionally, after reporting the collected component configuration information to the display end, the method provided in this embodiment further includes:
[0065] S500: receiving the processing status returned by the display end, and printing and outputting the processing status to a log file of the statistics end.
[0066] In summary, the present invention adopts a method of automatic registration and reporting of technical components, making component statistics simpler; the reported statistical information can be freely agreed and adjusted, making the statistical information richer and more flexible. Compared with the scanning method, the automatic registration and reporting method of the present invention has more accurate component statistical data.
[0067] Based on the same inventive concept, an embodiment of the present invention further provides an electronic device. Figure 4 As shown, the electronic device may include: one or more processors 101, one or more input devices 102, one or more output devices 103 and a memory 104, wherein the processors 101, input devices 102, output devices 103 and memory 104 are interconnected via a bus 105. The memory 104 is used to store a computer program, wherein the computer program includes program instructions, and the processor 101 is configured to call the program instructions to execute the method of the above-mentioned component statistics reporting method embodiment.
[0068] It should be understood that in the embodiment of the present invention, the processor 101 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0069] The input device 102 may include a keyboard, etc., and the output device 103 may include a display (LCD, etc.), a speaker, etc.
[0070] The memory 104 may include a read-only memory and a random access memory, and provides instructions and data to the processor 101. A portion of the memory 104 may also include a non-volatile random access memory. For example, the memory 104 may also store information on the device type.
[0071] In a specific implementation, the processor 101, input device 102, and output device 103 described in the embodiment of the present invention can execute the implementation method described in the embodiment of the component statistics method provided in the embodiment of the present invention, which will not be repeated here.
[0072] It should be noted that, for the specific workflow of the component statistics system, please refer to the aforementioned method embodiment part, which will not be repeated here.
[0073] Furthermore, an embodiment of the present invention also provides a readable storage medium storing a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the above-mentioned component statistics reporting method is implemented.
[0074] The computer-readable storage medium may be an internal storage unit of the background server described in the aforementioned embodiment, such as a hard disk or memory of the system. The computer-readable storage medium may also be an external storage device of the system, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. equipped on the system. Furthermore, the computer-readable storage medium may also include both an internal storage unit of the system and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by the system. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.
[0075] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0076] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0077] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0078] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0079] In the present application, the same or similar terminology concepts, technical solutions and / or application scenario descriptions are generally described in detail only the first time they appear. When they appear again later, they are generally not repeated for the sake of brevity. When understanding the technical solutions and other contents of the present application, for the same or similar terminology concepts, technical solutions and / or application scenario descriptions that are not described in detail later, reference can be made to the previous related detailed descriptions.
[0080] In the present application, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0081] The various technical features of the technical solution of the present application can be arbitrarily combined. In order to make the description concise, not all possible combinations of the various technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of the present application.
[0082] The above description is only a specific implementation mode of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or substitutions within the technical scope disclosed in the present application, and these modifications or substitutions should be included in the protection scope of the present application.
Claims
1. A component statistics reporting method, applied to a statistics terminal, characterized in that: include: Read and load the contents of the spring.factories configuration file in the component package; Instantiate the StatisticHandle class in the spring.factories configuration file; Call the report initialization method defined in the StatisticHandle class to collect component configuration information; Report the collected component configuration information to the display end; Instantiate the StatisticHandle class in the pring.factories configuration file, including: Read the spring.factories configuration file, parse the configuration content in the spring.factories configuration file, and obtain the com.sca4cloud.sca.common.statistic.StatisticHandle processing class path; The parameterless constructor function of the StatisticHandle class is called through the Java reflection method to obtain the instance object of the StatisticHandle class and complete the instantiation process.
2. A component statistics reporting method as claimed in claim 1, characterized in that: The spring.factories configuration file is pre-written and generated according to the actual situation of the component package; The spring.factories configuration file contains a list of classes that need to be instantiated when the component is loaded.
3. A component statistics reporting method as claimed in claim 1, characterized in that: The component configuration information includes component information and information defined in the StatisticProperties class, which is a predefined statistical parameter configuration class.
4. A component statistics reporting method as claimed in claim 3, characterized in that: The information defined in the StatisticProperties class is configured in the project configuration file of the statistics end.
5. A component statistics reporting method as claimed in claim 3, characterized in that: The StatisticHandle class and the StatisticProperties class are separately encapsulated in a public jar package in the component package.
6. A component statistics reporting method as claimed in claim 1, characterized in that: The display end data receiving interface is called through an asynchronous Http request to report the collected component configuration information to the display end.
7. A component statistics reporting method as claimed in claim 1, characterized in that: The method further comprises: Receive the processing status returned by the display end, and print the processing status to the statistics end log file.
8. An electronic device, characterized in that: The electronic device includes a processor, an input device, an output device and a memory, which are interconnected, wherein the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to call the program instructions to execute the method steps described in any one of claims 1-7.
9. A computer-readable storage medium storing a computer program, wherein the computer program includes program instructions, characterized in that: When the program instructions are executed by a processor, the method steps according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method and system for transferring request ID based on spring interceptor
CN107818024A
Spring Boot-based data visualization method and device and storage medium
CN113986205A