A log compression method, a log search method and related devices
By performing two compression operations on the logs and establishing an inverted index, the problem of low log compression rate was solved, achieving adaptive compression and efficient full-text search for the new log format.
Patent Information
- Application Number
- CN202310310640.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-27
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2043-03-27
AI Technical Summary
Existing log compression methods have low compression rates and cannot effectively adapt to new log formats, leading to increased storage and transmission pressure.
The first log template in the template library is used to compress the log to be compressed for the first time, and repeated strings are extracted to generate the first log template. The generated template is then used for the second compression, and an inverted index is built to achieve full-text search functionality.
It improves log compression rate, adapts to new log formats, reduces storage space usage, and supports efficient full-text search functionality.
Smart Images

Figure CN116302834B_ABST
Abstract
Description
Technical Field
[0001] The embodiments described in this specification relate to the field of computer application technology, specifically to log compression technology in the field of computer application technology, and more specifically to a log compression method, a log search method, and related apparatus. Background Technology
[0002] A log is a file used to record system or application operation events. Logs play an important role in processing historical data, locating problems, and understanding system activity. During the operation of network devices, systems, and service programs, an event record called a log is generated. A single line of data in a log can record a description of the relevant operation, such as the date, time, user, and action. Therefore, it is necessary to store logs to meet the need for viewing logs when necessary.
[0003] Traditional techniques typically involve directly storing or transmitting raw logs. However, log volumes are often substantial, and directly storing or transmitting raw logs requires significant memory and network resources. Therefore, it's necessary to compress the logs before storage or transmission. Current log compression methods have low compression rates, increasing storage and transmission overhead. Summary of the Invention
[0004] This specification provides a log compression method, a log search method, and related apparatus through various embodiments to address the problem of low log compression rates in related technologies.
[0005] Firstly, one embodiment of this specification provides a log compression method, comprising: Obtain multiple logs to be compressed; The first log template is used to perform a first compression on multiple logs to be compressed to obtain multiple first compressed logs; the first log template includes a string identifier corresponding to a string; the first log template is stored in a template library; A first log template is generated for the duplicate strings in the plurality of first compressed logs; the duplicate strings include the same string that exists in the plurality of first compressed logs; The first compressed log is compressed a second time based on the generated first log template to obtain a compressed log.
[0006] Secondly, one embodiment of this specification provides a log compression apparatus, comprising: The log acquisition module is used to acquire multiple logs to be compressed; A first compression module is used to perform a first compression on a plurality of logs to be compressed using a first log template to obtain a plurality of first compressed logs; the first log template includes a string identifier corresponding to a string; the first log template is stored in a template library; The template generation module is used to generate a first log template for repeated strings in the plurality of first compressed logs; the repeated strings include the same strings that exist in the plurality of first compressed logs; The second compression module is used to perform a second compression on the first compressed log based on the generated first log template to obtain a compressed log.
[0007] Thirdly, one embodiment of this specification provides a log search method, including: In response to a query command, determine the log content corresponding to the query command in the compressed log; The determined log content is returned as a response result to the party that requested the query instruction; The query instruction includes a full-text query instruction, which includes a query string; An inverted index is pre-built, comprising a first index and a second index. The first index represents the correspondence between words in the log and the identifier of the first log template; the second index represents the correspondence between words in the log and the identifier of the line containing the log content; the identifier of the line containing the log content is a location identifier representing the line containing a log content. In response to the query command, the log content corresponding to the query command is determined in the compressed log: If the query instruction includes the full-text query instruction, then based on the first index, the words in the query string are replaced with the first log template identifier to obtain a preprocessed string; Based on the second index, the compressed log is queried to obtain the row identifier of at least one log content corresponding to the preprocessed string; Based on the obtained line identifier of the log content, determine the target line content in the compressed log corresponding to the line identifier of the log content. Based on the first log template, the first log template in the target line content is restored to the word corresponding to the first log template identifier, so as to obtain the log content corresponding to the query instruction.
[0008] Fourthly, one embodiment of this specification provides an electronic device, including: a processor and a memory; The memory is connected to the processor and is used to store computer programs; The processor is configured to implement the log compression method or the log search method described above by running a computer program stored in the memory.
[0009] Fifthly, one embodiment of this specification provides a storage medium storing a computer program that, when executed by a processor, implements the log compression method or the log search method described above.
[0010] Sixthly, one embodiment of this specification provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium; a processor of the computer device reads the computer instructions from the computer-readable storage medium, and when the processor executes the computer instructions, it implements the steps of the log compression method or the log search method described above.
[0011] The multiple implementation methods provided in this specification solve the problem of low log compression rate caused by the fact that the existing first log templates in the template library cannot match the log to be compressed well. After the first compression of the log to be compressed is performed using the first log template in the template library, if there are still duplicate strings in multiple first log templates, a first log template is generated based on the duplicate strings, the template library is updated, and the first compressed log is compressed a second time based on the generated first log template to obtain compressed log. Attached Figure Description
[0012] Figure 1 A schematic diagram illustrating possible application scenarios for the log compression method and log search method provided in one embodiment of this specification; Figure 2 A flowchart illustrating a log compression method provided for one embodiment of this specification; Figure 3 A schematic diagram illustrating the execution process of a log compression method provided for one embodiment of this specification; Figure 4 A flowchart illustrating another log compression method provided as one embodiment of this specification; Figure 5 This specification provides a schematic diagram of a process for sliding segmentation of log content to be compressed based on a sliding window, as one embodiment of the specification. Figure 6 A flowchart illustrating a log search method provided for one embodiment of this specification; Figure 7 A schematic diagram of a log compression device provided for one embodiment of this specification; Figure 8 This is a schematic diagram of an electronic device provided for one embodiment of this specification. Detailed Implementation
[0013] Unless otherwise defined, the technical or scientific terms used in the embodiments of this specification shall have the ordinary meaning understood by one of ordinary skill in the art to which this specification pertains. The terms "first," "second," and similar terms used in the embodiments of this specification do not indicate any order, quantity, or importance, but are merely used to avoid confusion of constituent elements.
[0014] Unless the context otherwise requires, throughout this specification, "a plurality of" means "at least two," and "including" is interpreted as open-ended or encompassing, that is, "including, but not limited to." In the description of this specification, terms such as "one embodiment," "some embodiments," "exemplary embodiment," "example," "specific example," or "some examples" are intended to indicate that a particular feature, structure, material, or characteristic associated with that embodiment or example is included in at least one embodiment or example of this specification. The illustrative representations of the above terms do not necessarily refer to the same embodiment or example.
[0015] The technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this specification, and not all embodiments. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0016] Overview As described in the background section, network devices, systems, and service programs generate event records called logs during operation. A single log line can record the date, time, user, and action description. Through these logs, we can trace the source of errors and analyze their causes. On a single computer, the operating system generates various log files daily, such as application logs, security logs, system logs, and DNS (Domain Name System) server logs. In a data center or other equipment cluster consisting of multiple computers and network devices, massive amounts of logs are generated every hour. These massive log volumes occupy significant storage space, resulting in wasted resources. Therefore, it is necessary to efficiently compress and store these massive log volumes.
[0017] In related technologies, most log compression methods are template-based. This involves replacing the corresponding string in the log with a shorter encoded element based on the mapping between stored strings and encoded elements, thereby reducing the storage space occupied by the log and achieving compression. However, this method has a drawback: when a new log format emerges, the existing template (such as encoded elements) cannot adapt to the new format, resulting in poor deduplication and a low compression rate.
[0018] To address this issue, the inventors discovered through long-term research that multiple logs generated within a certain period can be compressed by first replacing existing templates in a template library. Then, duplicate fields from the compressed logs are extracted to generate new templates, and a second compression step is performed based on these new templates. This process extracts duplicate fields that cannot be matched by existing templates in the template library, making the log compression method applicable to the compression requirements of new log types, improving the compression ratio, and resulting in compressed logs occupying less storage space.
[0019] Furthermore, the inventors discovered through research that existing log compression schemes do not consider full-text search scenarios. Full-text search, or the ability to locate a given string of characters within a log file, has become a fundamental requirement for log search applications. The inventors implemented full-text search functionality based on an input string by creating inverted indexes for both the compressed log content and the log template.
[0020] Based on the above concept, embodiments of this specification provide a log compression method and a log search method. The following will exemplarily describe the possible application scenarios and feasible implementation methods of the log compression method provided in the embodiments of this specification with reference to the accompanying drawings.
[0021] Scenario Example refer to Figure 1 , Figure 1The illustration shows a possible application scenario for the log compression and log search methods, in which client 12 communicates with server 11 via a network. Storage device 13 can be integrated onto server 11 or placed on a cloud or other server. Server 11 can be used alone to execute the log compression and / or log search methods provided in the embodiments of this specification. For example, server 11 can obtain logs generated by server 11 or client 12, compress the logs according to the log compression method provided in the embodiments of this specification, and store the compressed logs in storage device 13. Server 11 can also obtain query instructions transmitted by client 12, execute the log search method provided in the embodiments of this specification according to the query instructions, obtain search results from the compressed logs stored in storage device 13, and return them to client 12.
[0022] The aforementioned client 12, server 11, and storage device 13 can collectively constitute a big data platform 10. In some embodiments, the aforementioned client 12, server 11, and storage device 13 can collectively constitute a smart transportation platform, a government service platform, etc. This specification does not limit the application scenarios to which the log compression method and log search method provided in the embodiments of this specification may be applicable; the specific application depends on the actual situation.
[0023] The aforementioned client 12 can be a desktop computer, tablet computer, laptop computer, smartphone, digital assistant, smart wearable device, shopping guide terminal, television, smart speaker, microphone, etc. Among these, smart wearable devices include, but are not limited to, smart bracelets, smartwatches, smart glasses, smart helmets, smart necklaces, etc. Alternatively, client 12 can also be software capable of running on the aforementioned electronic device. Server 11 can be an electronic device with a certain computing power. It can have a network communication module, processor, and memory, etc. Of course, server 11 can also refer to software running on the aforementioned electronic device. Server 11 can also be a distributed server, which can be a system with multiple processors, memory, network communication modules, etc., operating collaboratively. Alternatively, server 11 can also be a server cluster formed by several servers. Alternatively, with the development of science and technology, server 11 can also be a new technical means capable of realizing the corresponding functions of the embodiments described in the specification. For example, it can be a new form of "server" based on quantum computing.
[0024] Example method One embodiment of this specification provides a log compression method. The log compression method can be applied to, for example... Figure 1 Server 11 shown, as Figure 2 As shown, the log compression method may include the following steps: S201: Obtain multiple logs to be compressed.
[0025] The logs to be compressed can refer to various logs generated by the client or server. The multiple logs to be compressed obtained in step S201 can be logs generated within the most recent time window. These logs to be compressed can be cached first for later reading during compression. The length of this time window can be 3 minutes, 5 minutes, 10 minutes, etc. Generally, the size of this time window can be determined by the server's caching capacity. This specification does not limit the specific value of the time window.
[0026] S202: The first log template is used to perform a first compression on the multiple logs to be compressed to obtain multiple first compressed logs; the first log template includes a string identifier corresponding to a string; the first log template is stored in a template library.
[0027] The template library can be a database stored on the server containing multiple first log templates. First log templates can include templates used to replace specific strings (the template can specifically be a string identifier). The logs to be compressed may contain a large number of repetitive strings; these repetitive strings can be replaced using a shorter first log template. For example, logs to be compressed on the same day may all contain the same date characters (e.g., 2023-03-16). For these date characters, a uniform template (e.g., ${1}) can be used to replace them to compress the number of log characters and reduce the memory size occupied by the logs. In this example, the string identifier ${1} corresponds to the string 2023-03-16. Similarly, in other logs to be compressed, the string identifier ${1} can replace the string 2023-03-16.
[0028] S203: Generate a first log template for the duplicate strings in the plurality of first compressed logs; the duplicate strings include the same strings that exist in the plurality of first compressed logs.
[0029] After performing the first compression of the log to be compressed using the first log template in the template library, duplicate strings can be extracted from multiple first compressed logs, and a new first log template can be generated based on the extracted duplicate strings. In this way, the new first log template can correspond to the duplicate strings that were not compressed in the first compression, laying the foundation for the second compression using the newly generated first log template.
[0030] For example, suppose the log to be compressed contains a line of log data: "2023-02-03 20:32 [netty-worker-pool-28] INFO host 10.10.0.1 has sent 40 bytes message to host10.20.0.1". Before step S203, the first log template in the template library can include "${1}" and "${2}", where "${1}" corresponds to the string "2023-02-03" and "${2}" corresponds to the string "[netty-worker-pool-28]INFO host 10.10.0.1 has sent". After the first log compression, this line of log data is compressed to "${1}20:32 ${2} 40 bytes message to host 10.20.0.1". However, a comparison with duplicate strings in other first compressed logs reveals that "bytes message to host" also exists in multiple first compressed logs. Therefore, a new first log template can be generated: "${3}" corresponds to the string "bytes message to host".
[0031] In one implementation, whether the same string existing in multiple first compressed logs can be used as a duplicate string to generate a first log template depends on the generation rules of the first log template. For example, if the string "20:32" in a log line in the above example exists in N first compressed logs, a new first log template will only be generated based on this string if N is greater than a set threshold. If N is less than or equal to the set threshold, a new first log template will not be generated based on this string.
[0032] Of course, besides using the number of times the string coexists with the first compressed log as a factor in determining whether to generate the first log template, weights can also be set based on factors such as the number of characters in the string and the number of times the string coexists with the first compressed log. The weighted result of these factors will determine whether to generate the first log template. This specification does not impose any limitations on this; the specific approach will depend on the actual situation.
[0033] S204: Based on the generated first log template, the first compressed log is compressed a second time to obtain a compressed log.
[0034] In this embodiment, after a new first log template is generated, the first compressed log is compressed a second time based on the generated first log template, which can improve the compression ratio of the final compressed log and solve the problem of low compression ratio of traditional log compression methods for new log formats.
[0035] Taking the above example again, such as Figure 3 As shown, after generating a new first log template: "${3}" corresponding to the string "bytes message to host", the data "${1} 20:32 ${2} 40 bytes message to host 10.20.0.1" in the compressed first log can be compressed a second time based on the new first log template. Finally, this line of data can be stored as "${1} 20:32 ${2} 40 ${3} 10.20.0.1". In this way, the problem that the existing first log template in the template library cannot adapt to the repeated strings in the new log format can be solved, and the repeated strings in the first compressed log can be compressed a second time, thus solving the problem of low compression rate mentioned above.
[0036] In some implementations, the first log template generated in step S203 can be stored in a template library to improve the adaptability of the template library to various types of logs to be compressed, improve the compression rate of the logs to be compressed during the first compression in step S202, and avoid the situation of repeatedly generating the first log template in step S203, thereby improving the execution efficiency of the method.
[0037] Using the example above, after a new first log template is generated in step S203, corresponding to the string "bytes message to host" for "${3}", this first log template can be stored in the template library. Thus, when encountering a line of data such as "2023-02-03 20:35 [netty-worker-pool-28] INFO host 10.10.0.1 has sent 80 bytes message to host 10.20.0.2", the first compression in step S202 will yield the following compressed result: "${1} 20:35 ${2} 80 ${3} 10.20.0.2". This eliminates the need to repeatedly generate the template in step S203, thereby improving the method's execution efficiency.
[0038] To improve the applicability of the first log template generation rules to log compression scenarios, in one embodiment of this specification, generating the first log template for duplicate strings in the plurality of first compressed logs includes: The log content of multiple first compressed logs is segmented into words to divide the log content of the first compressed logs into multiple strings; Using a local matching algorithm, duplicate strings are extracted from multiple first compressed logs after word segmentation. In the penalty scoring rule of the local matching algorithm, the weight of the matching string is positively correlated with the length of the matching string. The matching string includes the same string that exists in at least two of the first compressed logs. A first log template is generated based on the repeated string.
[0039] Local matching algorithms are a type of sequence alignment algorithm. Unlike global alignment algorithms (such as the Needleman-Wunsch algorithm), local matching algorithms perform local comparisons. When applied to log compression, local matching algorithms are used to find duplicate strings between two or more log entries. Commonly used local matching algorithms include the Smith-Waterman Algorithm.
[0040] In this implementation, the traditional local matching algorithm has been optimized to make it more suitable for string matching in this scheme. The longer the string, the greater the benefit of using it as a template for compression. For example, as mentioned earlier, the benefit of compressing "[netty-worker-pool-28] INFO host 10.10.0.1 hassent" using the first log template is significantly higher than the benefit of compressing "has" using the first log template. If "has" is compressed using the first log template, the compression benefit may be very small, but it will consume certain computing resources to perform the compression step.
[0041] Therefore, in this embodiment, the penalty rule of the local matching algorithm sets the weight of the matching string to be positively correlated with the length of the matching string. Specifically, in one embodiment of this specification, the weight of the matching string can be equal to the length of the matching string. Thus, the first log template generated based on the generation method of the first log template provided in this embodiment tends to be generated based on longer strings, while shorter strings are discarded, thereby improving log compression efficiency.
[0042] To avoid generating a first log template based on a small number of repeated strings, in one embodiment of this specification, generating the first log template based on the repeated strings includes: If the number of words in the repeating string is greater than N, then the repeating string is divided into multiple substrings, and the number of words in the substrings is less than or equal to N; N is an integer greater than 1. When the number of characters in the substring exceeds a preset character count threshold, a correspondence between the substring and the string identifier is established to generate the first log template.
[0043] In this embodiment, in addition to introducing a restriction that the weight of the matching string is positively correlated with the length of the matching string in the local matching algorithm, a preset character number threshold is also set when generating the first log template. This avoids the situation where a few repeated strings are generated as the first log template, thereby improving the compression benefits when compressing logs.
[0044] To meet the need for searching compressed logs, in one embodiment of this specification, reference is made to... Figure 4 The log compression method further includes: S401: In response to a query command, determine the log content corresponding to the query command in the compressed log; S402: Return the determined log content as a response result to the requester of the query instruction.
[0045] In this embodiment, a response mechanism for query commands is established to meet the log content search requirements of query commands and to satisfy the user's search requirements for compressed logs.
[0046] Searching (querying) compressed logs can be divided into direct search and full-text search. In one embodiment of this specification, a feasible implementation of direct search is provided. The query instruction includes a direct query instruction, which includes the row identifier of the log content. The row identifier of the log content is a location identifier that represents the row of a log content. In response to the query command, the log content corresponding to the query command is determined in the compressed log: If the query instruction includes the direct query instruction, then the target line content is determined in the compressed log corresponding to the line identifier of the log content, based on the line identifier of the log content. Based on the first log template, the first log template in the target row content is restored to the word corresponding to the first log template identifier, so as to obtain the log content corresponding to the query instruction.
[0047] When performing a direct search, assuming the log content pointed to by the direct query command is: "${1} host 10.10.0.1 ${2} 40 ${3} 10.20.0.1", the first log template includes: ${1}->2023-02-03 20:32 [netty-worker-pool-28] INFO; ${2}->has sent; ${3}->bytes message to host.
[0048] After finding the above log line content according to the direct query command, the log line content is restored to the corresponding words according to the first log template mentioned above, and the following is obtained: "2023-02-03 20:32 [netty-worker-pool-28] INFOhost 10.10.0.1 has sent 40 bytes message to host 10.20.0.1".
[0049] Regarding the implementation of full-text search, in one embodiment of this specification, the search instruction includes a full-text search instruction, which includes a search string; An inverted index is pre-built, which includes a first index and a second index. The first index is used to represent the correspondence between words in the log and the first log template identifier; the second index is used to represent the correspondence between words in the log and the line identifier of the log content; the line identifier of the log content is a positioning identifier representing the line where a log content is located. In response to the query command, the log content corresponding to the query command is determined in the compressed log: If the query instruction includes the full-text query instruction, then based on the first index, the words in the query string are replaced with the first log template identifier to obtain a preprocessed string; Based on the second index, the compressed log is queried to obtain the row identifier of at least one log content corresponding to the preprocessed string; Based on the obtained line identifier of the log content, determine the target line content in the compressed log corresponding to the line identifier of the log content. Based on the first log template, the first log template in the target line content is restored to the word corresponding to the first log template identifier, so as to obtain the log content corresponding to the query instruction.
[0050] For example, when the first log template is generated, its content can be tokenized and an inverted index can be created. For instance, taking the first log template as "${3}->bytes message to host" (where "->" indicates correspondence), and assuming the first log template identifier is ${3}, the following first index will be created: bytes->${3}; message->${3}; to->${3}; host->${3}.
[0051] It is easy to understand that the first index can be called the template content index, which is used to indicate the template in which the word is located.
[0052] When compressing log storage, a second index can be created. Taking the log content "${1} 20:32 ${2} 40 ${3}10.20.0.1" as an example, assuming the line identifier of this log content is 1, the following second index will be created: ${1}->1; 20:32->1; ${2}->1; 40->1; ${3}->1; 10.20.0.1->1.
[0053] The above example makes it easy to understand that the second index is used to indicate which line in the log the content belongs to.
[0054] During the full-text search process, assuming the user's input query string is "INFOand bytes and 10.20.0.1", the words in the query string are replaced with the first log template identifier based on the first index to obtain the preprocessed string. The first index reveals that the words "INFO" and "bytes" exist in the corresponding strings of the first log templates ${1} and ${3}, respectively. Therefore, these two words in the query string are replaced with their corresponding first log templates to obtain the preprocessed string: ${1} and ${3} and 10.20.0.1. The second index identifies at least one log content line identifier corresponding to the preprocessed string. Based on this log content line identifier, the target line content is determined in the compressed log corresponding to that line identifier. Assuming the target line content is: ${1} host 10.10.0.1 ${2} 40 ${3} 10.20.0.1. Finally, the first log template of the target line content is restored to its corresponding string, and the log content corresponding to the query instruction is obtained as "2023-02-0320:32 [netty-worker-pool-28] INFO host 10.10.0.1 has sent 40 bytes message to host 10.20.0.1", thus realizing full-text search.
[0055] The full-text search and direct search functions for compressed logs implemented in the above manner are simple to implement and help improve search response efficiency.
[0056] The inventors discovered through studying the composition of logs that logs typically include a large amount of stack output content (also known as trace information) used to represent the execution order of methods in the code. This content is usually quite large and has a relatively uniform format and content. If the above-mentioned template replacement scheme is used for compression, it may lead to the problem of consuming a lot of computing power when compressing this part of the content.
[0057] To address this issue, in one embodiment of this specification, the template library further includes: a second log template, the second log template including a stack identifier corresponding to the stack output content; the stack output content is used to characterize information representing the execution order of methods in the code; Before performing the first compression of the multiple logs to be compressed using the first log template, the method further includes: S501: Determine the stack output content in the log to be compressed based on a preset regular expression; S502: If the second log template includes a stack identifier corresponding to the stack output content determined from the log to be compressed, then the stack output content in the log to be compressed is replaced with the stack identifier; S503: If the second log template does not include a stack identifier corresponding to the stack output content determined from the log to be compressed, then a new stack identifier is assigned to the determined stack output content, and a new second log template is generated based on the determined stack output content and stack identifier. Based on the generated second log template, the stack output content in the log to be compressed is replaced with the corresponding stack identifier.
[0058] In this embodiment, the stack output content in the log to be compressed is determined using a preset regular expression, which is simple, easy to implement, and consumes low computational power. Furthermore, in step S503, when the determined stack output content does not correspond to a second log template, a new stack identifier is assigned to the determined stack output content and compressed. A new second log template is then generated based on the determined stack output content and the stack identifier. In this way, new stack output content can also be compressed using a second log template, improving the log compression method's adaptability to new log formats and content, and increasing the log compression rate of this method.
[0059] Similar to the newly generated first log template, the newly generated second log template can also be stored in the template library, providing a usable second log template for the stack output content of subsequent identical logs to be compressed.
[0060] To improve compression efficiency, in one embodiment of this specification, a feasible compression method is provided, wherein, optionally, the number of words included in the first log template is less than or equal to N; N is an integer greater than 1. The method for compressing the log to be compressed includes: Using N words as a window, the log to be compressed is divided into multiple strings by sliding segmentation, so that the log content of the log to be compressed is divided into multiple strings, wherein the number of words in the strings is less than or equal to N; The first log template is used to match multiple strings in the log to be compressed, and the first log template is used to replace the strings in the log to be compressed that match the first log target.
[0061] In this embodiment, such as Figure 5 As shown, assuming the log content to be compressed is "2023-02-03 20:32 [netty-worker-pool-28] INFO host 10.10.0.1 has sent 40 bytes message to host10.20.0.1", the first log template is: ${1}->2023-02-03 20:32 [netty-worker-pool-28] INFO. The value of N is 3, meaning the number of words in the first log template is less than or equal to 3.
[0062] Using N words as a window, the log to be compressed is split using a sliding mechanism to obtain the following twelve strings: 1: 2023-02-03 20:32 [netty-worker-pool-28]; 2: 20:32 [netty-worker-pool-28] INFO; 3: [netty-worker-pool-28] INFO host; 4: INFO host 10.10.0.1; 5: host 10.10.0.1 has; 6: 10.10.0.1 has sent; 7: has sent 40; 8: sent 40 bytes; 9: 40 bytes message; 10 bytes message to; 11: Message to host; 12: to host 10.20.0.1.
[0063] By matching the first log template with multiple strings in the log to be compressed, it was found that the first log template, ${1}, matches the eleventh string. Therefore, after replacing the string in the log to be compressed that matches the first log target with the first log template, the result is as follows: 2023-02-03 20:32 [netty-worker-pool-28] INFO host 10.10.0.1 has sent 40 bytes ${1} 10.20.0.1.
[0064] Compressing the logs in the above manner can effectively improve the matching accuracy between the first log template and the corresponding strings in the logs to be compressed.
[0065] To improve log compression efficiency, in one embodiment of this specification, the step of matching the first log template with multiple strings in the log to be compressed includes: The steps of matching the first log template with multiple strings in the log to be compressed are performed in parallel.
[0066] Since there are usually multiple first log templates in the template library, and each matching of the first log template with the log to be compressed is independent, each matching process can be executed in parallel as an independent unit. Parallel execution methods include, but are not limited to: multi-threaded execution, multi-process execution, and execution based on big data services.
[0067] Based on the same concept, this specification also provides a log search method, such as... Figure 6 As shown, it includes: S601: In response to a query command, determine the log content corresponding to the query command in the compressed log; S602: Return the determined log content as a response result to the requester of the query instruction; The query instruction includes a full-text query instruction, which includes a query string; An inverted index is pre-built, which includes a first index and a second index. The first index is used to represent the correspondence between words in the log and the first log template identifier; the second index is used to represent the correspondence between words in the log and the line identifier of the log content; the line identifier of the log content is a positioning identifier representing the line where a log content is located. Step S601 includes: If the query instruction includes the full-text query instruction, then based on the first index, the words in the query string are replaced with the first log template identifier to obtain a preprocessed string; Based on the second index, the compressed log is queried to obtain the row identifier of at least one log content corresponding to the preprocessed string; Based on the obtained line identifier of the log content, determine the target line content in the compressed log corresponding to the line identifier of the log content; Based on the first log template, the first log template in the target line content is restored to the word corresponding to the first log template identifier, so as to obtain the log content corresponding to the query instruction.
[0068] For details on the specific process of obtaining compressed logs, please refer to the relevant limitations in the log compression method described above. The specific feasible execution process and beneficial effects of each step can be found in the relevant descriptions above; this manual will not repeat them here.
[0069] Example devices, electronic devices, storage media, and software One embodiment of this specification also provides a log compression device, such as... Figure 7 As shown, the log compression device may include: Log acquisition module 701 is used to acquire multiple logs to be compressed. The first compression module 702 is used to perform a first compression on a plurality of logs to be compressed using a first log template to obtain a plurality of first compressed logs; the first log template includes a string identifier corresponding to a string; the first log template is stored in a template library; The template generation module 703 is used to generate a first log template for repeated strings in the plurality of first compressed logs; the repeated strings include the same strings that exist in the plurality of first compressed logs. The second compression module 704 is used to perform a second compression on the first compressed log based on the generated first log template to obtain a compressed log.
[0070] The computing resource management device provided in this embodiment belongs to the same application concept as the log compression method or log search method provided in the above embodiments of this specification. It can execute the log compression method or log search method provided in any of the above embodiments of this specification, and has the corresponding functional modules and beneficial effects for executing the log compression method or log search method. Technical details not described in detail in this embodiment can be found in the specific processing content of the log compression method or log search method provided in the above embodiments of this specification, and will not be repeated here.
[0071] Another embodiment of this specification also proposes a computing device, see [link to documentation]. Figure 8 As shown, an exemplary embodiment of this specification also provides a computing device, including: a memory and a processor, the memory storing a computer program, the processor executing the computer program to perform the steps in the log compression method or log search method according to various embodiments of this specification described above.
[0072] The internal structure of the computing device can be as follows: Figure 8 As shown, the computing device includes a processor, memory, network interface, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory of the central control device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computing device is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it follows the steps of the log compression method or log search method according to various embodiments of this specification as described in the above embodiments.
[0073] The processor may include the main processor, as well as baseband chips, modems, etc.
[0074] The memory stores a computer program that executes the technical solution of this invention, and may also store an operating system and other key programs. Specifically, the computer program may include program code, which includes computer operation instructions. More specifically, the memory may include read-only memory (ROM), other types of static storage devices capable of storing static information and instructions, random access memory (RAM), other types of dynamic storage devices capable of storing information and instructions, disk storage, flash memory, etc.
[0075] The processor can be a general-purpose processor, such as a general-purpose processor (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of the program of the present invention. It can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0076] Input devices may include devices that receive data and information input by the user, such as keyboards, mice, cameras, scanners, light pens, voice input devices, touch screens, pedometers, or gravity sensors.
[0077] Output devices may include devices that allow information to be output to the user, such as displays, printers, speakers, etc.
[0078] The communication interface may include any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.
[0079] The processor executes the computer program stored in the memory and calls other devices, which can be used to implement the various steps of any of the log compression methods or log search methods provided in the above embodiments of this application.
[0080] The computing device may also include a display component and a voice component. The display component may be a liquid crystal display screen or an e-ink display screen. The input device of the computing device may be a touch layer covering the display component, or a button, trackball or touchpad set on the casing of the computing device, or an external keyboard, touchpad or mouse, etc.
[0081] Those skilled in the art will understand that Figure 8 The structures shown are merely block diagrams of some structures related to the solutions in this specification and do not constitute a limitation on the computing devices on which the solutions in this specification are applied. Specific computing devices may include more or fewer components than those shown in the figures, or combine certain components, or have different component arrangements.
[0082] In addition to the methods and devices described above, the log compression method or log search method provided in the embodiments of this specification can also be a computer program product, which includes a computer program that, when run by a processor, causes the processor to perform the steps in the log compression method or log search method according to various embodiments of this specification as described in the "Exemplary Methods" section above.
[0083] The computer program product described herein can be written in any combination of one or more programming languages to perform the operations of the embodiments described herein. These programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0084] Furthermore, embodiments of this specification also provide a computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor of the steps in the log compression method or log search method according to various embodiments of this specification as described in the "Example Methods" section above.
[0085] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0086] It is understood that the specific examples in this document are only intended to help those skilled in the art better understand the implementation methods of this specification, and are not intended to limit the scope of this specification.
[0087] It is understood that in the various embodiments described in this specification, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments described in this specification.
[0088] It is understood that the various implementation methods described in this specification can be implemented individually or in combination, and the implementation methods in this specification are not limited in this respect.
[0089] Unless otherwise stated, all technical and scientific terms used in the embodiments of this specification have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of this specification. The term "and / or" as used in this specification includes any and all combinations of one or more of the associated listed items. The singular forms "a," "the," and "the" as used in the embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.
[0090] It is understood that the processor in the embodiments of this specification can be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method embodiments can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this specification. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this specification can be directly implemented by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above methods.
[0091] It is understood that the memory in the embodiments of this specification may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may be random access memory (RAM). It should be noted that the memory in the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0092] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software 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 beyond the scope of this specification.
[0093] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the aforementioned method implementations, and will not be repeated here.
[0094] In the several embodiments provided in this specification, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0095] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0096] In addition, the functional units in the various embodiments of this specification can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0097] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of this specification, in essence, or the parts that contribute to the prior art, or parts of the technical solutions, can be embodied in the form of software products. These computer software products are stored in a storage medium and include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this specification. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0098] The above description is merely a specific embodiment of this specification, but the scope of protection of this specification is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this specification should be included within the scope of protection of this specification. Therefore, the scope of protection of this specification should be determined by the scope of the claims.
Claims
1. A log compression method, characterized in that, include: Obtain multiple logs to be compressed; The first log template is used to perform a first compression on the multiple logs to be compressed to obtain multiple first compressed logs; The first log template includes a string identifier corresponding to the string; The first log template is stored in the template library; A first log template is generated for the duplicate strings in the plurality of first compressed logs; the duplicate strings include the same string that exists in the plurality of first compressed logs; The first compressed log is compressed a second time based on the generated first log template to obtain a compressed log. In response to a query command, the log content corresponding to the query command is determined in the compressed log; the query command includes a full-text query command, which includes a query string; The determined log content is returned as a response result to the party that requested the query instruction; The query instruction includes a full-text query instruction, which includes a query string; An inverted index is pre-built, which includes a first index and a second index. The first index is used to represent the correspondence between words in the log and the first log template identifier; the second index is used to represent the correspondence between words in the log and the line identifier of the log content; the line identifier of the log content is a positioning identifier representing the line where a log content is located. The step of responding to a query command by determining the log content corresponding to the query command in the compressed log includes: If the query instruction includes the full-text query instruction, then based on the first index, the words in the query string are replaced with the first log template identifier to obtain a preprocessed string; Based on the second index, the compressed log is queried to obtain the row identifier of at least one log content corresponding to the preprocessed string; Based on the obtained line identifier of the log content, determine the target line content in the compressed log corresponding to the line identifier of the log content; Based on the first log template, the first log template in the target line content is restored to the word corresponding to the first log template identifier, so as to obtain the log content corresponding to the query instruction.
2. The method according to claim 1, characterized in that, The step of generating a first log template for duplicate strings in the plurality of first compressed logs includes: The log content of multiple first compressed logs is segmented into words to divide the log content of the first compressed logs into multiple strings; Using a local matching algorithm, duplicate strings are extracted from multiple first compressed logs after word segmentation. In the penalty scoring rule of the local matching algorithm, the weight of the matching string is positively correlated with the length of the matching string. The matching string includes the same string that exists in at least two of the first compressed logs. A first log template is generated based on the repeated string.
3. The method according to claim 2, characterized in that, The step of generating the first log template based on the repeated string includes: If the number of words in the repeating string is greater than N, then the repeating string is divided into multiple substrings, and the number of words in the substrings is less than or equal to N; N is an integer greater than 1. When the number of characters in the substring exceeds a preset character count threshold, a correspondence between the substring and the string identifier is established to generate the first log template.
4. The method according to claim 1, characterized in that, The query instruction includes a direct query instruction, which includes an identifier of the line containing the log content; the identifier of the line containing the log content is a location identifier representing the line containing a log content. The step of determining the log content corresponding to the query command in the compressed log in response to the query command includes: If the query instruction includes the direct query instruction, then the target line content is determined in the compressed log corresponding to the line identifier of the log content, based on the line identifier of the log content. Based on the first log template, the first log template in the target row content is restored to the word corresponding to the first log template identifier, so as to obtain the log content corresponding to the query instruction.
5. The method according to claim 1, characterized in that, The template library also includes: a second log template, which includes a stack identifier corresponding to the stack output content; the stack output content is used to represent information about the execution order of methods in the code. Before performing the first compression of the multiple logs to be compressed using the first log template, the method further includes: Based on a preset regular expression, determine the stack output content in the log to be compressed; If the second log template includes a stack identifier corresponding to the stack output content determined from the log to be compressed, then the stack output content in the log to be compressed is replaced with the stack identifier. If the second log template does not include a stack identifier corresponding to the stack output content determined from the log to be compressed, then a new stack identifier is assigned to the determined stack output content, and a new second log template is generated based on the determined stack output content and stack identifier. Based on the generated second log template, the stack output content in the log to be compressed is replaced with the corresponding stack identifier.
6. The method according to claim 1, characterized in that, The first log template includes a word count less than or equal to N; N is an integer greater than 1. The method for compressing the log to be compressed includes: Using N words as a window, the log to be compressed is divided into multiple strings by sliding segmentation, so that the log content of the log to be compressed is divided into multiple strings, wherein the number of words in the strings is less than or equal to N; The first log template is used to match multiple strings in the log to be compressed, and the first log template is used to replace the strings in the log to be compressed that match the first log template.
7. The method according to claim 6, characterized in that, The step of matching the first log template with multiple strings in the log to be compressed includes: The steps of matching the first log template with multiple strings in the log to be compressed are performed in parallel.
8. The method according to claim 1, characterized in that, The method further includes: Add the generated first log template to the template library.
9. A log search method, characterized in that, include: In response to a query command, determine the log content corresponding to the query command in the compressed log; The determined log content is returned as a response result to the party that requested the query instruction; The query instruction includes a full-text query instruction, which includes a query string; An inverted index is pre-built, which includes a first index and a second index. The first index is used to characterize the correspondence between words in the log and the first log template identifier. The second index is used to represent the correspondence between words in the log and the line identifiers where the log content is located; the line identifiers where the log content is located are the location identifiers representing the line where a log content is located. The step of determining the log content corresponding to the query command in the compressed log in response to the query command includes: If the query instruction includes the full-text query instruction, then based on the first index, the words in the query string are replaced with the first log template identifier to obtain a preprocessed string; Based on the second index, the compressed log is queried to obtain the row identifier of at least one log content corresponding to the preprocessed string; Based on the obtained line identifier of the log content, determine the target line content in the compressed log corresponding to the line identifier of the log content. Based on the first log template, the first log template in the target line content is restored to the word corresponding to the first log template identifier, so as to obtain the log content corresponding to the query instruction.
10. An electronic device, characterized in that, include: Processor and memory; The memory is connected to the processor and is used to store computer programs; The processor is configured to implement the log compression method as described in any one of claims 1 to 8 or the log search method as described in claim 9 by running a computer program stored in the memory.
11. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the log compression method as described in any one of claims 1 to 8 or the log search method as described in claim 9.
Citation Information
Patent Citations
Log data compression method based on storage structure
CN114860678A
Log data processing method and device, electronic equipment and storage medium
CN115061992A
